Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit 2294f89

Browse files
committed
fix(install): invoke npm install hook
1 parent 7acf399 commit 2294f89

File tree

4 files changed

+175
-21
lines changed

4 files changed

+175
-21
lines changed

packages/create-semantic-module/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {createEnv} from 'yeoman-environment';
1+
const yoEnv = require('yeoman-environment');
22

3-
function createSemanticModule(args) {
4-
const env = createEnv();
3+
function createSemanticModule(args = []) {
4+
const env = yoEnv.createEnv();
55

66
env.register(
77
require.resolve('generator-semantic-module'),
88
'semantic-module:app'
99
);
1010

1111
env.run('semantic-module:app', {
12-
'module-name': (args || [])[0]
12+
'module-name': (args)[0]
1313
});
1414
}
1515

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`create new module creates files: commitlint.config.js 1`] = `
4+
"/* eslint-env node */
5+
6+
module.exports = {// Add your own rules. See http://marionebl.github.io/commitlint
7+
rules: {
8+
}
9+
};
10+
"
11+
`;
12+
13+
exports[`create new module creates files: package.json 1`] = `
14+
"{
15+
\\"config\\": {
16+
\\"commitizen\\": {
17+
\\"path\\": \\"node_modules/@commitlint/prompt\\"
18+
}
19+
},
20+
\\"scripts\\": {
21+
\\"commit\\": \\"git-cz\\",
22+
\\"commit:retry\\": \\"git-cz --retry\\",
23+
\\"commitmsg\\": \\"commitlint -e\\"
24+
}
25+
}
26+
"
27+
`;
28+
29+
exports[`use command line arguments creates files: commitizen.config.js 1`] = `
30+
"/* eslint-env node */
31+
32+
const types = [
33+
{
34+
value: 'feat',
35+
name: 'feat: A new feature'
36+
},
37+
{
38+
value: 'fix',
39+
name: 'fix: A bug fix'
40+
},
41+
{
42+
value: 'docs',
43+
name: 'docs: Documentation only changes'
44+
},
45+
{
46+
value: 'style',
47+
name: \`style: Changes that do not affect the meaning of the code
48+
(white-space, formatting, missing semi-colons, etc)\`
49+
},
50+
{
51+
value: 'refactor',
52+
name: 'refactor: A code change that neither fixes a bug nor adds a feature'
53+
},
54+
{
55+
value: 'perf',
56+
name: 'perf: A code change that improves performance'
57+
},
58+
{
59+
value: 'test',
60+
name: 'test: Adding missing tests'
61+
},
62+
{
63+
value: 'chore',
64+
name: \`chore: Changes to the build process or auxiliary tools
65+
and libraries such as documentation generation\`
66+
},
67+
{
68+
value: 'revert',
69+
name: 'revert: Revert to a commit'
70+
}
71+
];
72+
73+
const scopes = [
74+
'example-1',
75+
'example-2'
76+
].map(name => ({ name }));
77+
78+
module.exports = {
79+
types,
80+
scopes,
81+
allowCustomScopes: true,
82+
allowBreakingChanges: [
83+
'feat',
84+
'fix',
85+
'perf',
86+
'refactor'
87+
]
88+
};
89+
"
90+
`;
91+
92+
exports[`use command line arguments creates files: commitlint.config.js 1`] = `
93+
"/* eslint-env node */
94+
95+
const { types, scopes, allowCustomScopes } = require('./commitizen.config');
96+
97+
const validTypes = types.map((type) => type.value);
98+
const validScopes = scopes.map((scope) => scope.name);
99+
const scopeValidationLevel = allowCustomScopes ? 1 : 2;
100+
101+
module.exports = {
102+
extends: ['@commitlint/config-lerna-scopes'],
103+
104+
// Add your own rules. See http://marionebl.github.io/commitlint
105+
rules: {
106+
// Apply valid scopes and types
107+
'scope-enum': [scopeValidationLevel, 'always', validScopes],
108+
'type-enum': [2, 'always', validTypes]
109+
}
110+
};
111+
"
112+
`;
113+
114+
exports[`use command line arguments creates files: package.json 1`] = `
115+
"{
116+
\\"config\\": {
117+
\\"commitizen\\": {
118+
\\"path\\": \\"node_modules/cz-customizable\\"
119+
},
120+
\\"cz-customizable\\": {
121+
\\"config\\": \\"commitizen.config.js\\"
122+
}
123+
},
124+
\\"scripts\\": {
125+
\\"commit\\": \\"git-cz\\",
126+
\\"commit:retry\\": \\"git-cz --retry\\",
127+
\\"commitmsg\\": \\"commitlint -e\\"
128+
}
129+
}
130+
"
131+
`;

