Skip to content

Commit

Permalink
xo
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmorneau committed Oct 29, 2020
1 parent 7ebea15 commit da1e30b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/commands/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
23 changes: 11 additions & 12 deletions lib/modes/pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -59,59 +58,59 @@ 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;
}`
);
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;
}`
);
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`
);
}
Expand Down
22 changes: 11 additions & 11 deletions lib/services/nitro-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -216,7 +216,7 @@ const runCommand = async (webpack, webpackConfig, showErrors) => {
colors: true
}));

reject('has errors');
reject(new Error('has errors'));
}
} else {
resolve('done');
Expand All @@ -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;
}
};
Expand All @@ -254,15 +254,15 @@ 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);
}

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);
Expand Down
14 changes: 4 additions & 10 deletions lib/services/npm-service.js
Original file line number Diff line number Diff line change
@@ -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 = './') => {
Expand All @@ -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'});

Expand All @@ -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');
Expand All @@ -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'});
Expand Down

0 comments on commit da1e30b

Please sign in to comment.