Skip to content

Commit

Permalink
feat: fix import plugin themes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurTriis1 committed Nov 14, 2024
1 parent bb8f5c0 commit f681703
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/utils/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ export const withBasePath = (basepath: string) => {
'themes',
'index.scss'
),
tmpThemesPluginsFile: path.join(tmpDir, 'src', 'plugins', 'index.scss'),
tmpCMSDir: path.join(tmpDir, 'cms', 'faststore'),
tmpCMSWebhookUrlsFile: path.join(tmpDir, 'cms-webhook-urls.json'),
tmpPagesDir: path.join(tmpDir, 'src', 'pages'),
tmpPluginsDir: path.join(tmpDir, 'src', 'plugins'),
tmpCMSWebhookUrlsFile: path.join(tmpDir, 'cms-webhook-urls.json'),
tmpStoreConfigFile: path.join(
tmpDir,
'src',
Expand Down
14 changes: 3 additions & 11 deletions packages/cli/src/utils/generate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk'
import {
copyFileSync,
copySync,
existsSync,
mkdirsSync,
Expand All @@ -16,7 +17,7 @@ import ora from 'ora'
import { withBasePath } from './directory'
import { installDependencies } from './dependencies'
import { logger } from './logger'
import { generateThemeIndexPluginsContent, installPlugins } from './plugins'
import { installPlugins } from './plugins'

interface GenerateOptions {
setup?: boolean
Expand Down Expand Up @@ -296,12 +297,7 @@ async function copyTheme(basePath: string) {
)
if (existsSync(customTheme)) {
try {
const themeIndexPluginsContent = await generateThemeIndexPluginsContent(
basePath,
`@import "./${storeConfig.theme}.scss";`
)

writeFileSync(tmpThemesCustomizationsFile, themeIndexPluginsContent)
copyFileSync(customTheme, tmpThemesCustomizationsFile)
logger.log(
`${chalk.green('success')} - ${
storeConfig.theme
Expand All @@ -311,10 +307,6 @@ async function copyTheme(basePath: string) {
logger.error(`${chalk.red('error')} - ${err}`)
}
} else {
const themeIndexPluginsContent =
await generateThemeIndexPluginsContent(basePath)
writeFileSync(tmpThemesCustomizationsFile, themeIndexPluginsContent)

logger.info(
`${chalk.blue('info')} - The ${
storeConfig.theme
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,28 @@ export const generateThemeIndexPluginsContent = async (
return [...pluginImports, ...customImports].join('\n')
}

const addPluginsTheme = async (basePath: string, plugins: Plugin[]) => {
const { getPackagePath, tmpThemesPluginsFile } = withBasePath(basePath)

const pluginImportsContent = plugins
.filter((plugin) =>
existsSync(
getPackagePath(getPluginName(plugin), 'src', 'themes', 'index.scss')
)
)
.map(
(plugin) => `@import "${getPluginName(plugin)}/src/themes/index.scss";`
)
.join('\n')

writeFileSync(tmpThemesPluginsFile, pluginImportsContent)
}

export const installPlugins = async (basePath: string) => {
const plugins = await getPluginsList(basePath)

copyPluginsSrc(basePath, plugins)
generatePluginPages(basePath, plugins)
addPluginsSections(basePath, plugins)
addPluginsTheme(basePath, plugins)
}
1 change: 1 addition & 0 deletions packages/core/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SEO from '../../next-seo.config'

// FastStore UI's base styles
import '../styles/global/index.scss'
import '../plugins/index.scss'
import '../customizations/src/themes/index.scss'

import { DefaultSeo } from 'next-seo'
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/plugins/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// ----------------------------------------------------------
// Plugins' themes will override this file
// ----------------------------------------------------------

0 comments on commit f681703

Please sign in to comment.