packages/generator-semantic-module/src/__tests__/app.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
const path = require('path');
33
const assert = require('yeoman-assert');
44
const helpers = require('yeoman-test');
5+
const {promisify} = require('es6-promisify');
6+
const fs = require('fs');
7+
8+
const readFile = promisify(fs.readFile);
59

610
describe('use command line arguments', () => {
711
beforeAll(() => {
@@ -18,16 +22,16 @@ describe('use command line arguments', () => {
1822
});
1923
});
2024

21-
it('creates files', () => {
22-
assert.file([
25+
it('creates files', async () => {
26+
await checkFiles([
2327
'commitlint.config.js',
2428
'commitizen.config.js',
2529
'package.json'
2630
]);
2731
});
2832
});
2933

30-
describe('create new module', () => {
34+
describe('create new module', async () => {
3135
beforeAll(() => {
3236
return helpers.run(path.join(__dirname, '../generators/app'))
3337
.withArguments(['my-module'])
@@ -42,10 +46,19 @@ describe('create new module', () => {
4246
expect(process.cwd().endsWith('/my-module')).toBe(true);
4347
});
4448

45-
it('creates files', () => {
46-
assert.file([
49+
it('creates files', async () => {
50+
await checkFiles([
4751
'commitlint.config.js',
4852
'package.json'
4953
]);
5054
});
5155
});
56+
57+
async function checkFiles(files) {
58+
assert.file(files);
59+
60+
return Promise.all(files.map(async file => {
61+
const contents = await readFile(file);
62+
expect(contents.toString()).toMatchSnapshot(file);
63+
}));
64+
}

packages/generator-semantic-module/src/generators/app/index.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'babel-polyfill';
2-
import Generator from 'yeoman-generator';
3-
import yosay from 'yosay';
1+
require('babel-polyfill');
2+
const Generator = require('yeoman-generator');
3+
const yosay = require('yosay');
44

55
const options = {
66
moduleName: 'module-name',
@@ -147,7 +147,7 @@ You can always run create-semantic-module again and select a different option.`)
147147
this.fs.extendJSON(this.destinationPath('package.json'), packageJSON);
148148
}
149149

150-
async install() {
150+
install() {
151151
const packages = [
152152
'commitizen',
153153
'@commitlint/cli',
@@ -160,14 +160,24 @@ You can always run create-semantic-module again and select a different option.`)
160160
packages.push(commitLintConfig);
161161
}
162162

163-
const packager = this.config.get(options.packager);
164-
const installFlags = packager === 'yarn' ? {
165-
dev: true,
166-
'ignore-workspace-root-check': true
167-
} : {
168-
'save-dev': true
169-
};
170-
await this.runInstall(packager, packages, installFlags);
163+
const useYarn = this.config.get(options.packager) === 'yarn';
164+
165+
if (useYarn) {
166+
this.yarnInstall(packages, {
167+
dev: true,
168+
'ignore-workspace-root-check': true
169+
});
170+
} else {
171+
this.npmInstall(packages, {
172+
'save-dev': true
173+
});
174+
}
175+
176+
this.installDependencies({
177+
yarn: useYarn,
178+
npm: !useYarn,
179+
bower: false
180+
});
171181
}
172182
}
173183

0 commit comments

Comments
 (0)