Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/generators/__tests__/loader-generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import { join } from 'path';
import { run } from 'yeoman-test';
import assert from 'yeoman-assert';
import * as assert from 'yeoman-assert';

import { makeLoaderName } from '../src/loader-generator';

describe('loader generator', () => {
it.skip('generates a default loader', async () => {
const outputDir = await run(join(__dirname, '../loader-generator'));
const loaderDir = `${outputDir}/my-loader`;
it('generates a default loader', async () => {
const loaderName = 'my-test-loader';
const outputDir = await run(join(__dirname, '../src/loader-generator')).withPrompts({
name: loaderName,
});
const loaderDir = join(outputDir, loaderName);
const srcFiles = ['cjs.js', 'index.js'];
const testFiles = ['functional.test.js', 'test-utils.js', 'unit.test.js', 'fixtures/simple-file.js'];
const exampleFiles = ['webpack.config.js', 'src/index.js', 'src/lazy-module.js', 'src/static-esm-module.js'];

// Check that files in all folders are scaffolded. Checking them separately so we know which directory has the problem
// assert for src files
assert.file([...srcFiles.map(file => `${loaderDir}/src/${file}`)]);
assert.file(srcFiles.map(file => join(loaderDir, 'src', file)));

// assert for test files
assert.file([...testFiles.map(file => `${loaderDir}/test/${file}`)]);
assert.file(testFiles.map(file => join(loaderDir, 'test', file)));

// assert for example files
assert.file([...exampleFiles.map(file => `${loaderDir}/examples/simple/${file}`)]);
assert.file(exampleFiles.map(file => join(loaderDir, 'examples/simple', file)));

// Check the contents of the webpack config and loader file
assert.fileContent([
[`${loaderDir}/examples/simple/webpack.config.js`, /resolveLoader: {/],
[`${loaderDir}/src/index.js`, /export default function loader(source) {/],
[join(loaderDir, 'examples/simple/webpack.config.js'), /resolveLoader: {/],
[join(loaderDir, 'src/index.js'), /export default function loader\(source\) {/],
[join(loaderDir, 'package.json'), new RegExp(loaderName)],
]);

// higher timeout so travis has enough time to execute
Expand Down
22 changes: 13 additions & 9 deletions packages/generators/__tests__/plugin-generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import { join } from 'path';
import { run } from 'yeoman-test';
import assert from 'yeoman-assert';
import * as assert from 'yeoman-assert';

import { generatePluginName } from '../src/utils';

describe('plugin generator', () => {
it.skip('generates a default plugin', async () => {
const outputDir = await run(join(__dirname, '../plugin-generator'));
const pluginDir = `${outputDir}/my-webpack-plugin`;
it('generates a default plugin', async () => {
const pluginName = 'my-test-plugin';
const outputDir = await run(join(__dirname, '../src/plugin-generator')).withPrompts({
name: pluginName,
});
const pluginDir = join(outputDir, pluginName);
const srcFiles = ['cjs.js', 'index.js'];
const testFiles = ['functional.test.js', 'test-utils.js'];
const exampleFiles = ['webpack.config.js', 'src/index.js', 'src/lazy-module.js', 'src/static-esm-module.js'];

// Check that files in all folders are scaffolded. Checking them separately so we know which directory has the problem
// assert for src files
assert.file([...srcFiles.map(file => `${pluginDir}/src/${file}`)]);
assert.file(srcFiles.map(file => join(pluginDir, 'src', file)));

// assert for test files
assert.file([...testFiles.map(file => `${pluginDir}/test/${file}`)]);
assert.file(testFiles.map(file => join(pluginDir, 'test', file)));

// assert for example files
assert.file([...exampleFiles.map(file => `${pluginDir}/examples/simple/${file}`)]);
assert.file(exampleFiles.map(file => join(pluginDir, 'examples/simple', file)));

// Check the contents of the webpack config and loader file
assert.fileContent([
[`${pluginDir}/examples/simple/webpack.config.js`, /new MyWebpackPlugin()/],
[`${pluginDir}/src/index.js`, /MyWebpackPlugin.prototype.apply = function(compiler) {/],
[join(pluginDir, 'examples/simple/webpack.config.js'), /new MyTestPlugin\(\)/],
[join(pluginDir, 'src/index.js'), /MyTestPlugin\.prototype\.apply = function\(compiler\) {/],
[join(pluginDir, 'package.json'), new RegExp(pluginName)],
]);

// higher timeout so travis has enough time to execute
Expand Down
17 changes: 8 additions & 9 deletions packages/generators/src/addon-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,23 @@ const addonGenerator = (
}
}

public writing(): void {
this.copy = generatorCopy(this, templateDir);
public writing(): void {
const packageJsonTemplatePath = "../templates/addon-package.json.js";
this.fs.extendJSON(this.destinationPath("package.json"), require(packageJsonTemplatePath)(this.props.name));

this.copy = generatorCopy(this, templateDir);
this.copyTpl = generatorCopyTpl(this, templateDir, templateFn(this));

copyFiles.forEach(this.copy);
copyTemplateFiles.forEach(this.copyTpl);
}
}

public install(): void {
public install(): void {
this.npmInstall(['webpack-defaults', 'bluebird'], {
'save-dev': true,
});
}

public end(): void {
this.spawnCommand('npm', ['run', 'defaults']);
}
};
};
};

export default addonGenerator;
2 changes: 1 addition & 1 deletion packages/generators/src/loader-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const LoaderGenerator = addonGenerator(
validate: (str: string): boolean => str.length > 0
}
],
path.resolve(__dirname, "..", "generate-loader"),
path.resolve(__dirname, "../../generate-loader/templates"),
[
"src/cjs.js.tpl",
"test/test-utils.js.tpl",
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/src/plugin-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PluginGenerator = addonGenerator(
validate: (str: string): boolean => str.length > 0
}
],
path.resolve(__dirname, "..", "generate-plugin"),
path.resolve(__dirname, "../../generate-plugin/templates"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this! That was my fault

[
"src/cjs.js.tpl",
"test/test-utils.js.tpl",
Expand Down
8 changes: 8 additions & 0 deletions packages/generators/templates/addon-package.json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
module.exports = name => {
return {
version: "1.0.0",
description: "webpack loader",
name
};
};