Skip to content

Commit ce227fd

Browse files
committed
feat(dependency-updaters): apply lifters after scaffolding
1 parent 0f92d93 commit ce227fd

File tree

8 files changed

+85
-64
lines changed

8 files changed

+85
-64
lines changed

.eslintrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
extends:
22
- '@form8ion'
33
- '@form8ion/cucumber'
4+
5+
parserOptions:
6+
ecmaVersion: 2022

README.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,33 @@ import {lift, questionNames, scaffold} from '@form8ion/project';
7777
#### Execute
7878

7979
```javascript
80-
await scaffold({
81-
decisions: {
82-
[questionNames.PROJECT_NAME]: 'my-project',
83-
[questionNames.LICENSE]: 'MIT',
84-
[questionNames.VISIBILITY]: 'Public',
85-
[questionNames.DESCRIPTION]: 'My project',
86-
[questionNames.GIT_REPO]: false,
87-
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
88-
[questionNames.COPYRIGHT_YEAR]: '2022',
89-
[questionNames.PROJECT_LANGUAGE]: 'foo'
80+
await scaffold({
81+
decisions: {
82+
[questionNames.PROJECT_NAME]: 'my-project',
83+
[questionNames.LICENSE]: 'MIT',
84+
[questionNames.VISIBILITY]: 'Public',
85+
[questionNames.DESCRIPTION]: 'My project',
86+
[questionNames.GIT_REPO]: false,
87+
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
88+
[questionNames.COPYRIGHT_YEAR]: '2022',
89+
[questionNames.PROJECT_LANGUAGE]: 'foo'
90+
},
91+
plugins: {
92+
dependencyUpdaters: {
93+
bar: {scaffold: options => options}
9094
},
91-
plugins: {
92-
dependencyUpdaters: {
93-
bar: {scaffold: options => options}
94-
},
95-
languages: {
96-
foo: {scaffold: options => options}
97-
}
95+
languages: {
96+
foo: {scaffold: options => options}
9897
}
99-
});
100-
101-
await lift({
102-
projectRoot: process.cwd(),
103-
results: {},
104-
enhancers: {foo: {test: () => true, lift: () => ({})}},
105-
vcs: {}
106-
});
98+
}
99+
});
100+
101+
await lift({
102+
projectRoot: process.cwd(),
103+
results: {},
104+
enhancers: {foo: {test: () => true, lift: () => ({})}},
105+
vcs: {}
106+
});
107107
```
108108

109109
### API

example.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ import {lift, questionNames, scaffold} from './lib/index.js';
77

88
// #### Execute
99

10-
// remark-usage-ignore-next 2
11-
(async () => {
12-
stubbedFs({templates: {'editorconfig.ini': await fs.readFile(resolve('templates', 'editorconfig.ini'))}});
10+
// remark-usage-ignore-next 4
11+
stubbedFs({
12+
templates: {'editorconfig.ini': await fs.readFile(resolve('templates', 'editorconfig.ini'))},
13+
node_modules: stubbedFs.load('node_modules')
14+
});
1315

14-
await scaffold({
15-
decisions: {
16-
[questionNames.PROJECT_NAME]: 'my-project',
17-
[questionNames.LICENSE]: 'MIT',
18-
[questionNames.VISIBILITY]: 'Public',
19-
[questionNames.DESCRIPTION]: 'My project',
20-
[questionNames.GIT_REPO]: false,
21-
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
22-
[questionNames.COPYRIGHT_YEAR]: '2022',
23-
[questionNames.PROJECT_LANGUAGE]: 'foo'
16+
await scaffold({
17+
decisions: {
18+
[questionNames.PROJECT_NAME]: 'my-project',
19+
[questionNames.LICENSE]: 'MIT',
20+
[questionNames.VISIBILITY]: 'Public',
21+
[questionNames.DESCRIPTION]: 'My project',
22+
[questionNames.GIT_REPO]: false,
23+
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
24+
[questionNames.COPYRIGHT_YEAR]: '2022',
25+
[questionNames.PROJECT_LANGUAGE]: 'foo'
26+
},
27+
plugins: {
28+
dependencyUpdaters: {
29+
bar: {scaffold: options => options}
2430
},
25-
plugins: {
26-
dependencyUpdaters: {
27-
bar: {scaffold: options => options}
28-
},
29-
languages: {
30-
foo: {scaffold: options => options}
31-
}
31+
languages: {
32+
foo: {scaffold: options => options}
3233
}
33-
});
34+
}
35+
});
3436

35-
await lift({
36-
projectRoot: process.cwd(),
37-
results: {},
38-
enhancers: {foo: {test: () => true, lift: () => ({})}},
39-
vcs: {}
40-
});
41-
// remark-usage-ignore-next
42-
})();
37+
await lift({
38+
projectRoot: process.cwd(),
39+
results: {},
40+
enhancers: {foo: {test: () => true, lift: () => ({})}},
41+
vcs: {}
42+
});

package-lock.json

+4-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
}
5959
},
6060
"dependencies": {
61-
"@form8ion/core": "^4.4.1",
61+
"@form8ion/core": "^4.6.0",
6262
"@form8ion/execa-wrapper": "^1.0.0",
6363
"@form8ion/git": "^1.2.0",
6464
"@form8ion/overridable-prompts": "^1.1.0",

src/scaffolder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export async function scaffold(options) {
7272
nextSteps: contributedTasks
7373
});
7474

