diff --git a/CHANGELOG.md b/CHANGELOG.md index d08376d..7bac1db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ ## [Unreleased] ## [Released] +## [1.0.0] - 26.05.2022 +- Add custom vendor name functionality (#2) +- Add mising styles imports, rework addFilesFromDir method (#10) +- Import child theme variables before default ones (#13) +- Add Alpaca Docs info (#1) ## [1.0.0-rc.2] - 25.03.2022 - Improvements and initial fixes diff --git a/README.md b/README.md index cd94097..04120ee 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Quickly create Magento 2 Child Theme based on [Snowdog Alpaca Theme](https://git After installation is completed: - Go to `Admin Panel -> Content -> Design -> Configuration` and choose your theme. -- Run `yarn dev` in `app/design/frontend/Snowdog/CHILD_THEME_NAME/Snowdog_Components` directory to see components in Fractal environment. +- Run `yarn dev` in `app/design/frontend/VENDOR_NAME/CHILD_THEME_NAME/Snowdog_Components` directory to see components in Fractal environment. ## What it does? - Installs following packages: @@ -35,7 +35,7 @@ After installation is completed: - [snowdog/module-shipping-latency](https://github.com/SnowdogApps/magento2-shipping-latency) - [snowdog/module-wishlist-unlocker](https://github.com/SnowdogApps/magento2-wishlist-unlocker) - [webshopapps/module-matrixrate](https://github.com/webshopapps/module-matrixrate)

