Skip to content

Commit

Permalink
feat(dependency-updaters): apply lifters after scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jul 25, 2024
1 parent 0f92d93 commit ce227fd
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
extends:
- '@form8ion'
- '@form8ion/cucumber'

parserOptions:
ecmaVersion: 2022
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,33 @@ import {lift, questionNames, scaffold} from '@form8ion/project';
#### Execute

```javascript
await scaffold({
decisions: {
[questionNames.PROJECT_NAME]: 'my-project',
[questionNames.LICENSE]: 'MIT',
[questionNames.VISIBILITY]: 'Public',
[questionNames.DESCRIPTION]: 'My project',
[questionNames.GIT_REPO]: false,
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
[questionNames.COPYRIGHT_YEAR]: '2022',
[questionNames.PROJECT_LANGUAGE]: 'foo'
await scaffold({
decisions: {
[questionNames.PROJECT_NAME]: 'my-project',
[questionNames.LICENSE]: 'MIT',
[questionNames.VISIBILITY]: 'Public',
[questionNames.DESCRIPTION]: 'My project',
[questionNames.GIT_REPO]: false,
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
[questionNames.COPYRIGHT_YEAR]: '2022',
[questionNames.PROJECT_LANGUAGE]: 'foo'
},
plugins: {
dependencyUpdaters: {
bar: {scaffold: options => options}
},
plugins: {
dependencyUpdaters: {
bar: {scaffold: options => options}
},
languages: {
foo: {scaffold: options => options}
}
languages: {
foo: {scaffold: options => options}
}
});

await lift({
projectRoot: process.cwd(),
results: {},
enhancers: {foo: {test: () => true, lift: () => ({})}},
vcs: {}
});
}
});

await lift({
projectRoot: process.cwd(),
results: {},
enhancers: {foo: {test: () => true, lift: () => ({})}},
vcs: {}
});
```

### API
Expand Down
58 changes: 29 additions & 29 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ import {lift, questionNames, scaffold} from './lib/index.js';

// #### Execute

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

await scaffold({
decisions: {
[questionNames.PROJECT_NAME]: 'my-project',
[questionNames.LICENSE]: 'MIT',
[questionNames.VISIBILITY]: 'Public',
[questionNames.DESCRIPTION]: 'My project',
[questionNames.GIT_REPO]: false,
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
[questionNames.COPYRIGHT_YEAR]: '2022',
[questionNames.PROJECT_LANGUAGE]: 'foo'
await scaffold({
decisions: {
[questionNames.PROJECT_NAME]: 'my-project',
[questionNames.LICENSE]: 'MIT',
[questionNames.VISIBILITY]: 'Public',
[questionNames.DESCRIPTION]: 'My project',
[questionNames.GIT_REPO]: false,
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
[questionNames.COPYRIGHT_YEAR]: '2022',
[questionNames.PROJECT_LANGUAGE]: 'foo'
},
plugins: {
dependencyUpdaters: {
bar: {scaffold: options => options}
},
plugins: {
dependencyUpdaters: {
bar: {scaffold: options => options}
},
languages: {
foo: {scaffold: options => options}
}
languages: {
foo: {scaffold: options => options}
}
});
}
});

await lift({
projectRoot: process.cwd(),
results: {},
enhancers: {foo: {test: () => true, lift: () => ({})}},
vcs: {}
});
// remark-usage-ignore-next
})();
await lift({
projectRoot: process.cwd(),
results: {},
enhancers: {foo: {test: () => true, lift: () => ({})}},
vcs: {}
});
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"dependencies": {
"@form8ion/core": "^4.4.1",
"@form8ion/core": "^4.6.0",
"@form8ion/execa-wrapper": "^1.0.0",
"@form8ion/git": "^1.2.0",
"@form8ion/overridable-prompts": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function scaffold(options) {
nextSteps: contributedTasks
});

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

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

Expand Down
3 changes: 2 additions & 1 deletion src/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ describe('project scaffolder', () => {
expect(scaffoldEditorconfig).toHaveBeenCalledWith({projectRoot: projectPath});
expect(lift).toHaveBeenCalledWith({
projectRoot: projectPath,
results: deepmerge.all([licenseResults, languageResults, dependencyUpdaterResults, contributingResults])
results: deepmerge.all([licenseResults, languageResults, dependencyUpdaterResults, contributingResults]),
enhancers: dependencyUpdaters
});
expect(resultsReporter.reportResults).toHaveBeenCalledWith({
nextSteps: [...gitNextSteps, ...dependencyUpdaterNextSteps]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
import {promises as fs} from 'node:fs';

import {After, Before, Given, Then} from '@cucumber/cucumber';
import sinon from 'sinon';
import any from '@travi/any';
import {fileExists} from '@form8ion/core';

let updaterScaffolder;
let updaterScaffolder, updaterLifter;

Before(function () {
updaterScaffolder = sinon.stub();
updaterLifter = sinon.stub();
});

After(function () {
updaterScaffolder = null;
});

Given('a dependency updater can be chosen', async function () {
this.updatePlugin = {scaffold: foo => updaterScaffolder(foo)};
const filename = any.word();
this.updatePlugin = {
scaffold: async ({projectRoot}) => {
updaterScaffolder();
await fs.writeFile(`${projectRoot}/${filename}.txt`, any.sentence());
},
lift: foo => {
updaterLifter(foo);
return any.simpleObject();
},
test: async ({projectRoot}) => fileExists(`${projectRoot}/${filename}.txt`)
};
});

Then('the dependency updater was executed', async function () {
sinon.assert.calledOnce(updaterScaffolder);
sinon.assert.calledOnce(updaterLifter);
});

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

0 comments on commit ce227fd

Please sign in to comment.