Skip to content

Commit

Permalink
feat: add create and new alias for init
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Apr 12, 2021
1 parent 5ea478c commit a3c83d6
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/generators/src/index.ts
Expand Up @@ -12,7 +12,7 @@ class GeneratorsCommand {
await cli.makeCommand(
{
name: 'init [generation-path]',
alias: 'c',
alias: ['c', 'create', 'new'],
description: 'Initialize a new webpack project.',
usage: '[generation-path] [options]',
pkg: '@webpack-cli/generators',
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -654,7 +654,7 @@ class WebpackCLI {
},
{
name: 'init',
alias: 'c',
alias: ['c', 'create', 'new'],
pkg: '@webpack-cli/generators',
},
{
Expand Down
63 changes: 63 additions & 0 deletions test/init/__snapshots__/init.test.js.snap.webpack4
Expand Up @@ -365,6 +365,69 @@ module.exports = {
"
`;

exports[`init command should should work with 'c' alias 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"html-webpack-plugin": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
"webpack-dev-server": "x.x.x",
},
"name": "my-webpack-project",
"scripts": Object {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"serve": "webpack serve",
"watch": "webpack --watch",
},
"version": "1.0.0",
}
`;

exports[`init command should should work with 'create' alias 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"html-webpack-plugin": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
"webpack-dev-server": "x.x.x",
},
"name": "my-webpack-project",
"scripts": Object {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"serve": "webpack serve",
"watch": "webpack --watch",
},
"version": "1.0.0",
}
`;

exports[`init command should should work with 'new' alias 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"html-webpack-plugin": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
"webpack-dev-server": "x.x.x",
},
"name": "my-webpack-project",
"scripts": Object {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"serve": "webpack serve",
"watch": "webpack --watch",
},
"version": "1.0.0",
}
`;

exports[`init command should use less in project when selected 1`] = `
Object {
"description": "My webpack project",
Expand Down
63 changes: 63 additions & 0 deletions test/init/__snapshots__/init.test.js.snap.webpack5
Expand Up @@ -365,6 +365,69 @@ module.exports = {
"
`;

exports[`init command should should work with 'c' alias 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"html-webpack-plugin": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
"webpack-dev-server": "x.x.x",
},
"name": "my-webpack-project",
"scripts": Object {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"serve": "webpack serve",
"watch": "webpack --watch",
},
"version": "1.0.0",
}
`;

exports[`init command should should work with 'create' alias 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"html-webpack-plugin": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
"webpack-dev-server": "x.x.x",
},
"name": "my-webpack-project",
"scripts": Object {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"serve": "webpack serve",
"watch": "webpack --watch",
},
"version": "1.0.0",
}
`;

exports[`init command should should work with 'new' alias 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"html-webpack-plugin": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
"webpack-dev-server": "x.x.x",
},
"name": "my-webpack-project",
"scripts": Object {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"serve": "webpack serve",
"watch": "webpack --watch",
},
"version": "1.0.0",
}
`;

exports[`init command should use less in project when selected 1`] = `
Object {
"description": "My webpack project",
Expand Down
48 changes: 48 additions & 0 deletions test/init/init.test.js
Expand Up @@ -380,4 +380,52 @@ describe('init command', () => {
expect(exitCode).toBe(2);
expect(stderr).toContain('Failed to create directory');
});

it("should should work with 'new' alias", async () => {
const assetsPath = await uniqueDirectoryForTest(rootAssetsPath);
const { stdout, stderr } = await run(assetsPath, ['new', '--force']);
expect(stdout).toContain('Project has been initialised with webpack!');
expect(stderr).toContain('webpack.config.js');

// Test files
const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js'];
files.forEach((file) => {
expect(existsSync(resolve(assetsPath, file))).toBeTruthy();
});

// Check if the generated package.json file content matches the snapshot
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
});

it("should should work with 'create' alias", async () => {
const assetsPath = await uniqueDirectoryForTest(rootAssetsPath);
const { stdout, stderr } = await run(assetsPath, ['create', '--force']);
expect(stdout).toContain('Project has been initialised with webpack!');
expect(stderr).toContain('webpack.config.js');

// Test files
const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js'];
files.forEach((file) => {
expect(existsSync(resolve(assetsPath, file))).toBeTruthy();
});

// Check if the generated package.json file content matches the snapshot
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
});

it("should should work with 'c' alias", async () => {
const assetsPath = await uniqueDirectoryForTest(rootAssetsPath);
const { stdout, stderr } = await run(assetsPath, ['c', '--force']);
expect(stdout).toContain('Project has been initialised with webpack!');
expect(stderr).toContain('webpack.config.js');

// Test files
const files = ['package.json', 'src', 'src/index.js', 'webpack.config.js'];
files.forEach((file) => {
expect(existsSync(resolve(assetsPath, file))).toBeTruthy();
});

// Check if the generated package.json file content matches the snapshot
expect(readFromPkgJSON(assetsPath)).toMatchSnapshot();
});
});

0 comments on commit a3c83d6

Please sign in to comment.