Skip to content

Commit

Permalink
feat(bundlers): scaffolded the chosen bundler for package-type projects
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rollup is no longer provided as a default bundler, so bundler plugins (with rollup
being available as an option at https://github.com/form8ion/rollup) must be provided as an option to
the javascript scaffolder in order for bundling to be configured on new package-type projects
  • Loading branch information
travi committed May 17, 2022
1 parent 1e3a71f commit 77944b2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
24 changes: 12 additions & 12 deletions src/scaffolder/project-type/package/build-details-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {promises as fsPromises, promises as fs} from 'fs';
import mustache from 'mustache';
import {dialects, projectTypes} from '@form8ion/javascript-core';
import * as rollupScaffolder from '@form8ion/rollup';
import * as jsCore from '@form8ion/javascript-core';

import {assert} from 'chai';
import sinon from 'sinon';
Expand All @@ -20,7 +19,7 @@ suite('package build details', () => {
const projectName = any.word();
const pathToExample = `${projectRoot}/example.js`;
const pathToCreatedSrcDirectory = any.string();
const rollupResults = any.simpleObject();
const bundlerResults = any.simpleObject();
const exampleContent = any.string();
const pathToExampleTemplate = any.string();
const exampleTemplateContent = any.string();
Expand All @@ -36,7 +35,7 @@ suite('package build details', () => {
sandbox.stub(touch, 'default');
sandbox.stub(mkdir, 'default');
sandbox.stub(templatePath, 'default');
sandbox.stub(rollupScaffolder, 'scaffold');
sandbox.stub(jsCore, 'scaffoldChoice');
sandbox.stub(mustache, 'render');
sandbox.stub(camelcase, 'default');
sandbox.stub(bundlerPrompt, 'default');
Expand All @@ -51,24 +50,25 @@ suite('package build details', () => {
teardown(() => sandbox.restore());

test('that common-js project is defined correctly', async () => {
assert.deepEqual(await buildDetails({dialect: dialects.COMMON_JS, projectRoot, projectName}), {});
assert.deepEqual(await buildDetails({dialect: jsCore.dialects.COMMON_JS, projectRoot, projectName}), {});
assert.calledWith(fsPromises.writeFile, pathToExample, `const ${camelizedProjectName} = require('.');\n`);
assert.calledWith(touch.default, `${projectRoot}/index.js`);
});

test('that a modern-js project is defined correctly', async () => {
const dialect = dialects.BABEL;
rollupScaffolder.scaffold
.withArgs({projectRoot, dialect, projectType: projectTypes.PACKAGE})
.resolves(rollupResults);
const dialect = jsCore.dialects.BABEL;
const chosenBundler = any.word();
bundlerPrompt.default.withArgs({bundlers: packageBundlers, decisions}).resolves(chosenBundler);
jsCore.scaffoldChoice
.withArgs(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: jsCore.projectTypes.PACKAGE})
.resolves(bundlerResults);

const results = await buildDetails({dialect, projectRoot, projectName, packageBundlers, decisions});

assert.calledWith(bundlerPrompt.default, {bundlers: packageBundlers, decisions});
assert.deepEqual(
results,
{
...rollupResults,
...bundlerResults,
devDependencies: ['rimraf'],
scripts: {
clean: 'rimraf ./lib',
Expand All @@ -89,7 +89,7 @@ suite('package build details', () => {
const packageName = any.word();

const {badges} = await buildDetails({
dialect: dialects.BABEL,
dialect: jsCore.dialects.BABEL,
projectRoot,
projectName,
packageName,
Expand Down
7 changes: 3 additions & 4 deletions src/scaffolder/project-type/package/build-details.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {promises as fs} from 'fs';
import deepmerge from 'deepmerge';
import mustache from 'mustache';
import {dialects, projectTypes} from '@form8ion/javascript-core';
import {scaffold as scaffoldRollup} from '@form8ion/rollup';
import {dialects, projectTypes, scaffoldChoice as scaffoldChosenBundler} from '@form8ion/javascript-core';

import camelcase from '../../../../thirdparty-wrappers/camelcase';
import mkdir from '../../../../thirdparty-wrappers/make-dir';
Expand Down Expand Up @@ -42,11 +41,11 @@ export default async function ({
}) {
if (dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});

await chooseBundler({bundlers: packageBundlers, decisions});
const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});

const pathToCreatedSrcDirectory = await mkdir(`${projectRoot}/src`);
const [bundlerResults] = await Promise.all([
scaffoldRollup({projectRoot, dialect, projectType: projectTypes.PACKAGE}),
scaffoldChosenBundler(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: projectTypes.PACKAGE}),
await createExample(projectRoot, projectName),
touch(`${pathToCreatedSrcDirectory}/index.js`)
]);
Expand Down
1 change: 0 additions & 1 deletion test/integration/features/scaffold/dialect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ Feature: Dialects
When the project is scaffolded
Then no error is thrown
And the "typescript" dialect is configured
And the package is bundled with rollup
1 change: 0 additions & 1 deletion test/integration/features/scaffold/package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Feature: Package Project Type
Then no repository details will be defined
And the expected details are provided for a root-level project
And the expected files for a "Package" are generated
And the package is bundled with rollup
And the expected results for a "Package" are returned to the project scaffolder

Scenario: Minimal Options w/ Version Control
Expand Down
12 changes: 0 additions & 12 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ Before(async function () {
templates: {
'example.mustache': await fs.readFile(resolve(...pathToProjectRoot, 'templates', 'example.mustache'))
}
},
rollup: {
templates: {
'rollup.config.js': await fs.readFile(resolve(
...pathToNodeModules,
'@form8ion',
'rollup',
'templates',
'rollup.config.js'
))
}
}
},
node_modules: stubbedNodeModules
Expand All @@ -86,7 +75,6 @@ Before(async function () {
this.visibility = any.fromList(['Public', 'Private']);
this.eslintScope = `@${any.word()}`;
this.barUnitTestFrameworkEslintConfigs = any.listOf(any.word);
// this.fooApplicationEslintConfigs = any.listOf(() => ({name: any.word(), files: any.word()}));
this.fooApplicationEslintConfigs = [(() => ({name: any.word(), files: any.word()}))()];
this.fooMonorepoScripts = any.simpleObject();
});
Expand Down

0 comments on commit 77944b2

Please sign in to comment.