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

Commit

Permalink
Merge 5e5a0ba into c3ae6d3
Browse files Browse the repository at this point in the history
  • Loading branch information
jhwohlgemuth authored Mar 29, 2018
2 parents c3ae6d3 + 5e5a0ba commit 8a3da67
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 85 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ yo omaha --defaults --template-technology lodash --skip-coveralls
> Default in **bold**
- `--defaults`: scaffold app with no user input using defaults
- `--slim`: use with `--defaults` to skip install of support for benchmark, coveralls, jsinspect, aria, and imagemin
- `--amd`: use AMD module format (with r.js as script bundler)
- `--use-browserify`: use Browserify as script bundler (auto selects CommonJS module format)
- `--use-jest`: use Facebook's Jest instead of mocha (auto selects CommonJS module format)
Expand Down
11 changes: 7 additions & 4 deletions generators/app/doneMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const { maybe } = require('./utils');

module.exports = function (generator) {
const LETS_GET_STARTED = 'npm start';
const ELECTRON_TAGLINE = '⚡ Powered by Electron!';
const JEST_TAGLINE = 'Delightful testing provided by Jest ;)';
const ELECTRON_TAGLINE = '⚡ Powered by Electron! ';
const JEST_TAGLINE = ' Delightful testing provided by Jest ;) ';
const RUST_WARNING = '=> make sure rustc and wasm-gc are installed';
const RUST_TAGLINE = ' WebAssembly ❤ Rust ';
const { config } = generator;
const {
projectName,
Expand All @@ -20,9 +22,10 @@ module.exports = function (generator) {
useJest,
useJsinspect,
useLess,
useRust,
useSass,
useWebpack
} = config.get('projectParameters');
} = config.getAll();
const isNative = config.get('isNative');
const isWebapp = config.get('isWebapp');
const isApplication = isNative || isWebapp;
Expand All @@ -37,7 +40,7 @@ module.exports = function (generator) {
const rjs = red('r.js');
const webpack = blue('Webpack');

return [].concat('', `${type} Name: ${bold.inverse(spaceWrap(projectName))}`, maybe(isWebapp, ''), maybe(isNativeWebapp, 'Renderer:', maybe(isWebapp, 'Webapp:')), maybe(isWebapp, [`Script Bundler: ${bold(maybe(useAmd, rjs, maybe(useWebpack, webpack, browserify)))}`, `CSS pre-processor: ${bold(maybe(useLess, less, maybe(useSass, sass, dim('None'))))}`, `Template renderer: ${bold(maybe(useHandlebars, handlebars, lodash))}`].map(yes).map(str => ` ${str}`)), '', yesNo(useBenchmark)('Install benchmarks.js support'), yesNo(useCoveralls)('Integrate Coveralls.io support'), yesNo(useJsinspect)('Find duplicate code with JSInspect'), maybe(isWebapp, [yesNo(useAria)('Perform accessibility audit on HTML code'), yesNo(useImagemin)('Compress production images with imagemin')]), maybe(useJest, ['', white.bgMagenta.bold(JEST_TAGLINE)]), maybe(isNative, ['', yellow.bgBlack.bold(ELECTRON_TAGLINE)]), '', green.bold('All done!'), maybe(isApplication, white('Try out your shiny new app by running ') + white.bgBlack(spaceWrap(LETS_GET_STARTED))), '').join('\n');
return [].concat('', `${type} Name: ${bold.inverse(spaceWrap(projectName))}`, maybe(isWebapp, ''), maybe(isNativeWebapp, 'Renderer:', maybe(isWebapp, 'Webapp:')), maybe(isWebapp, [`Script Bundler: ${bold(maybe(useAmd, rjs, maybe(useWebpack, webpack, browserify)))}`, `CSS pre-processor: ${bold(maybe(useLess, less, maybe(useSass, sass, dim('None'))))}`, `Template renderer: ${bold(maybe(useHandlebars, handlebars, lodash))}`].map(yes).map(str => ` ${str}`)), '', yesNo(useBenchmark)('Install benchmarks.js support'), yesNo(useCoveralls)('Integrate Coveralls.io support'), yesNo(useJsinspect)('Find duplicate code with JSInspect'), maybe(isWebapp, [yesNo(useAria)('Perform accessibility audit on HTML code'), yesNo(useImagemin)('Compress production images with imagemin')]), maybe(isNative, ['', yellow.bgBlack.bold(ELECTRON_TAGLINE)]), maybe(useJest, ['', white.bgMagenta.bold(JEST_TAGLINE)]), maybe(useRust, ['', `${white.bgRed.bold(RUST_TAGLINE)}\n${dim(RUST_WARNING)}`]), '', green.bold('All done!'), maybe(isApplication, white('Try out your shiny new app by running ') + white.bgBlack(spaceWrap(LETS_GET_STARTED))), '').join('\n');
};
function yes(str) {
return bold(green('✔ ') + white(str));
Expand Down
15 changes: 5 additions & 10 deletions generators/project/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


const { assign, partial, pick } = require('lodash');
const { assign, partial } = require('lodash');

const { mkdirp, readFileSync, writeFileSync } = require('fs-extra');
const Generator = require('yeoman-generator');
Expand All @@ -27,13 +27,13 @@ const getSourceDirectory = (generator, dir) => {
const getProjectVariables = generator => {
const { options, use } = generator;
const { projectName, sourceDirectory } = use;
const { skipBenchmark, skipCoveralls, skipJsinspect } = options;
const { skipBenchmark, skipCoveralls, skipJsinspect, slim } = options;
return {
projectName,
sourceDirectory: getSourceDirectory(generator, sourceDirectory),
useBenchmark: use.benchmark && !skipBenchmark,
useCoveralls: use.coveralls && !skipCoveralls,
useJsinspect: use.jsinspect && !skipJsinspect
useBenchmark: use.benchmark && !skipBenchmark && !slim,
useCoveralls: use.coveralls && !skipCoveralls && !slim,
useJsinspect: use.jsinspect && !skipJsinspect && !slim
};
};
const getModuleFormat = generator => {
Expand Down Expand Up @@ -140,11 +140,6 @@ module.exports = class extends Generator {
gruntfile.insertConfig('benchmark', tasks.benchmark);
writeFileSync(generator.destinationPath('Gruntfile.js'), gruntfile.toString());
}
//
// Save configuration
//
const projectParameters = pick(config.getAll(), ['moduleFormat', 'projectName', 'sourceDirectory', 'useAmd', 'useAria', 'useBenchmark', 'useBrowserify', 'useCoveralls', 'useHandlebars', 'useImagemin', 'useJest', 'useJsinspect', 'useLess', 'useSass', 'useWebpack']);
config.set({ projectParameters });
}
end() {
const { config, log } = this;
Expand Down
14 changes: 4 additions & 10 deletions generators/webapp/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


const { assign, flow, partial, pick } = require('lodash');
const { assign, flow, partial } = require('lodash');

const { mkdirp, readFileSync, writeFileSync } = require('fs-extra');
const Generator = require('yeoman-generator');
Expand Down Expand Up @@ -105,7 +105,7 @@ module.exports = class extends Generator {
writing() {
const generator = this;
const { config, options, use, user } = generator;
const { skipAria, skipImagemin } = options;
const { skipAria, skipImagemin, slim } = options;
const {
isNative,
projectName,
Expand All @@ -117,8 +117,8 @@ module.exports = class extends Generator {
useWebpack
} = config.getAll();
const userName = config.get('userName') || user.git.name();
const useAria = use.aria && !skipAria;
const useImagemin = use.imagemin && !skipImagemin;
const useAria = use.aria && !skipAria && !slim;
const useImagemin = use.imagemin && !skipImagemin && !slim;
const appDirectory = `${sourceDirectory}app/`;
const assetsDirectory = `${sourceDirectory}assets/`;
const pluginDirectory = sourceDirectory;
Expand Down Expand Up @@ -159,7 +159,6 @@ module.exports = class extends Generator {
const generator = this;
const { config } = generator;
const {
projectParameters,
sourceDirectory,
useAmd,
useAria,
Expand Down Expand Up @@ -261,11 +260,6 @@ module.exports = class extends Generator {
// Write to file and display footer
//
writeFileSync(generator.destinationPath('Gruntfile.js'), gruntfile.toString());
//
// Save configuration
//
const parameters = assign({}, projectParameters, pick(config.getAll(), ['moduleFormat', 'projectName', 'sourceDirectory', 'useAmd', 'useAria', 'useBenchmark', 'useBrowserify', 'useCoveralls', 'useHandlebars', 'useImagemin', 'useJest', 'useJsinspect', 'useLess', 'useSass', 'useWebpack']));
config.set({ parameters });
}
};
function getPackageJsonAttributes() {
Expand Down
12 changes: 8 additions & 4 deletions src/app/doneMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const {maybe} = require('./utils');

module.exports = function(generator) {
const LETS_GET_STARTED = 'npm start';
const ELECTRON_TAGLINE = '⚡ Powered by Electron!';
const JEST_TAGLINE = 'Delightful testing provided by Jest ;)';
const ELECTRON_TAGLINE = '⚡ Powered by Electron! ';
const JEST_TAGLINE = ' Delightful testing provided by Jest ;) ';
const RUST_WARNING = '=> make sure rustc and wasm-gc are installed';
const RUST_TAGLINE = ' WebAssembly ❤ Rust ';
const {config} = generator;
const {
projectName,
Expand All @@ -20,9 +22,10 @@ module.exports = function(generator) {
useJest,
useJsinspect,
useLess,
useRust,
useSass,
useWebpack
} = config.get('projectParameters');
} = config.getAll();
const isNative = config.get('isNative');
const isWebapp = config.get('isWebapp');
const isApplication = (isNative || isWebapp);
Expand Down Expand Up @@ -55,8 +58,9 @@ module.exports = function(generator) {
yesNo(useAria)('Perform accessibility audit on HTML code'),
yesNo(useImagemin)('Compress production images with imagemin')
]),
maybe(useJest, ['', white.bgMagenta.bold(JEST_TAGLINE)]),
maybe(isNative, ['', yellow.bgBlack.bold(ELECTRON_TAGLINE)]),
maybe(useJest, ['', white.bgMagenta.bold(JEST_TAGLINE)]),
maybe(useRust, ['', `${white.bgRed.bold(RUST_TAGLINE)}\n${dim(RUST_WARNING)}`]),
'',
green.bold('All done!'),
maybe(isApplication, white('Try out your shiny new app by running ') + white.bgBlack(spaceWrap(LETS_GET_STARTED))),
Expand Down
31 changes: 5 additions & 26 deletions src/project/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
import type {ProjectGenerator} from '../types';

const {assign, partial, pick} = require('lodash');
const {assign, partial} = require('lodash');
const {mkdirp, readFileSync, writeFileSync} = require('fs-extra');
const Generator = require('yeoman-generator');
const Gruntfile = require('gruntfile-editor');
Expand All @@ -27,13 +27,13 @@ const getSourceDirectory = (generator: ProjectGenerator, dir: string) => {
const getProjectVariables = (generator: ProjectGenerator) => {
const {options, use} = generator;
const {projectName, sourceDirectory} = use;
const {skipBenchmark, skipCoveralls, skipJsinspect} = options;
const {skipBenchmark, skipCoveralls, skipJsinspect, slim} = options;
return {
projectName,
sourceDirectory: getSourceDirectory(generator, sourceDirectory),
useBenchmark: use.benchmark && !skipBenchmark,
useCoveralls: use.coveralls && !skipCoveralls,
useJsinspect: use.jsinspect && !skipJsinspect
useBenchmark: use.benchmark && !skipBenchmark && !slim,
useCoveralls: use.coveralls && !skipCoveralls && !slim,
useJsinspect: use.jsinspect && !skipJsinspect && !slim
};
};
const getModuleFormat = (generator: ProjectGenerator) => {
Expand Down Expand Up @@ -184,27 +184,6 @@ module.exports = class extends Generator {
gruntfile.insertConfig('benchmark', tasks.benchmark);
writeFileSync(generator.destinationPath('Gruntfile.js'), gruntfile.toString());
}
//
// Save configuration
//
const projectParameters = pick(config.getAll(), [
'moduleFormat',
'projectName',
'sourceDirectory',
'useAmd',
'useAria',
'useBenchmark',
'useBrowserify',
'useCoveralls',
'useHandlebars',
'useImagemin',
'useJest',
'useJsinspect',
'useLess',
'useSass',
'useWebpack'
]);
config.set({projectParameters});
}
end() {
const {config, log} = this;
Expand Down
19 changes: 18 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type Config = {
isNative: boolean,
isWebapp: boolean,
pluginDirectory: string,
projectParameters: Object,
projectName: string,
sourceDirectory: string,
userName: string,
useAmd: boolean,
Expand Down Expand Up @@ -35,6 +35,7 @@ export type ProjectGenerator = {
skipBenchmark: boolean,
skipCoveralls: boolean,
skipJsinspect: boolean,
slim: boolean,
useBrowserify: boolean,
useJest: boolean,
useWebpack: boolean
Expand All @@ -52,13 +53,29 @@ export type WebappGenerator = {
config: GeneratorConfig,
destinationPath: (path: string) => string,
npmInstall: (dependencies: string[], options?: {save?: boolean, saveDev?: boolean}) => void,
option: Function,
options: {
cssPreprocessor: string,
defaults: boolean,
skipAria: boolean,
skipImagemin: boolean,
slim: boolean,
templateTechnology: string,
useBrowserify: boolean,
useJest: boolean,
useRust: boolean,
useWebpack: boolean
},
prompt: Function,
use: {
aria: boolean,
imagemin: boolean,
moduleData: string
},
user: {
git: {
name: Function
}
}
};
export type ServerGenerator = {
Expand Down
38 changes: 8 additions & 30 deletions src/webapp/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
import type {WebappGenerator} from '../types';

const {assign, flow, partial, pick} = require('lodash');
const {assign, flow, partial} = require('lodash');
const {mkdirp, readFileSync, writeFileSync} = require('fs-extra');
const Generator = require('yeoman-generator');
const Gruntfile = require('gruntfile-editor');
Expand Down Expand Up @@ -43,13 +43,13 @@ const resolveCssPreprocessor = (generator: WebappGenerator) => {
module.exports = class extends Generator {
constructor(args: any, opts: any) {
super(args, opts);
const generator = this;
const generator: WebappGenerator = this;
Object.keys(COMMAND_LINE_OPTIONS).forEach(option => {
generator.option(option, COMMAND_LINE_OPTIONS[option]);
});
}
prompting() {
const generator = this;
const generator: WebappGenerator = this;
const {config, options} = generator;
const {useBrowserify, useJest, useRust, useWebpack} = options;
const isUnAnswered = option => (!!!options[option.name] || (options[option.name] === COMMAND_LINE_OPTIONS[option.name].defaults));
Expand Down Expand Up @@ -103,9 +103,9 @@ module.exports = class extends Generator {
}
}
writing() {
const generator = this;
const generator: WebappGenerator = this;
const {config, options, use, user} = generator;
const {skipAria, skipImagemin} = options;
const {skipAria, skipImagemin, slim} = options;
const {
isNative,
projectName,
Expand All @@ -117,8 +117,8 @@ module.exports = class extends Generator {
useWebpack
} = config.getAll();
const userName = config.get('userName') || user.git.name();
const useAria = use.aria && !skipAria;
const useImagemin = use.imagemin && !skipImagemin;
const useAria = use.aria && !skipAria && !slim;
const useImagemin = use.imagemin && !skipImagemin && !slim;
const appDirectory = `${sourceDirectory}app/`;
const assetsDirectory = `${sourceDirectory}assets/`;
const pluginDirectory = sourceDirectory;
Expand Down Expand Up @@ -248,7 +248,6 @@ module.exports = class extends Generator {
const generator: WebappGenerator = this;
const {config} = generator;
const {
projectParameters,
sourceDirectory,
useAmd,
useAria,
Expand Down Expand Up @@ -428,31 +427,10 @@ module.exports = class extends Generator {
// Write to file and display footer
//
writeFileSync(generator.destinationPath('Gruntfile.js'), gruntfile.toString());
//
// Save configuration
//
const parameters = assign({}, projectParameters, pick(config.getAll(), [
'moduleFormat',
'projectName',
'sourceDirectory',
'useAmd',
'useAria',
'useBenchmark',
'useBrowserify',
'useCoveralls',
'useHandlebars',
'useImagemin',
'useJest',
'useJsinspect',
'useLess',
'useSass',
'useWebpack'
]));
config.set({parameters});
}
};
function getPackageJsonAttributes() {
const generator = this;
const generator: WebappGenerator = this;
const {
isNative,
sourceDirectory,
Expand Down
8 changes: 8 additions & 0 deletions test/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ describe('Default generator', function() {
verifyBoilerplateFiles('./');
verifyDefaultConfiguration();
}));
it('--defaults --slim', () => helpers.run(join(__dirname, '../generators/app'))
.withOptions(merge({}, SKIP_INSTALL, {defaults, slim: true}))
.toPromise()
.then(() => {
verify();
noFileContent(ariaContent);
noFileContent('Gruntfile.js', 'imagemin: ');
}));
it('--defaults --use-rust', () => helpers.run(join(__dirname, '../generators/app'))
.withOptions(merge({}, SKIP_INSTALL, {defaults, 'use-rust': true}))
.toPromise()
Expand Down
1 change: 1 addition & 0 deletions test/lib/builds
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
RLH="yo omaha --defaults"
RLHS="yo omaha --defaults --slim"
BLHJ="yo omaha --defaults --use-jest"
RSH="yo omaha --defaults --css-preprocessor sass"
RSL="yo omaha --defaults --css-preprocessor sass --template-technology lodash"
Expand Down
4 changes: 4 additions & 0 deletions test/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ describe('Project generator', () => {
assert.noFileContent('package.json', 'nyc');
assert.noFileContent('package.json', 'mocha');
}));
it('--defaults --slim', () => helpers.run(join(__dirname, '../generators/project'))
.withOptions(merge(clone(SKIP_INSTALL), {defaults: true, slim: true}))
.toPromise()
.then(() => verify(...useNeither)));
});
});
function verifyCoreFiles() {
Expand Down

0 comments on commit 8a3da67

Please sign in to comment.