Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const packageInfo = require(PAGE_BASE_PROJECT_JSON_FILE)
packageInfo.scripts[`start:${page}`] = `sui-widget-embedder dev -p ${page}`
const {config = {}} = packageInfo
const {sitePrefix = ''} = config['sui-widget-embedder'] || {}
// Check if the page already exist before continuing
if (fs.existsSync(PAGE_PATH)) {
showError(`[${page}] This page already exist in the path:
${PAGE_PATH}`)
}
Promise.all([
writeFile(PAGE_PACKAGE_JSON_FILE, packageJSON(pageRegExpIdentifier)),
writeFile(PAGE_ENTRY_JS_POINT_FILE, indexJS()),
writeFile(PAGE_ENTRY_SCSS_POINT_FILE, indexSCSS(sitePrefix)),
writeFile(
PAGE_BASE_PROJECT_JSON_FILE,
JSON.stringify(packageInfo, null, ' ')
)
]).then(() => {
console.log(
colors.green(
`➜ [${page}]: Your page files have been generated successfully.`
)
)
})
packageInfo.scripts[`start:${page}`] = `sui-widget-embedder dev -p ${page}`
const {config = {}} = packageInfo
const {sitePrefix = ''} = config['sui-widget-embedder'] || {}
// Check if the page already exist before continuing
if (fs.existsSync(PAGE_PATH)) {
showError(`[${page}] This page already exist in the path:
${PAGE_PATH}`)
}
Promise.all([
writeFile(PAGE_PACKAGE_JSON_FILE, packageJSON(pageRegExpIdentifier)),
writeFile(PAGE_ENTRY_JS_POINT_FILE, indexJS()),
writeFile(PAGE_ENTRY_SCSS_POINT_FILE, indexSCSS(sitePrefix)),
writeFile(
PAGE_BASE_PROJECT_JSON_FILE,
JSON.stringify(packageInfo, null, ' ')
)
]).then(() => {
console.log(
colors.green(
`➜ [${page}]: Your page files have been generated successfully.`
)
)
})
const PAGE_BASE_PROJECT_JSON_FILE = path.join(process.cwd(), 'package.json')
const {pageRegExpIdentifier} = program
const packageInfo = require(PAGE_BASE_PROJECT_JSON_FILE)
packageInfo.scripts[`start:${page}`] = `sui-widget-embedder dev -p ${page}`
const {config = {}} = packageInfo
const {sitePrefix = ''} = config['sui-widget-embedder'] || {}
// Check if the page already exist before continuing
if (fs.existsSync(PAGE_PATH)) {
showError(`[${page}] This page already exist in the path:
${PAGE_PATH}`)
}
Promise.all([
writeFile(PAGE_PACKAGE_JSON_FILE, packageJSON(pageRegExpIdentifier)),
writeFile(PAGE_ENTRY_JS_POINT_FILE, indexJS()),
writeFile(PAGE_ENTRY_SCSS_POINT_FILE, indexSCSS(sitePrefix)),
writeFile(
PAGE_BASE_PROJECT_JSON_FILE,
JSON.stringify(packageInfo, null, ' ')
)
]).then(() => {
console.log(
colors.green(
`➜ [${page}]: Your page files have been generated successfully.`
)
)
})
const areDifferentLintConfig =
JSON.stringify({eslintConfig, prettier, stylelint}) !==
JSON.stringify(LINT_CONFIGS)
// if they're different, we're going to rewrite the package.json
if (areDifferentLintConfig) {
console.log('Adding @s-ui/lint config to package.json...')
// remove deprecated linter config of sasslintConfig
const {sasslintConfig, ...originalPackageJSON} = packageJSON
// create the new package.json object to be written
const newPackageJSON = {
...originalPackageJSON,
...LINT_CONFIGS
}
// write the new package.json with the linter conifg
writeFile(
ACTUAL_PACKAGE_PATH,
JSON.stringify(newPackageJSON, null, 2)
).then(() => console.log('Added @s-ui/lint config successfully'))
} else {
console.log('@s-ui/lint config already in your package.json. Great!')
}
} catch (e) {
console.log("@s-ui/lint can't update package.json file.")
}
const {pageRegExpIdentifier} = program
const packageInfo = require(PAGE_BASE_PROJECT_JSON_FILE)
packageInfo.scripts[`start:${page}`] = `sui-widget-embedder dev -p ${page}`
const {config = {}} = packageInfo
const {sitePrefix = ''} = config['sui-widget-embedder'] || {}
// Check if the page already exist before continuing
if (fs.existsSync(PAGE_PATH)) {
showError(`[${page}] This page already exist in the path:
${PAGE_PATH}`)
}
Promise.all([
writeFile(PAGE_PACKAGE_JSON_FILE, packageJSON(pageRegExpIdentifier)),
writeFile(PAGE_ENTRY_JS_POINT_FILE, indexJS()),
writeFile(PAGE_ENTRY_SCSS_POINT_FILE, indexSCSS(sitePrefix)),
writeFile(
PAGE_BASE_PROJECT_JSON_FILE,
JSON.stringify(packageInfo, null, ' ')
)
]).then(() => {
console.log(
colors.green(
`➜ [${page}]: Your page files have been generated successfully.`
)
)
})
writeFile(COMPONENT_PLAYGROUND_FILE, `return (<${componentInPascal} />)`),
router &&
writeFile(
COMPONENT_ROUTES_FILE,
`module.exports = {
pattern: '/:lang',
'default': '/es',
'en': '/en',
'de': '/de'
}`
),
context &&
writeFile(
COMPONENT_CONTEXT_FILE,
`module.exports = {
'default': {
i18n: {t (s) { return s.split('').reverse().join('') }}
}
}`
)
]).then(() => {
console.log(colors.gray(`[${packageName}]: Installing the dependencies`))
const install = spawn('npm', ['install'], {cwd: COMPONENT_PATH})
install.stdout.on('data', data =>
console.log(colors.gray(`[${packageName}]: ${data.toString()}`))
)
install.stderr.on('data', data =>
console.log(colors.red(`[${packageName}]: ${data.toString()}`))
if (!repository.url || !homepage) {
console.log(
`Missing repository and/or homepage field in monorepo package.json
Component is created without those fields.`.yellow
)
}
Promise.all([
writeFile(
COMPONENT_PACKAGE_GITIGNORE_FILE,
`lib
node_modules`
),
writeFile(COMPONENT_PACKAGE_NPMIGNORE_FILE, `src`),
writeFile(
COMPONENT_PACKAGE_JSON_FILE,
`{
"name": "${packageName}",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"scripts": {
"build": "npx rimraf ./lib && npx mkdirp ./lib && npm run build:js && npm run build:styles",
"build:js": "../../../node_modules/.bin/babel --presets sui ./src --out-dir ./lib",
"build:styles": "../../../node_modules/.bin/cpx './src/**/*.scss' ./lib"
},
"dependencies": {
"@s-ui/component-dependencies": "1"
},${
console.log(
`Missing repository and/or homepage field in monorepo package.json
Component is created without those fields.`.yellow
)
}
Promise.all([
writeFile(
COMPONENT_PACKAGE_GITIGNORE_FILE,
`lib
node_modules`
),
writeFile(COMPONENT_PACKAGE_NPMIGNORE_FILE, `src`),
writeFile(
COMPONENT_PACKAGE_JSON_FILE,
`{
"name": "${packageName}",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"scripts": {
"build": "npx rimraf ./lib && npx mkdirp ./lib && npm run build:js && npm run build:styles",
"build:js": "../../../node_modules/.bin/babel --presets sui ./src --out-dir ./lib",
"build:styles": "../../../node_modules/.bin/cpx './src/**/*.scss' ./lib"
},
"dependencies": {
"@s-ui/component-dependencies": "1"
},${
repository.url
? `
const writePackageJson = ({name, path, auth} = {}) => {
const serveCommand = ['serve', '.', '--single', auth ? '--auth' : undefined]
const packageJson = {
name: `@sui-deploy/${name}`,
scripts: {
start: serveCommand.join(' ')
},
dependencies: {
serve: '6'
}
}
return writeFile(path, JSON.stringify(packageJson))
}