From d36cd4f5f852170606aa3728cd0d67a69fc91576 Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Fri, 23 Feb 2018 13:51:44 +0100 Subject: [PATCH 1/2] ast(init): fix init command --- lib/commands/init.js | 5 +++-- lib/init/transformations/index.js | 15 +++++++++------ lib/utils/modify-config-helper.js | 8 +++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index e3748d5dc85..ecc72cfa92b 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -1,7 +1,8 @@ "use strict"; const npmPackagesExists = require("../utils/npm-packages-exists"); -const creator = require("../init/index").creator; +const defaultGenerator = require("../generators/init-generator"); +const modifyHelper = require("../utils/modify-config-helper"); /** * @@ -15,7 +16,7 @@ const creator = require("../init/index").creator; module.exports = function initializeInquirer(pkg) { if (pkg.length === 0) { - return creator(); + return modifyHelper("init", defaultGenerator); } return npmPackagesExists(pkg); }; diff --git a/lib/init/transformations/index.js b/lib/init/transformations/index.js index dc44c0ed42f..b29d1b3f865 100644 --- a/lib/init/transformations/index.js +++ b/lib/init/transformations/index.js @@ -98,7 +98,9 @@ module.exports = function runTransform(webpackProperties, action) { .filter(e => e[1]); const ast = j( - action ? webpackProperties.configFile : "module.exports = {}" + action && action !== "init" + ? webpackProperties.configFile + : "module.exports = {}" ); const transformAction = action || null; @@ -111,15 +113,16 @@ module.exports = function runTransform(webpackProperties, action) { }) .then(_ => { let configurationName; - if (!config.configName) { + if (!config.configName && action !== "init") { configurationName = "webpack.config.js"; } else { configurationName = "webpack." + config.configName + ".js"; } - const outputPath = action - ? webpackProperties.configPath - : path.join(process.cwd(), configurationName); + const outputPath = + action && action !== "init" + ? webpackProperties.configPath + : path.join(process.cwd(), configurationName); const source = ast.toSource({ quote: "single" }); @@ -130,7 +133,7 @@ module.exports = function runTransform(webpackProperties, action) { console.error(err.message ? err.message : err); }); }); - if (action) { + if (action && webpackProperties.config.item) { process.stdout.write( "\n" + chalk.green( diff --git a/lib/utils/modify-config-helper.js b/lib/utils/modify-config-helper.js index cf2f8b81dfa..179ba0c4bbe 100644 --- a/lib/utils/modify-config-helper.js +++ b/lib/utils/modify-config-helper.js @@ -16,12 +16,10 @@ const runTransform = require("../init/transformations/index"); */ module.exports = function modifyHelperUtil(action, generator) { - const configPath = path.resolve(process.cwd(), "webpack.config.js"); + let configPath = path.resolve(process.cwd(), "webpack.config.js"); const webpackConfigExists = fs.existsSync(configPath); if (!webpackConfigExists) { - throw new Error( - "Couldn't find a webpack configuration in your project path" - ); + configPath = null; } const env = yeoman.createEnv("webpack", null); const generatorName = `webpack-${action}-generator`; @@ -30,7 +28,7 @@ module.exports = function modifyHelperUtil(action, generator) { env.run(generatorName).on("end", () => { const config = Object.assign( { - configFile: fs.readFileSync(configPath, "utf8"), + configFile: !configPath ? null : fs.readFileSync(configPath, "utf8"), configPath: configPath }, env.getArgument("configuration") From 4dff074dbfb2c93627de1d8945d1bdfeca10b04c Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Fri, 23 Feb 2018 13:55:07 +0100 Subject: [PATCH 2/2] chore(pkg.json): remove commitmsg cmd --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 915fc64026b..071c079c5ea 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,11 @@ "travis:integration": "yarn prepare && nyc jest && yarn reportCoverage", "travis:lint": "yarn lint && yarn bundlesize", "bundlesize": "bundlesize", - "commitmsg": "commitlint -e $GIT_PARAMS", "changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile CHANGELOG.md --same-file" }, "lint-staged": { "{lib,bin}/**/!(__testfixtures__)/**.js": [ "eslint --fix", - "npm run commitmsg", "git add" ] },