diff --git a/README.md b/README.md index ce88b704..0278e13f 100644 --- a/README.md +++ b/README.md @@ -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'); ``` @@ -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]: 'john@smith.org', - [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]: 'john@smith.org', + [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: {}}) + }) ); })(); ``` diff --git a/example.js b/example.js index 17868009..5d8d4c64 100644 --- a/example.js +++ b/example.js @@ -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 @@ -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]: 'john@smith.org', - [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]: 'john@smith.org', + [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: {}}) + }) ); })(); diff --git a/src/high-level.js b/src/high-level.js index 90ef379e..b9d67463 100644 --- a/src/high-level.js +++ b/src/high-level.js @@ -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( @@ -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 + }) } } } diff --git a/src/high-level.test.js b/src/high-level.test.js index 8a71df1c..f630eb17 100644 --- a/src/high-level.test.js +++ b/src/high-level.test.js @@ -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, @@ -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}} }); }); }); diff --git a/test/integration/features/step_definitions/common-steps.js b/test/integration/features/step_definitions/common-steps.js index 6375ef90..0c01e4b3 100644 --- a/test/integration/features/step_definitions/common-steps.js +++ b/test/integration/features/step_definitions/common-steps.js @@ -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) {