@fws/cli
Version:
This CLI is work in progress and it's meant to work together with other Forwardslash boilerplates. Please do not use it if you don't have access to other stuff.
74 lines (65 loc) • 2.19 kB
JavaScript
/**
* Install NPM
*
* @description CLI script for installing node_modules in theme's root directory.
*/
const fs = require('fs');
const path = require('path');
const colors = require('ansi-colors');
const helpers = require('../helpers');
const store = require('../store');
module.exports = {
wpThemeDir: '',
wpThemePath: '',
themeName: '',
spawnConfig: {},
spinner: null,
timeout: 1500,
callback: null,
init: function(callback) {
this.callback = callback;
this.themeName = store.getters.getWpThemeName();
this.wpThemePath = store.getters.getWpThemePath();
this.wpThemeDir = path.join(this.wpThemePath, this.themeName);
this.spawnConfig = {
stdio: 'inherit',
cwd: this.wpThemeDir
};
this.npmInstall();
},
npmInstall: function() {
// exit if node_modules already exists
if (fs.existsSync(path.join(this.wpThemeDir, 'node_modules'))) {
helpers.consoleLogWarning(`node_modules already installed in the root of '${this.themeName}' theme.`);
this.buildFiles();
return null;
}
// run bash script with spawn - 'npm i'
helpers.spawnScript(
store.data.isWin ? 'npm.cmd' : 'npm',
['i'],
this.spawnConfig,
colors.cyan('%s ...getting ready for \'npm install\'...'),
() => {
helpers.consoleLogWarning(`node_modules installed in the root of '${this.themeName}' theme.`, 'cyan');
this.buildFiles();
}
);
},
buildFiles: function() {
// run bash script with spawn - 'npm run build-dev'
helpers.spawnScript(
store.data.isWin ? 'npm.cmd' : 'npm',
['run', 'build-dev'],
this.spawnConfig,
colors.cyan('%s ...getting ready for \'fws build-dev\'...'),
() => {
helpers.consoleLogWarning(`Gulp build and vue build done!`, 'green');
if (!this.callback) {
process.exit(0);
}
this.callback();
}
);
}
};