Skip to content

Commit

Permalink
feat(js-plugin): expect a factory function to be passed for the full …
Browse files Browse the repository at this point in the history
…plugin rather than scaffolder
  • Loading branch information
travi committed Aug 27, 2024
1 parent 81aa86f commit 6c39e8e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $ npm install @form8ion/eslint-config-extender --save-prod
const {packageManagers} = await import('@form8ion/javascript-core');
const githubPlugin = await import('@form8ion/github');
const {questionNames: projectQuestionNames} = await import('@form8ion/project');
const {scaffold: javascriptScaffolder, questionNames: jsQuestionNames} = await import('@form8ion/javascript');
const javascriptPlugin = await import('@form8ion/javascript');
const {scaffold, extendEslintConfig} = await import('./lib/index.mjs');
```

Expand Down Expand Up @@ -83,18 +83,21 @@ const {scaffold, extendEslintConfig} = await import('./lib/index.mjs');
[projectQuestionNames.GIT_REPO]: true,
[projectQuestionNames.REPO_HOST]: 'GitHub',
[projectQuestionNames.REPO_OWNER]: 'org-name',
[jsQuestionNames.AUTHOR_NAME]: 'John Smith',
[jsQuestionNames.AUTHOR_EMAIL]: '[email protected]',
[jsQuestionNames.AUTHOR_URL]: 'https://smith.org',
[jsQuestionNames.SCOPE]: 'org-name',
[jsQuestionNames.PACKAGE_MANAGER]: packageManagers.NPM,
[jsQuestionNames.NODE_VERSION_CATEGORY]: 'LTS',
[jsQuestionNames.CI_SERVICE]: 'Other',
[jsQuestionNames.PROVIDE_EXAMPLE]: false
[javascriptPlugin.questionNames.AUTHOR_NAME]: 'John Smith',
[javascriptPlugin.questionNames.AUTHOR_EMAIL]: '[email protected]',
[javascriptPlugin.questionNames.AUTHOR_URL]: 'https://smith.org',
[javascriptPlugin.questionNames.SCOPE]: 'org-name',
[javascriptPlugin.questionNames.PACKAGE_MANAGER]: packageManagers.NPM,
[javascriptPlugin.questionNames.NODE_VERSION_CATEGORY]: 'LTS',
[javascriptPlugin.questionNames.CI_SERVICE]: 'Other',
[javascriptPlugin.questionNames.PROVIDE_EXAMPLE]: false
},
plugins: {vcsHosts: {GitHub: githubPlugin}}
},
decisions => options => javascriptScaffolder({...options, decisions, unitTestFrameworks: {}})
decisions => ({
...javascriptPlugin,
scaffold: options =>javascriptPlugin.scaffold({...options, decisions, unitTestFrameworks: {}})
})
);
})();
```
Expand Down
23 changes: 13 additions & 10 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ td.when(execa('npm', ['whoami'])).thenResolve({stdout: any.word()});
const {packageManagers} = await import('@form8ion/javascript-core');
const githubPlugin = await import('@form8ion/github');
const {questionNames: projectQuestionNames} = await import('@form8ion/project');
const {scaffold: javascriptScaffolder, questionNames: jsQuestionNames} = await import('@form8ion/javascript');
const javascriptPlugin = await import('@form8ion/javascript');
const {scaffold, extendEslintConfig} = await import('./lib/index.mjs');

// remark-usage-ignore-next
Expand Down Expand Up @@ -55,17 +55,20 @@ stubbedFs({node_modules: stubbedNodeModules});
[projectQuestionNames.GIT_REPO]: true,
[projectQuestionNames.REPO_HOST]: 'GitHub',
[projectQuestionNames.REPO_OWNER]: 'org-name',
[jsQuestionNames.AUTHOR_NAME]: 'John Smith',
[jsQuestionNames.AUTHOR_EMAIL]: '[email protected]',
[jsQuestionNames.AUTHOR_URL]: 'https://smith.org',
[jsQuestionNames.SCOPE]: 'org-name',
[jsQuestionNames.PACKAGE_MANAGER]: packageManagers.NPM,
[jsQuestionNames.NODE_VERSION_CATEGORY]: 'LTS',
[jsQuestionNames.CI_SERVICE]: 'Other',
[jsQuestionNames.PROVIDE_EXAMPLE]: false
[javascriptPlugin.questionNames.AUTHOR_NAME]: 'John Smith',
[javascriptPlugin.questionNames.AUTHOR_EMAIL]: '[email protected]',
[javascriptPlugin.questionNames.AUTHOR_URL]: 'https://smith.org',
[javascriptPlugin.questionNames.SCOPE]: 'org-name',
[javascriptPlugin.questionNames.PACKAGE_MANAGER]: packageManagers.NPM,
[javascriptPlugin.questionNames.NODE_VERSION_CATEGORY]: 'LTS',
[javascriptPlugin.questionNames.CI_SERVICE]: 'Other',
[javascriptPlugin.questionNames.PROVIDE_EXAMPLE]: false
},
plugins: {vcsHosts: {GitHub: githubPlugin}}
},
decisions => options => javascriptScaffolder({...options, decisions, unitTestFrameworks: {}})
decisions => ({
...javascriptPlugin,
scaffold: options => javascriptPlugin.scaffold({...options, decisions, unitTestFrameworks: {}})
})
);
})();
24 changes: 11 additions & 13 deletions src/high-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {questionNames as projectQuestionNames, scaffold} from '@form8ion/project

