diff --git a/lib/commands/launch.js b/lib/commands/launch.js index 87b11d4..755223f 100644 --- a/lib/commands/launch.js +++ b/lib/commands/launch.js @@ -179,7 +179,7 @@ module.exports = async function (cb, {nomin = false}) { fs.ensureDirSync(path.resolve(config.distFolder)); - let buildResult = await nitroService.build(config, true, nomin); + const buildResult = await nitroService.build(config, true, nomin); if (buildResult.valid) { console.log(chalk.cyan('=> build complete')); diff --git a/lib/modes/pro.js b/lib/modes/pro.js index 597ec4f..e360d13 100644 --- a/lib/modes/pro.js +++ b/lib/modes/pro.js @@ -37,7 +37,6 @@ module.exports = class ProModeInitializer { // Copy the files from node_modules to the current directory await fs.copy(path.join(this.getTemplatePath(), 'template'), this.appPath); - // Initialize the template const templateConfig = await templateService.initTemplate( path.join(this.getTemplatePath(), 'init.js'), @@ -59,18 +58,18 @@ module.exports = class ProModeInitializer { }; if (finalConfig.cssExtensions.includes('css')) { - finalConfig.mainCss = "./src/main.css"; + finalConfig.mainCss = './src/main.css'; await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, `main.css`), `body { + path.resolve(process.cwd(), finalConfig.srcFolder, 'main.css'), `body { background-color: #fff; }` ); } if (finalConfig.cssExtensions.includes('scss')) { - finalConfig.mainCss = "./src/main.scss"; + finalConfig.mainCss = './src/main.scss'; await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, `main.scss`), `@import "scss/file1"; + path.resolve(process.cwd(), finalConfig.srcFolder, 'main.scss'), `@import "scss/file1"; body { background-color: #fff; @@ -78,16 +77,16 @@ body { ); await fs.ensureDir(path.resolve(process.cwd(), finalConfig.srcFolder, 'scss')); await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, 'scss', `file1.scss`), `.file1 { + path.resolve(process.cwd(), finalConfig.srcFolder, 'scss', 'file1.scss'), `.file1 { background-color: #fff; }` ); } if (finalConfig.cssExtensions.includes('less')) { - finalConfig.mainCss = "./src/main.less"; + finalConfig.mainCss = './src/main.less'; await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, `main.less`), `@import "less/file1"; + path.resolve(process.cwd(), finalConfig.srcFolder, 'main.less'), `@import "less/file1"; body { background-color: #fff; @@ -95,23 +94,23 @@ body { ); await fs.ensureDir(path.resolve(process.cwd(), finalConfig.srcFolder, 'less')); await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, 'less', `file1.less`), `.file1 { + path.resolve(process.cwd(), finalConfig.srcFolder, 'less', 'file1.less'), `.file1 { background-color: #fff; }` ); } if (finalConfig.cssExtensions.includes('styl')) { - finalConfig.mainCss = "./src/main.styl"; + finalConfig.mainCss = './src/main.styl'; await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, `main.styl`), `@import "styl/file1"; + path.resolve(process.cwd(), finalConfig.srcFolder, 'main.styl'), `@import "styl/file1"; body background-color: #fff` ); await fs.ensureDir(path.resolve(process.cwd(), finalConfig.srcFolder, 'styl')); await fs.writeFile( - path.resolve(process.cwd(), finalConfig.srcFolder, 'styl', `file1.styl`), `.file1 + path.resolve(process.cwd(), finalConfig.srcFolder, 'styl', 'file1.styl'), `.file1 background-color: #fff` ); } diff --git a/lib/services/nitro-service.js b/lib/services/nitro-service.js index 32203bb..2dc6fa4 100644 --- a/lib/services/nitro-service.js +++ b/lib/services/nitro-service.js @@ -200,14 +200,14 @@ const runCommand = async (webpack, webpackConfig, showErrors) => { console.error(err.details); } - reject('webpack failed'); + reject(new Error('webpack failed')); } - if (showErrors && (stats.hasErrors() || stats.hasWarnings())) { - if (stats.toString().includes('Cannot find module') - || (stats.toString().includes('Module not found') && stats.toString().includes(`in '${path.resolve(process.cwd())}'`)) + if (showErrors && (stats.hasErrors() || stats.hasWarnings())) { + if (stats.toString().includes('Cannot find module') || + (stats.toString().includes('Module not found') && stats.toString().includes(`in '${path.resolve(process.cwd())}'`)) ) { - reject('MODULE_NOT_FOUND'); + reject(new Error('MODULE_NOT_FOUND')); } else { console.log(stats.toString({ preset: 'errors-warnings', @@ -216,7 +216,7 @@ const runCommand = async (webpack, webpackConfig, showErrors) => { colors: true })); - reject('has errors'); + reject(new Error('has errors')); } } else { resolve('done'); @@ -240,12 +240,12 @@ const build = async (config, firstAttempt = true, nomin = false) => { let buildResult = { valid: true, moduleNotFound: false - } + }; - const catchError = (error) => { + const catchError = error => { buildResult.valid = false; - if (error.code === 'MODULE_NOT_FOUND' || error === 'MODULE_NOT_FOUND') { + if (error.code === 'MODULE_NOT_FOUND' || error.message === 'MODULE_NOT_FOUND') { buildResult.moduleNotFound = true; } }; @@ -254,7 +254,7 @@ const build = async (config, firstAttempt = true, nomin = false) => { const webpack = require(path.resolve(process.cwd(), 'node_modules', 'webpack')); try { - let webpackConfigDev = require(path.resolve(process.cwd(), 'webpack.dev')); + const webpackConfigDev = require(path.resolve(process.cwd(), 'webpack.dev')); await runCommand(webpack, webpackConfigDev, true); } catch (error) { catchError(error); @@ -262,7 +262,7 @@ const build = async (config, firstAttempt = true, nomin = false) => { if (buildResult.valid && nomin === false) { try { - let webpackConfigProd = require(path.resolve(process.cwd(), 'webpack.prod')); + const webpackConfigProd = require(path.resolve(process.cwd(), 'webpack.prod')); await runCommand(webpack, webpackConfigProd, false); } catch (error) { catchError(error); diff --git a/lib/services/npm-service.js b/lib/services/npm-service.js index 60df4e9..b92a131 100644 --- a/lib/services/npm-service.js +++ b/lib/services/npm-service.js @@ -1,6 +1,5 @@ const fs = require('fs-extra'); const {spawn} = require('child_process'); -const chalk = require('chalk'); const ora = require('ora'); const installPackage = async (packageName, packagePath = './') => { @@ -9,14 +8,9 @@ const installPackage = async (packageName, packagePath = './') => { await fs.ensureDir(packagePath); return new Promise((resolve, reject) => { - const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; - let args; + const command = process.platform.startsWith('win') ? 'npm.cmd' : 'npm'; - if (packagePath) { - args = ['--prefix', packagePath, 'install', packageName]; - } else { - args = ['install', packageName]; - } + const args = packagePath ? ['--prefix', packagePath, 'install', packageName] : ['install', packageName]; const child = spawn(command, args, {stdio: 'ignore'}); @@ -35,7 +29,7 @@ const installPackage = async (packageName, packagePath = './') => { const installDependencies = async (config, packagePath = './') => { await fs.ensureDir(packagePath); - const spinner = ora(`Installing dependencies`).start(); + const spinner = ora('Installing dependencies').start(); if (config.cssExtensions.includes('scss')) { await installPackage('sass'); @@ -53,7 +47,7 @@ const installDependencies = async (config, packagePath = './') => { } return new Promise((resolve, reject) => { - const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; + const command = process.platform.startsWith('win') ? 'npm.cmd' : 'npm'; const args = ['install', '--loglevel', 'error']; const child = spawn(command, args, {cwd: packagePath, stdio: 'ignore'});