|
1 |
| -import Generator = require("yeoman-generator"); |
2 |
| - |
3 |
| -import * as glob from "glob-all"; |
4 |
| -import * as autoComplete from "inquirer-autocomplete-prompt"; |
5 |
| -import * as path from "path"; |
6 |
| - |
7 | 1 | import npmExists from "@webpack-cli/utils/npm-exists";
|
8 | 2 | import { getPackageManager } from "@webpack-cli/utils/package-manager";
|
9 | 3 | import PROP_TYPES from "@webpack-cli/utils/prop-types";
|
10 | 4 | import {
|
11 | 5 | AutoComplete,
|
12 | 6 | Confirm,
|
13 | 7 | IInquirerInput,
|
14 |
| - IInquirerList, |
15 | 8 | Input,
|
| 9 | + InputValidate, |
16 | 10 | List,
|
17 | 11 | } from "@webpack-cli/webpack-scaffold";
|
18 |
| - |
| 12 | +import { existsSync } from "fs"; |
| 13 | +import * as glob from "glob-all"; |
| 14 | +import * as autoComplete from "inquirer-autocomplete-prompt"; |
| 15 | +import { resolve } from "path"; |
| 16 | +import Generator = require("yeoman-generator"); |
19 | 17 | import { ISchemaProperties, IWebpackOptions } from "./types";
|
20 | 18 | import entryQuestions from "./utils/entry";
|
| 19 | +import validate from "./utils/validate"; |
21 | 20 |
|
22 | 21 | // tslint:disable:no-var-requires
|
23 | 22 | const webpackDevServerSchema = require("webpack-dev-server/lib/options.json");
|
@@ -94,7 +93,8 @@ export default class AddGenerator extends Generator {
|
94 | 93 | config: {
|
95 | 94 | configName?: string,
|
96 | 95 | topScope?: string[],
|
97 |
| - item?: string; |
| 96 | + item?: string, |
| 97 | + merge?: object, |
98 | 98 | webpackOptions?: IWebpackOptions,
|
99 | 99 | },
|
100 | 100 | };
|
@@ -173,6 +173,36 @@ export default class AddGenerator extends Generator {
|
173 | 173 | done();
|
174 | 174 | });
|
175 | 175 | }
|
| 176 | + if (action === "merge") { |
| 177 | + const validatePath = (path: string) => { |
| 178 | + const resolvedPath = resolve(process.env.PWD, path); |
| 179 | + if (existsSync(resolvedPath)) { |
| 180 | + if (/\.js$/.test(path)) { |
| 181 | + if (typeof require(resolvedPath) !== "object") { |
| 182 | + return "Given file doesn't export an Object"; |
| 183 | + } |
| 184 | + return true; |
| 185 | + } else { |
| 186 | + return "Path doesn't corresponds to a javascript file"; |
| 187 | + } |
| 188 | + } |
| 189 | + return "Invalid path provided"; |
| 190 | + }; |
| 191 | + return this.prompt([ |
| 192 | + InputValidate( |
| 193 | + "mergeFile", |
| 194 | + "What is the location of webpack configuration file with which you want to merge current configuration?", |
| 195 | + validatePath, |
| 196 | + ), |
| 197 | + ]) |
| 198 | + .then((mergeFileAnswer: { |
| 199 | + mergeFile: string; |
| 200 | + }) => { |
| 201 | + const resolvedPath = resolve(process.env.PWD, mergeFileAnswer.mergeFile); |
| 202 | + const mergeConfig = require(resolvedPath); |
| 203 | + this.configuration.config.merge = mergeConfig; |
| 204 | + }); |
| 205 | + } |
176 | 206 | }
|
177 | 207 | const temp: string = action;
|
178 | 208 | if (action === "resolveLoader") {
|
@@ -367,7 +397,7 @@ export default class AddGenerator extends Generator {
|
367 | 397 | pluginsSchemaPath.indexOf("optimize") >= 0
|
368 | 398 | ? "webpack.optimize"
|
369 | 399 | : "webpack";
|
370 |
| - const resolvePluginsPath: string = path.resolve(pluginsSchemaPath); |
| 400 | + const resolvePluginsPath: string = resolve(pluginsSchemaPath); |
371 | 401 | const pluginSchema: object = resolvePluginsPath
|
372 | 402 | ? require(resolvePluginsPath)
|
373 | 403 | : null;
|
|
0 commit comments