-- Creates Alpaca Child Theme in `app/design/frontend/Snowdog/CHILD_THEME_NAME` including everything you need to start working with Alpaca: +- Creates Alpaca Child Theme in `app/design/frontend/VENDOR_NAME/CHILD_THEME_NAME` including everything you need to start working with Alpaca: - Essential configuration files - Styles inheritance setup - Custom variables file in `Snowdog_Components/components/Atoms/variables/` directory @@ -47,28 +47,26 @@ After installation is completed: - Upgrades Magento instance, compiles styles, JS files and SVGs. ## User guide -- [Working with Alpaca Theme]() - Learn how to utilize Alpaca Theme. -- [Alpaca Theme step by step setup]() - How to set up Alpaca from scratch, without **create-alpaca-theme**. +- [Alpaca Theme Docs](https://magento2-alpaca-docs.vercel.app/) - Learn how to utilize Alpaca Theme. ## Useful Links * [Alpaca Theme](https://github.com/SnowdogApps/magento2-alpaca-theme) * [Snowdog Frontools](https://github.com/SnowdogApps/magento2-frontools) - * [Valet Plus](https://github.com/weprovide/valet-plus/wiki/Database) * [Fractal guide](https://fractal.build/guide/) * [Alpaca Packages](https://github.com/SnowdogApps/magento2-alpaca-packages) - * [Alpaca Components guide](https://github.com/SnowdogApps/magento2-alpaca-theme/blob/master/Snowdog_Components/README.md) * [Alpaca Components preview](https://magento2-alpaca-theme-git-master-snowdog1.vercel.app/) - * [Theme inheritance magento docs](https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-inherit.html) - * [Layout instructions magento docs](https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/layouts/xml-instructions.html) -## Test package locally - * clone repository - * change name of package in `package.json` to `create-alpaca-theme` - * install package globally: `npm install -g` - * link command running `npm link` - * run `npx create-alpaca-theme` +## Testing and local development + * Clone this repository + * Change name of package in `package.json` to `create-alpaca-theme` + * Install package globally: `npm install -g` + * Link command running `npm link` + * Run `npx create-alpaca-theme` from Magento project root directory -If you have problems with global npm persmission, check npm docs: [Resolving eaccess permissions error when installing package globally](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
+## Troubleshooting + +* If you have problems with global npm persmission, check npm docs: [Resolving eaccess permissions error when installing package globally](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally) +* When running Warden or other dockerized Magento instance, make sure you run `npx @snowdog/create-alpaca-theme` from proper container. **** 2022 **[Snowdog](https://www.snow.dog)** diff --git a/package-lock.json b/package-lock.json index b67dcc9..5c3a7fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@snowdog/create-alpaca-theme", - "version": "1.0.0-rc.2", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@snowdog/create-alpaca-theme", - "version": "1.0.0-rc.2", + "version": "1.0.0", "license": "MIT", "dependencies": { "cli-progress": "3.9.1", diff --git a/package.json b/package.json index 54e18cd..caccc5c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@snowdog/create-alpaca-theme", - "version": "1.0.0-rc.2", + "version": "1.0.0", "description": "Create Magento 2 child theme based on Snowdog Alpaca Theme", "type": "module", "main": "index.js", diff --git a/src/components-actions.js b/src/components-actions.js index a78fe56..374152f 100644 --- a/src/components-actions.js +++ b/src/components-actions.js @@ -1,13 +1,13 @@ import { validateYarn } from './validators.js' import promiseExec from './utils/promiseExec.js' -import { BASE_PATH } from './constants/constants.js' +import { BASE_THEME_PATH } from './constants/constants.js' const COMPONENTS_INSTALL_ERROR_MSG = 'There was an error installing Snowdog_Components:' -export async function installComponents(themeName) { +export async function installComponents(themeName, vendor) { const packageManager = await validateYarn() ? 'yarn' : 'npm' - return promiseExec(`cd ${BASE_PATH}${themeName}/Snowdog_Components && ${packageManager} install`, (msg) => { + return promiseExec(`cd ${BASE_THEME_PATH}${vendor}/${themeName}/Snowdog_Components && ${packageManager} install`, (msg) => { return `${COMPONENTS_INSTALL_ERROR_MSG} ${msg}` }) } diff --git a/src/constants/constants.js b/src/constants/constants.js index 3cc64e8..a2ebf42 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -11,7 +11,7 @@ export const PACKAGE_PATH = { } // BASE PATHS -export const BASE_PATH = 'app/design/frontend/Snowdog/' +export const BASE_THEME_PATH = 'app/design/frontend/' export const FRONTOOLS_PATH = 'vendor/snowdog/frontools' export const SNOWDOG_COMPONENTS = '/Snowdog_Components' export const MAGENTO_CHECKOUT_STYLES = '/Magento_Checkout/styles' diff --git a/src/create-alpaca-theme.js b/src/create-alpaca-theme.js index b2c0c5f..e0fc524 100644 --- a/src/create-alpaca-theme.js +++ b/src/create-alpaca-theme.js @@ -26,6 +26,7 @@ import { validateName, validateConfigFiles, validateComposer, + validateVendorName, validateMagentoInstance, validateRegistrationName } from './validators.js' @@ -37,7 +38,7 @@ import { addExemplaryStyles } from './local-env-actions.js' import { - BASE_PATH, + BASE_THEME_PATH, LOADING_BAR, PACKAGE_PATH, CHECK_MARK_CHARACTER, @@ -67,6 +68,13 @@ const promptQuestions = [ name: 'name', validate: validateRegistrationName }, + { + type: 'input', + message: `Enter vendor name, or leave it as default (${colors.yellow('Snowdog')}):`, + name: 'vendor', + default: 'Snowdog', + validate: validateVendorName + }, { type: 'confirm', message: `Extend exemplary Alpaca Component? (${colors.yellow('Recommended')})`, @@ -91,8 +99,18 @@ function init() { log(colors.blue('Snowdog Alpaca Theme CLI v1.0.0\n')) Inquirer.prompt(promptQuestions).then(async (answers) => { + const { + fullName, + name, + vendor, + exemplaryComponent, + database + } = answers + const timerMsg = 'Finished in' + const vendorPath = `${BASE_THEME_PATH}${vendor}/` + try { - console.time(colors.blue('Finished in')) // Start time counter + console.time(colors.blue(timerMsg)) spinner.start() bar.start(100, 0, { info: infoColor('Validating Magento config files...') }) validateConfigFiles() @@ -112,35 +130,35 @@ function init() { bar.update(35, { info: infoColor('Creating directories...') }) await Promise.all(directoriesList.map(async (dir) => { - await createDirectory(`${BASE_PATH}${answers.name}${dir}`) + await createDirectory(`${vendorPath}${name}${dir}`) })) bar.update(36, { info: infoColor('Setting up component config files...') }) - await setupComponentsConfigFiles(answers.name, answers.fullName) + await setupComponentsConfigFiles(name, fullName, vendor) bar.update(37, { info: infoColor('Setting up theme config files...') }) - await setupThemeConfigFiles(answers.name, answers.fullName) + await setupThemeConfigFiles(name, fullName, vendor) bar.update(38, { info: infoColor('Setting up frontools config files...') }) - await setupFrontoolsConfigFiles(answers.name) + await setupFrontoolsConfigFiles(name, vendor) bar.update(39, { info: infoColor('Setting up base styles structure...') }) - await addBaseStyles(answers.name) + await addBaseStyles(name, vendor) - if (answers.exemplaryComponent) { + if (exemplaryComponent) { bar.update(40, { info: infoColor('Creating exemplary component directories...') }) await Promise.all(exemplaryComponentDirectories.map(async (dir) => { - await createDirectory(`${BASE_PATH}${answers.name}${dir}`) + await createDirectory(`${vendorPath}${name}${dir}`) })) bar.update(41, { info: infoColor('Adding exemplary styles...') }) - await addExemplaryStyles(answers.name) + await addExemplaryStyles(name, vendor) } bar.update(42, { info: infoColor('Installing Snowdog Components...') }) - await installComponents(answers.name) + await installComponents(name, vendor) - if (answers.database) { + if (database) { bar.update(55, { info: infoColor('Creating media directories...') }) await Promise.all(mediaDirList.map(async (dir) => { await createDirectory(dir) @@ -155,7 +173,7 @@ function init() { bar.update(60, { info: infoColor('Upgrading Magneto instance...') }) await magentoUpgrade() - if (answers.database) { + if (database) { bar.update(85, { info: infoColor('Running database queries...') }) dbErrors = await runQueries() } @@ -167,8 +185,8 @@ function init() { process.stdout.write(`\r${CHECK_MARK_CHARACTER}`) spinner.stop() bar.stop() - console.timeEnd(colors.blue('Finished in')) // Stop time counter - CLISuccesMessage(answers.fullName, answers.exemplaryComponent, answers.name) + console.timeEnd(colors.blue(timerMsg)) + CLISuccesMessage(fullName, exemplaryComponent, name, vendor) if (dbErrors.length !== 0) { databaseErrorMessage() diff --git a/src/local-env-actions.js b/src/local-env-actions.js index dcd9f65..f1fb95a 100644 --- a/src/local-env-actions.js +++ b/src/local-env-actions.js @@ -5,18 +5,19 @@ import { ENV_PATH, SNOWDOG_COMPONENTS, ALPACA_THEME_DIR, - BASE_PATH, + BASE_THEME_PATH, MAGENTO_CHECKOUT_STYLES } from './constants/constants.js' import { addFilesFromDir, addFilesFromTemplate, replacePhraseInAll, - prependImport + prependImport, + replacePhrase } from './local-env-helper.js' // SETING UP SNOWDOG_COMPONENTS CONFIG FILES -export async function setupComponentsConfigFiles(themeName, fullThemeName) { +export async function setupComponentsConfigFiles(themeName, fullThemeName, vendor) { const componentFilesToUpdate = [ { name: 'gulpfile.mjs', @@ -30,16 +31,16 @@ export async function setupComponentsConfigFiles(themeName, fullThemeName) { } ] try { - await addFilesFromDir(ENV_PATH.ALPACA_COMPONENTS_DIR, themeName, '.lock|.md', SNOWDOG_COMPONENTS) - await addFilesFromTemplate(ENV_PATH.TEMPLATES_COMPONENTS_CONFIG_DIR, `${BASE_PATH}${themeName}${SNOWDOG_COMPONENTS}`) - await replacePhraseInAll(componentFilesToUpdate, `${BASE_PATH}${themeName}${SNOWDOG_COMPONENTS}`) + await addFilesFromDir(ENV_PATH.ALPACA_COMPONENTS_DIR, themeName, '.lock|.md', vendor, SNOWDOG_COMPONENTS) + await addFilesFromTemplate(ENV_PATH.TEMPLATES_COMPONENTS_CONFIG_DIR, `${BASE_THEME_PATH}${vendor}/${themeName}${SNOWDOG_COMPONENTS}`) + await replacePhraseInAll(componentFilesToUpdate, `${BASE_THEME_PATH}${vendor}/${themeName}${SNOWDOG_COMPONENTS}`) } catch (error) { console.log(`\n${error}`) } } // SETTING UP THEME LEVEL BASE CONFIG FILES -export async function setupThemeConfigFiles(themeName, fullThemeName) { +export async function setupThemeConfigFiles(themeName, fullThemeName, vendor) { const lineToAddParentTag = 2 const parentTag = ' Snowdog/alpaca' const ignoredFiles = '.lock|.md|now|LICENSE|composer' @@ -61,11 +62,12 @@ export async function setupThemeConfigFiles(themeName, fullThemeName) { } ] - await addFilesFromDir(ALPACA_THEME_DIR, themeName, ignoredFiles) - await addFilesFromTemplate(ENV_PATH.TEMPLATES_THEME_DIR, `${BASE_PATH}${themeName}`) - await replacePhraseInAll(themeFilesToUpdate, `${BASE_PATH}${themeName}`) + await addFilesFromDir(ALPACA_THEME_DIR, themeName, ignoredFiles, vendor) + await addFilesFromTemplate(ENV_PATH.TEMPLATES_THEME_DIR, `${BASE_THEME_PATH}${vendor}/${themeName}`) + await replacePhraseInAll(themeFilesToUpdate, `${BASE_THEME_PATH}${vendor}/${themeName}`) + await replacePhrase(`${BASE_THEME_PATH}${vendor}/${themeName}/registration.php`, 'Snowdog', vendor) await prependImport( - `${BASE_PATH}${themeName}/theme.xml`, + `${BASE_THEME_PATH}${vendor}/${themeName}/theme.xml`, parentTag, themeName, lineToAddParentTag @@ -73,7 +75,7 @@ export async function setupThemeConfigFiles(themeName, fullThemeName) { } // CONFIGURING FRONTOOLS -export async function setupFrontoolsConfigFiles(themeName) { +export async function setupFrontoolsConfigFiles(themeName, vendor) { const frontoolsFilesToUpdate = [ { name: 'browser-sync.json', @@ -89,42 +91,43 @@ export async function setupFrontoolsConfigFiles(themeName) { await addFilesFromTemplate(ENV_PATH.TEMPLATES_FRONTOOLS_DIR, ENV_PATH.DEV_FRONTOOLS_CONFIG_DIR) await replacePhraseInAll(frontoolsFilesToUpdate, ENV_PATH.DEV_FRONTOOLS_CONFIG_DIR) + await replacePhrase(`${ENV_PATH.DEV_FRONTOOLS_CONFIG_DIR}/themes.json`, 'YOUR_VENDOR', vendor) } // ADDING ALPACA BASE STYLES -export async function addBaseStyles(themeName) { - const docsPath = `${BASE_PATH}${themeName}${ENV_PATH.COMPONENT_DOCS_STYLES_DIR}` +export async function addBaseStyles(themeName, vendor) { + const docsPath = `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.COMPONENT_DOCS_STYLES_DIR}` const docsText = VARIABLES_IMPORT_PATHS.COMMENT + VARIABLES_IMPORT_PATHS.DOCS - const chechoutPath = `${BASE_PATH}${themeName}${MAGENTO_CHECKOUT_STYLES}/checkout.scss` + const chechoutPath = `${BASE_THEME_PATH}${vendor}/${themeName}${MAGENTO_CHECKOUT_STYLES}/checkout.scss` const checkoutText = VARIABLES_IMPORT_PATHS.COMMENT + VARIABLES_IMPORT_PATHS.CHECKOUT - const themeLevelStylesPath = `${BASE_PATH}${themeName}/styles` + const themeLevelStylesPath = `${BASE_THEME_PATH}${vendor}/${themeName}/styles` const themeLevelStylesText = VARIABLES_IMPORT_PATHS.COMMENT + VARIABLES_IMPORT_PATHS.MAIN // CREATING CHILD THEME VARIABLES await addFilesFromTemplate( ENV_PATH.TEMPLATES_COMPONENTS_BASE_DIR, - `${BASE_PATH}${themeName}${ENV_PATH.COMPONENT_VARIABLES_DIR}` + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.COMPONENT_VARIABLES_DIR}` ) await rename( - `${BASE_PATH}${themeName}${ENV_PATH.COMPONENT_VARIABLES_FILE}`, - `${BASE_PATH}${themeName}${ENV_PATH.COMPONENT_VARIABLES_DIR}/_${themeName}-variables.scss` + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.COMPONENT_VARIABLES_FILE}`, + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.COMPONENT_VARIABLES_DIR}/_${themeName}-variables.scss` ) // IMPORTING ALPACA COMPONENTS DOCS STYLES - await addFilesFromDir(ENV_PATH.ALPACA_COMPONENTS_DOCS_STYLES_DIR, themeName, '_', ENV_PATH.COMPONENT_DOCS_STYLES_DIR) + await addFilesFromDir(ENV_PATH.ALPACA_COMPONENTS_DOCS_STYLES_DIR, themeName, '_', vendor, ENV_PATH.COMPONENT_DOCS_STYLES_DIR) const docsFilesNames = await listFiles(docsPath) docsFilesNames.forEach((fileName) => { - prependImport(`${docsPath}/${fileName}`, docsText, themeName, null, 'variables', 'YOUR_THEME_NAME') + prependImport(`${docsPath}/${fileName}`, docsText, themeName, 0, null, 'YOUR_THEME_NAME') }) // IMPORTING MAGENTO CHECKOUT STYLES - await addFilesFromDir(ENV_PATH.ALPACA_MAGENTO_CHECKOUT_STYLES_DIR, themeName, '_', MAGENTO_CHECKOUT_STYLES) - await prependImport(chechoutPath, checkoutText, themeName, null, 'variables', 'YOUR_THEME_NAME') + await addFilesFromDir(ENV_PATH.ALPACA_MAGENTO_CHECKOUT_STYLES_DIR, themeName, null, vendor, MAGENTO_CHECKOUT_STYLES) + await prependImport(chechoutPath, checkoutText, themeName, 0, null, 'YOUR_THEME_NAME') // CREATING THEME LEVEL STYLES - await addFilesFromDir(ENV_PATH.ALPACA_STYLES_DIR, themeName, 'email|gallery', '/styles') + await addFilesFromDir(ENV_PATH.ALPACA_STYLES_DIR, themeName, null, vendor, '/styles') const themeLevelStyles = await listFiles(themeLevelStylesPath) @@ -133,15 +136,15 @@ export async function addBaseStyles(themeName) { `${themeLevelStylesPath}/${fileName}`, themeLevelStylesText, themeName, + 0, null, - 'variables', 'YOUR_THEME_NAME' ) }) } // ADDING EXEMPLARY BUTTON STYLES AND CRITICAL/NON-CRITICAL IMPORTS -export async function addExemplaryStyles(themeName) { +export async function addExemplaryStyles(themeName, vendor) { const exemplaryFilesToUpdate = [ { name: '_button-extend.scss', @@ -166,16 +169,16 @@ export async function addExemplaryStyles(themeName) { // ADDING BUTTON STYLES await addFilesFromTemplate( ENV_PATH.TEMPLATES_COMPONENTS_EXEMPLARY_DIR, - `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button` + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button` ) - await replacePhraseInAll(exemplaryFilesToUpdate, `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button`) + await replacePhraseInAll(exemplaryFilesToUpdate, `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button`) await rename( - `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/button.scss`, - `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/_${themeName}-button.scss` + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/button.scss`, + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/_${themeName}-button.scss` ) await rename( - `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/button-variables.scss`, - `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/_${themeName}-button-variables.scss` + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/button-variables.scss`, + `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_MOLECULES_DIR}/button/_${themeName}-button-variables.scss` ) // IMPORTING CRITICAL AND NON CRITICAL STYLES @@ -183,7 +186,8 @@ export async function addExemplaryStyles(themeName) { ENV_PATH.ALPACA_COMPONENTS_STYLES_DIR, themeName, 'mixins|-extends|_checkout', + vendor, ENV_PATH.SNOWDOG_COMPONENTS_STYLES_DIR ) - await replacePhraseInAll(criticalStylesToUpdate, `${BASE_PATH}${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_STYLES_DIR}`) + await replacePhraseInAll(criticalStylesToUpdate, `${BASE_THEME_PATH}${vendor}/${themeName}${ENV_PATH.SNOWDOG_COMPONENTS_STYLES_DIR}`) } diff --git a/src/local-env-helper.js b/src/local-env-helper.js index b24a6f4..286b08f 100644 --- a/src/local-env-helper.js +++ b/src/local-env-helper.js @@ -1,6 +1,6 @@ import * as fs from 'fs' import { readFile } from 'fs/promises' -import { BASE_PATH } from './constants/constants.js' +import { BASE_THEME_PATH } from './constants/constants.js' import { createFile, listFiles @@ -14,14 +14,17 @@ export async function replacePhrase(filePath, phraseToReplace, phraseToReplaceWi await createFile(filePath, fileUpdated) } -export async function addFilesFromDir(dir, themeName, ignoredFiles, dirInChildTheme = '') { - const configFiles = await listFiles(dir) - const re = new RegExp(ignoredFiles) - const configFilesFiltered = configFiles.filter((str) => !re.test(str)) +export async function addFilesFromDir(dir, themeName, ignoredFiles, vendor, dirInChildTheme = '') { + let configFiles = await listFiles(dir) - await Promise.all(configFilesFiltered.map(async (fileName) => { + if (ignoredFiles) { + const re = new RegExp(ignoredFiles) + configFiles = configFiles.filter((str) => !re.test(str)) + } + + await Promise.all(configFiles.map(async (fileName) => { const file = await readFile(`${dir}/${fileName}`) - await createFile(`${BASE_PATH}${themeName}${dirInChildTheme}/${fileName}`, file) + await createFile(`${BASE_THEME_PATH}${vendor}/${themeName}${dirInChildTheme}/${fileName}`, file) })) } @@ -53,8 +56,10 @@ export async function prependImport( ) { const data = fs.readFileSync(filePath) const dataArr = data.toString().split('\n') - const lineIdx = lineToPrepend || dataArr.findIndex((str) => str.includes(prependAfterWord)) + 2 const re = phraseToReplace ? new RegExp(phraseToReplace, 'gim') : null + const lineIdx = typeof lineToPrepend === 'number' + ? lineToPrepend + : dataArr.findIndex((str) => str.includes(prependAfterWord)) + 2 dataArr.splice(lineIdx, 0, phraseToReplace ? textToPrepend.replace(re, themeName) : textToPrepend) const text = dataArr.join('\n') diff --git a/src/utils/messages.js b/src/utils/messages.js index d9a1c04..79cf9ec 100644 --- a/src/utils/messages.js +++ b/src/utils/messages.js @@ -2,20 +2,20 @@ import colors from 'colors' const { log } = console -export const CLISuccesMessage = (fullThemeName, exemplaryComponent, themeName) => { +export const CLISuccesMessage = (fullThemeName, exemplaryComponent, themeName, vendor) => { return log( colors.yellow('\nInstallation completed successfully!'), - colors.blue(`\n\nāœ… Theme created in ${colors.green(`app/design/frontend/Snowdog/${themeName}`)}`), + colors.blue(`\n\nāœ… Theme created in ${colors.green(`app/design/frontend/${vendor}/${themeName}`)}`), colors.blue('\nšŸ‘‰ Go to'), colors.green('Admin Panel -> Content -> Design -> Configuration'), colors.blue('and choose your theme'), (`(${colors.green(fullThemeName)})`), colors.blue(`\nāœØ Use ${colors.green('yarn dev')} in`), - colors.green(`app/design/frontend/Snowdog/${themeName}/Snowdog_Components`), + colors.green(`app/design/frontend/${vendor}/${themeName}/Snowdog_Components`), colors.blue('to run components in Fractal'), - colors.blue('\nšŸ”Ž Read'), + colors.blue('\nšŸ”Ž Visit'), colors.green('Alpaca Docs'), - colors.blue('to learn how to use Alpaca Theme'), + colors.blue('at https://magento2-alpaca-docs.vercel.app/'), exemplaryComponent ? colors.blue(`\n\nVariables ${colors.green('$color-primary')} and ${colors.green('$button-text-color')} have been changed as an example`) : '', exemplaryComponent ? colors.blue(`\nSee ${colors.green(`_${themeName}-variables.scss`)} and ${colors.green(`_${themeName}-button-variables.scss`)} to edit them`) : '', colors.yellow('\n\n2022 Snowdog || https://snow.dog || https://github.com/SnowdogApps \n') diff --git a/src/validators.js b/src/validators.js index 13ef30e..ded5327 100644 --- a/src/validators.js +++ b/src/validators.js @@ -19,15 +19,18 @@ function getNameValidator(customRule) { if (name.length < NAME_MINIMUM_LENGTH) { return NAME_TO_SHORT_MSG } - if (BANNED_NAMES_LIST.includes(name)) { - return BANNED_NAMES_MSG - } return customRule ? customRule(name) : true } } -export const validateName = getNameValidator() +export const validateName = getNameValidator((name) => { + if (BANNED_NAMES_LIST.includes(name)) { + return BANNED_NAMES_MSG + } + + return true +}) export const validateRegistrationName = getNameValidator((name) => { if (name.split(' ').length > 1) { @@ -36,6 +39,17 @@ export const validateRegistrationName = getNameValidator((name) => { if (name !== name.toLowerCase()) { return NAME_NOT_LOWERCASE } + if (BANNED_NAMES_LIST.includes(name)) { + return BANNED_NAMES_MSG + } + + return true +}) + +export const validateVendorName = getNameValidator((name) => { + if (name.split(' ').length > 1) { + return REGISTRATION_NAME_NOT_SINGULAR + } return true }) diff --git a/templates/frontools/themes.json.sample b/templates/frontools/themes.json.sample index bba027c..72ddd8a 100644 --- a/templates/frontools/themes.json.sample +++ b/templates/frontools/themes.json.sample @@ -10,8 +10,8 @@ ] }, "YOUR_THEME_NAME": { - "src": "app/design/frontend/Snowdog/YOUR_THEME_NAME", - "dest": "pub/static/frontend/Snowdog/YOUR_THEME_NAME", + "src": "app/design/frontend/YOUR_VENDOR/YOUR_THEME_NAME", + "dest": "pub/static/frontend/YOUR_VENDOR/YOUR_THEME_NAME", "parent": "alpaca", "locale": ["en_US"], "ignore": [