Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Reduce webapp prompting complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
jhwohlgemuth committed Dec 23, 2017
1 parent d53e9fc commit 02f1339
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
23 changes: 17 additions & 6 deletions generators/webapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ const CSS_PREPROCESSOR_EXT_LOOKUP = {
none: 'css'
};

function resolveCssPreprocessor(generator) {
return generator.useLess ? 'less' : generator.useSass ? 'sass' : 'none';
}
const getModuleFormat = generator => {
const { options } = generator;
const { useBrowserify, useJest, useWebpack } = options;
return useJest || useBrowserify || useWebpack ? 'commonjs' : 'amd';
};
const getScriptBundler = generator => parseModuleData(generator.use.moduleData)[1].toLowerCase();
const useDefaultScriptBundler = generator => {
const scriptBundler = getScriptBundler(generator);
const moduleFormat = scriptBundler !== 'rjs' ? 'commonjs' : 'amd';
const useWebpack = scriptBundler === 'webpack';
const useAmd = moduleFormat === 'amd';
return !(useAmd || useWebpack);
};
const resolveCssPreprocessor = generator => generator.useLess ? 'less' : generator.useSass ? 'sass' : 'none';

module.exports = class extends Generator {
constructor(args, opts) {
Expand All @@ -84,7 +95,7 @@ module.exports = class extends Generator {
if (options.defaults) {
const done = this.async();
generator.use = webapp.defaults;
const moduleFormat = useJest || useBrowserify || useWebpack ? 'commonjs' : 'amd';
const moduleFormat = getModuleFormat(generator);
const useAmd = moduleFormat === 'amd';
const settings = {
moduleFormat,
Expand All @@ -105,17 +116,17 @@ module.exports = class extends Generator {
const { cssPreprocessor, templateTechnology } = options;
const USE_DEFAULT_CSS_PREPROCESSOR = cssPreprocessor === COMMAND_LINE_OPTIONS.cssPreprocessor.defaults;
const USE_DEFAULT_TEMPLATE_RENDERER = templateTechnology === COMMAND_LINE_OPTIONS.templateTechnology.defaults;
const SCRIPT_BUNDLER = parseModuleData(generator.use.moduleData)[1].toLowerCase();
const CSS_PREPROCESSOR = USE_DEFAULT_CSS_PREPROCESSOR ? generator.use.cssPreprocessor.toLowerCase() : cssPreprocessor;
const TEMPLATE_TECHNOLOGY = USE_DEFAULT_TEMPLATE_RENDERER ? generator.use.templateTechnology.toLowerCase() : templateTechnology;
const SCRIPT_BUNDLER = parseModuleData(generator.use.moduleData)[1].toLowerCase();
const USE_BROWSERIFY = SCRIPT_BUNDLER === 'browserify';
const USE_WEBPACK = SCRIPT_BUNDLER === 'webpack';
const moduleFormat = SCRIPT_BUNDLER === 'rjs' ? 'amd' : 'commonjs';
const useAmd = moduleFormat === 'amd';
const settings = {
moduleFormat,
useAmd,
useBrowserify: USE_BROWSERIFY || !(useAmd || USE_WEBPACK), // Browserify is default
useBrowserify: USE_BROWSERIFY || useDefaultScriptBundler(generator), // Browserify is default
useWebpack: USE_WEBPACK,
useJest: useJest || useWebpack, // Jest is ONLY an option and does not need to be saved via config
useLess: CSS_PREPROCESSOR === 'less',
Expand Down
4 changes: 4 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export type WebappGenerator = {
config: any,
destinationPath: (path: string) => string,
npmInstall: (dependencies: string[], options?: {save?: boolean, saveDev?: boolean}) => void,
options: any,
sourceDirectory: string,
use: {
moduleData: string
},
isNative: boolean,
useAmd: boolean,
useAria: boolean,
Expand Down
23 changes: 17 additions & 6 deletions src/webapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ const CSS_PREPROCESSOR_EXT_LOOKUP = {
none: 'css'
};

function resolveCssPreprocessor(generator) {
return generator.useLess ? 'less' : (generator.useSass ? 'sass' : 'none');
}
const getModuleFormat = (generator: WebappGenerator) => {
const {options} = generator;
const {useBrowserify, useJest, useWebpack} = options;
return (useJest || useBrowserify || useWebpack) ? 'commonjs' : 'amd';
};
const getScriptBundler = (generator: WebappGenerator) => parseModuleData(generator.use.moduleData)[1].toLowerCase();
const useDefaultScriptBundler = (generator: WebappGenerator) => {
const scriptBundler = getScriptBundler(generator);
const moduleFormat = (scriptBundler !== 'rjs') ? 'commonjs' : 'amd';
const useWebpack = (scriptBundler === 'webpack');
const useAmd = (moduleFormat === 'amd');
return !(useAmd || useWebpack);
};
const resolveCssPreprocessor = (generator: WebappGenerator) => generator.useLess ? 'less' : (generator.useSass ? 'sass' : 'none');

module.exports = class extends Generator {
constructor(args: any, opts: any) {
Expand All @@ -84,7 +95,7 @@ module.exports = class extends Generator {
if (options.defaults) {
const done = this.async();
generator.use = webapp.defaults;
const moduleFormat = (useJest || useBrowserify || useWebpack) ? 'commonjs' : 'amd';
const moduleFormat = getModuleFormat(generator);
const useAmd = (moduleFormat === 'amd');
const settings = {
moduleFormat,
Expand All @@ -105,17 +116,17 @@ module.exports = class extends Generator {
const {cssPreprocessor, templateTechnology} = options;
const USE_DEFAULT_CSS_PREPROCESSOR = (cssPreprocessor === COMMAND_LINE_OPTIONS.cssPreprocessor.defaults);
const USE_DEFAULT_TEMPLATE_RENDERER = (templateTechnology === COMMAND_LINE_OPTIONS.templateTechnology.defaults);
const SCRIPT_BUNDLER = parseModuleData(generator.use.moduleData)[1].toLowerCase();
const CSS_PREPROCESSOR = USE_DEFAULT_CSS_PREPROCESSOR ? generator.use.cssPreprocessor.toLowerCase() : cssPreprocessor;
const TEMPLATE_TECHNOLOGY = USE_DEFAULT_TEMPLATE_RENDERER ? generator.use.templateTechnology.toLowerCase() : templateTechnology;
const SCRIPT_BUNDLER = parseModuleData(generator.use.moduleData)[1].toLowerCase();
const USE_BROWSERIFY = (SCRIPT_BUNDLER === 'browserify');
const USE_WEBPACK = (SCRIPT_BUNDLER === 'webpack');
const moduleFormat = (SCRIPT_BUNDLER === 'rjs') ? 'amd' : 'commonjs';
const useAmd = (moduleFormat === 'amd');
const settings = {
moduleFormat,
useAmd,
useBrowserify: USE_BROWSERIFY || !(useAmd || USE_WEBPACK), // Browserify is default
useBrowserify: USE_BROWSERIFY || useDefaultScriptBundler(generator), // Browserify is default
useWebpack: USE_WEBPACK,
useJest: (useJest || useWebpack), // Jest is ONLY an option and does not need to be saved via config
useLess: (CSS_PREPROCESSOR === 'less'),
Expand Down

0 comments on commit 02f1339

Please sign in to comment.