import {PLUGIN_NAME} from './constants.js';

export default function (options, javascriptScaffolderFactory) {
export default function (options, javascriptPluginFactory) {
const javaScriptLanguageChoice = 'JavaScript';

return scaffold(
Expand All @@ -15,18 +15,16 @@ export default function (options, javascriptScaffolderFactory) {
decisions: {[projectQuestionNames.PROJECT_LANGUAGE]: javaScriptLanguageChoice},
plugins: {
languages: {
[javaScriptLanguageChoice]: {
scaffold: javascriptScaffolderFactory({
...options.decisions,
[jsQuestionNames.PROJECT_TYPE]: 'Package',
[jsQuestionNames.PROJECT_TYPE_CHOICE]: PLUGIN_NAME,
[jsQuestionNames.UNIT_TESTS]: false,
[jsQuestionNames.INTEGRATION_TESTS]: false,
[jsQuestionNames.CONFIGURE_LINTING]: false,
[jsQuestionNames.DIALECT]: dialects.COMMON_JS,
[jsQuestionNames.SHOULD_BE_SCOPED]: true
})
}
[javaScriptLanguageChoice]: javascriptPluginFactory({
...options.decisions,
[jsQuestionNames.PROJECT_TYPE]: 'Package',
[jsQuestionNames.PROJECT_TYPE_CHOICE]: PLUGIN_NAME,
[jsQuestionNames.UNIT_TESTS]: false,
[jsQuestionNames.INTEGRATION_TESTS]: false,
[jsQuestionNames.CONFIGURE_LINTING]: false,
[jsQuestionNames.DIALECT]: dialects.COMMON_JS,
[jsQuestionNames.SHOULD_BE_SCOPED]: true
})
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/high-level.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe('high-level scaffolder', () => {
it('should execute the project-scaffolder', async () => {
const providedDecisions = any.simpleObject();
const options = {...any.simpleObject(), decisions: providedDecisions};
const jsScaffolder = any.simpleObject();
const javascriptScaffolderFactory = vi.fn();
when(javascriptScaffolderFactory).calledWith({
const jsPlugin = {scaffold: any.simpleObject()};
const javascriptPluginFactory = vi.fn();
when(javascriptPluginFactory).calledWith({
...providedDecisions,
[javascriptScaffolder.questionNames.PROJECT_TYPE]: 'Package',
[javascriptScaffolder.questionNames.PROJECT_TYPE_CHOICE]: PLUGIN_NAME,
Expand All @@ -32,14 +32,14 @@ describe('high-level scaffolder', () => {
[javascriptScaffolder.questionNames.CONFIGURE_LINTING]: false,
[javascriptScaffolder.questionNames.DIALECT]: dialects.COMMON_JS,
[javascriptScaffolder.questionNames.SHOULD_BE_SCOPED]: true
}).mockReturnValue(jsScaffolder);
}).mockReturnValue(jsPlugin);

await extendEslintConfig(options, javascriptScaffolderFactory);
await extendEslintConfig(options, javascriptPluginFactory);

expect(projectScaffolder.scaffold).toHaveBeenCalledWith({
...options,
decisions: {...providedDecisions, [projectScaffolder.questionNames.PROJECT_LANGUAGE]: 'JavaScript'},
plugins: {languages: {JavaScript: {scaffold: jsScaffolder}}}
plugins: {languages: {JavaScript: jsPlugin}}
});
});
});
14 changes: 8 additions & 6 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ When('the high-level scaffolder is executed', async function () {
vcsHosts: {[gitHubVcsHostChoice]: githubPlugin}
}
},
decisions => options => scaffoldJs({
...options,
unitTestFrameworks: {},
packageTypes: {[pluginName]: {scaffolder: scaffoldEslintConfig}},
configs: {eslint: {scope: `@${any.word()}`}},
decisions
decisions => ({
scaffold: options => scaffoldJs({
...options,
unitTestFrameworks: {},
packageTypes: {[pluginName]: {scaffolder: scaffoldEslintConfig}},
configs: {eslint: {scope: `@${any.word()}`}},
decisions
})
})
);
} catch (e) {
Expand Down

0 comments on commit 6c39e8e

Please sign in to comment.