Skip to content

Commit

Permalink
feat: add plugins styles integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurTriis1 committed Nov 14, 2024
1 parent dcb8517 commit 97a2bdb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/cli/src/utils/generate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import chalk from 'chalk'
import {
copyFileSync,
copySync,
existsSync,
mkdirsSync,
Expand All @@ -17,7 +16,7 @@ import ora from 'ora'
import { withBasePath } from './directory'
import { installDependencies } from './dependencies'
import { logger } from './logger'
import { installPlugins } from './plugins'
import { generateThemeIndexPluginsContent, installPlugins } from './plugins'

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

writeFileSync(tmpThemesCustomizationsFile, themeIndexPluginsContent)
logger.log(
`${chalk.green('success')} - ${
storeConfig.theme
Expand All @@ -307,6 +311,10 @@ 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
21 changes: 21 additions & 0 deletions packages/cli/src/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ export async function addPluginsSections(basePath: string, plugins: Plugin[]) {
logger.log(pluginsImportFileContent)
}

export const generateThemeIndexPluginsContent = async (
basePath: string,
...customImports: string[]
) => {
const { getPackagePath } = withBasePath(basePath)

const plugins = await getPluginsList(basePath)

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

return [...pluginImports, ...customImports].join('\n')
}

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

Expand Down

0 comments on commit 97a2bdb

Please sign in to comment.