|
| 1 | +const child_process = require("child_process"); |
| 2 | +const { SuccessMessage } = require("./helper"); |
| 3 | + |
| 4 | +const DEPENDENCIES = ["prop-types", "react", "react-dom", "react-hot-loader"]; |
| 5 | +const DEV_DEPENDENCIES = [ |
| 6 | + "@babel/cli", |
| 7 | + "@babel/core", |
| 8 | + "@babel/plugin-proposal-class-properties", |
| 9 | + "@babel/preset-env", |
| 10 | + "@babel/preset-react", |
| 11 | + "babel-loader", |
| 12 | + "brotli-webpack-plugin", |
| 13 | + "compression-webpack-plugin", |
| 14 | + "css-loader", |
| 15 | + "eslint", |
| 16 | + "eslint-plugin-react", |
| 17 | + "html-webpack-plugin", |
| 18 | + "husky", |
| 19 | + "jest", |
| 20 | + "prettier", |
| 21 | + "pretty-quick", |
| 22 | + "style-loader", |
| 23 | + "webpack", |
| 24 | + "webpack-cli", |
| 25 | + "webpack-dev-server", |
| 26 | + "webpack-manifest-plugin", |
| 27 | + "webpack-merge" |
| 28 | +]; |
| 29 | + |
| 30 | +/** |
| 31 | + * Returns npm command for installing dependencies |
| 32 | + */ |
| 33 | +function getDependencies() { |
| 34 | + var installCommand = "npm install --save"; |
| 35 | + DEPENDENCIES.forEach(dependency => { |
| 36 | + installCommand += ` ${dependency} `; |
| 37 | + }); |
| 38 | + return installCommand; |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Returns npm command for installing dev-dependencies |
| 43 | + */ |
| 44 | +function getDevDependencies() { |
| 45 | + var installCommand = "npm install --save-dev"; |
| 46 | + DEV_DEPENDENCIES.forEach(dependency => { |
| 47 | + installCommand += ` ${dependency} `; |
| 48 | + }); |
| 49 | + return installCommand; |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * |
| 54 | + * @param {Array<String>} commands list of commands needs to be executed |
| 55 | + * @param {Object} options |
| 56 | + * @param {String} options.cwd directory where you want to execute command |
| 57 | + * @param {String} options.stdio process's stdio config |
| 58 | + */ |
| 59 | +function installDependencies(commands, options) { |
| 60 | + options.stdio = options.stdio || "inherit"; |
| 61 | + //cleaning the npm cache |
| 62 | + child_process.execSync("npm cache clean --force", options); |
| 63 | + |
| 64 | + if (commands) { |
| 65 | + try { |
| 66 | + commands.forEach(command => { |
| 67 | + console.log(SuccessMessage(command)); |
| 68 | + child_process.execSync(command, options); |
| 69 | + }); |
| 70 | + } catch (error) { |
| 71 | + throw error; |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +module.exports = { installDependencies, getDependencies, getDevDependencies }; |
0 commit comments