75-
await lift({projectRoot, results: deepmerge.all(contributors)});
75+
await lift({projectRoot, results: deepmerge.all(contributors), enhancers: dependencyUpdaters});
7676

7777
const gitResults = gitRepo && await liftGit({projectRoot, origin: vcsHostResults});
7878

src/scaffolder.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ describe('project scaffolder', () => {
151151
expect(scaffoldEditorconfig).toHaveBeenCalledWith({projectRoot: projectPath});
152152
expect(lift).toHaveBeenCalledWith({
153153
projectRoot: projectPath,
154-
results: deepmerge.all([licenseResults, languageResults, dependencyUpdaterResults, contributingResults])
154+
results: deepmerge.all([licenseResults, languageResults, dependencyUpdaterResults, contributingResults]),
155+
enhancers: dependencyUpdaters
155156
});
156157
expect(resultsReporter.reportResults).toHaveBeenCalledWith({
157158
nextSteps: [...gitNextSteps, ...dependencyUpdaterNextSteps]
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
1+
import {promises as fs} from 'node:fs';
2+
13
import {After, Before, Given, Then} from '@cucumber/cucumber';
24
import sinon from 'sinon';
5+
import any from '@travi/any';
6+
import {fileExists} from '@form8ion/core';
37

4-
let updaterScaffolder;
8+
let updaterScaffolder, updaterLifter;
59

610
Before(function () {
711
updaterScaffolder = sinon.stub();
12+
updaterLifter = sinon.stub();
813
});
914

1015
After(function () {
1116
updaterScaffolder = null;
1217
});
1318

1419
Given('a dependency updater can be chosen', async function () {
15-
this.updatePlugin = {scaffold: foo => updaterScaffolder(foo)};
20+
const filename = any.word();
21+
this.updatePlugin = {
22+
scaffold: async ({projectRoot}) => {
23+
updaterScaffolder();
24+
await fs.writeFile(`${projectRoot}/${filename}.txt`, any.sentence());
25+
},
26+
lift: foo => {
27+
updaterLifter(foo);
28+
return any.simpleObject();
29+
},
30+
test: async ({projectRoot}) => fileExists(`${projectRoot}/${filename}.txt`)
31+
};
1632
});
1733

1834
Then('the dependency updater was executed', async function () {
1935
sinon.assert.calledOnce(updaterScaffolder);
36+
sinon.assert.calledOnce(updaterLifter);
2037
});
2138

2239
Then('the dependency updater was not executed', async function () {
2340
sinon.assert.notCalled(updaterScaffolder);
41+
sinon.assert.notCalled(updaterLifter);
2442
});

0 commit comments

Comments
 (0)