From ce227fdd1ad994f7c74658ffe8f7a00aec651580 Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Thu, 25 Jul 2024 11:42:55 -0500 Subject: [PATCH] feat(dependency-updaters): apply lifters after scaffolding --- .eslintrc.yml | 3 + README.md | 50 ++++++++-------- example.js | 58 +++++++++---------- package-lock.json | 9 ++- package.json | 2 +- src/scaffolder.js | 2 +- src/scaffolder.test.js | 3 +- .../dependency-updater-steps.js | 22 ++++++- 8 files changed, 85 insertions(+), 64 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 37194ee8..4b157d6b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,3 +1,6 @@ extends: - '@form8ion' - '@form8ion/cucumber' + +parserOptions: + ecmaVersion: 2022 diff --git a/README.md b/README.md index ad6c7ba4..4493ffa6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example.js b/example.js index 0a0d59c6..792c08e6 100644 --- a/example.js +++ b/example.js @@ -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: {} +}); diff --git a/package-lock.json b/package-lock.json index 65888c08..783cb9ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0-semantically-released", "license": "MIT", "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", @@ -1726,10 +1726,9 @@ } }, "node_modules/@form8ion/core": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/@form8ion/core/-/core-4.4.1.tgz", - "integrity": "sha512-GGctHNb5FVw8oMe/I8ZuW9wvdRVbwrdw9MHLb+RIHihGK0k6vsttcThNPEZyWn3PpKefjUIJmz5+xVTUU8BMSQ==", - "license": "MIT", + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@form8ion/core/-/core-4.6.0.tgz", + "integrity": "sha512-wDPYTFZvsLZln3wJRwd7g+ixpy3PGABVMjeJ7XHQIOQJjgEpS/ACBuyBNMfuC+MC/Pw9SF3CJBTCO0xS062t0g==", "dependencies": { "@hapi/hoek": "^11.0.2", "@travi/cli-messages": "^1.0.5", diff --git a/package.json b/package.json index 07c5299f..ad8a3a85 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/scaffolder.js b/src/scaffolder.js index cc3d2694..3c15f820 100644 --- a/src/scaffolder.js +++ b/src/scaffolder.js @@ -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}); diff --git a/src/scaffolder.test.js b/src/scaffolder.test.js index 11b409ae..5e7179f6 100644 --- a/src/scaffolder.test.js +++ b/src/scaffolder.test.js @@ -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] diff --git a/test/integration/features/step_definitions/dependency-updater-steps.js b/test/integration/features/step_definitions/dependency-updater-steps.js index 165ec2f8..d8584f4a 100644 --- a/test/integration/features/step_definitions/dependency-updater-steps.js +++ b/test/integration/features/step_definitions/dependency-updater-steps.js @@ -1,10 +1,15 @@ +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 () { @@ -12,13 +17,26 @@ After(function () { }); 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); });