Skip to content

Commit a7cba2f

Browse files
authored
chore: project maintanance and typescript fix (#1247)
* chore(generate-loader): : moved ts files to src folder and compile to lib * chore(generate-plugin): : moved ts files to src folder and compile to lib * chore(generators): : moved ts files to src folder and compile to lib * chore(info): : moved ts files to src folder and compile to lib * chore(init): : moved ts files to src folder and compile to lib * chore(migrate): : moved ts files to src folder and compile to lib * chore(serve): : moved ts files to src folder and compile to lib * chore(webpack-scaffold): : moved ts files to src folder and compile to lib * chore(utils): : moved ts files to src folder and compile to lib * chore(package-utils): created new package for processes and packages * chore(logger): logger module * chore(webpack-cli): use new packages for better usability * tests: create test for typescript * chore: added git ignores and changes to package * chore: added git ignore files * chore: renamed file * fix(generators): fix typing * chore: added references * chore: added composite and root dir to typescript config * fix(webpack-cli): removed logger * chore(migrate): fixed tests * fix(utils): broken test
1 parent 7748472 commit a7cba2f

File tree

269 files changed

+3603
-3284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+3603
-3284
lines changed

.eslintignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ test/**/**/dist/
1616
test/**/**/**/dist/
1717
test/**/**/index.js
1818
test/binCases/config-location/webpack-babel-config/bin/es6.js
19-
packages/**/*.js
19+
packages/**/lib
2020
packages/utils/validate-identifier.ts
2121

2222

23-
lib/utils/interactive.js
23+
lib/utils/interactive.js
24+
test/typescript/webpack.config.ts

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@
2323
"bundler",
2424
"web"
2525
],
26-
"files": [
27-
"lib",
28-
"bin/cli.js"
29-
],
3026
"workspaces": [
3127
"./packages/*"
3228
],
3329
"scripts": {
3430
"bootstrap": "lerna bootstrap",
35-
"build": "tsc",
31+
"build": "node scripts/buildPackages.js",
3632
"clean:all": "rimraf node_modules packages/*/{node_modules}",
3733
"commit": "git-cz",
3834
"docs": "typedoc",
3935
"format": "eslint --fix . --ext .js,.ts",
4036
"lint": "eslint . --ext .js,.ts",
37+
"lint:fix": "eslint . --ext .js,.ts --fix",
4138
"pretest": "yarn build && yarn lint",
4239
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
4340
"smoketest": "smoketests/smoketests.sh",

packages/generate-loader/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.js
2+
lib/

packages/generate-loader/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "@webpack-cli/generate-loader",
33
"version": "1.0.1-alpha.0",
44
"description": "A scaffold for generating a loader",
5-
"main": "index.js",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
67
"directories": {
78
"example": "examples",
89
"test": "test"
@@ -24,5 +25,10 @@
2425
"scripts": {
2526
"build": "tsc",
2627
"watch": "npm run build && tsc -w"
27-
}
28+
},
29+
"files": [
30+
"lib",
31+
"templates",
32+
"examples"
33+
]
2834
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import LoaderGenerator from "@webpack-cli/generators/loader-generator";
2-
import * as yeoman from "yeoman-environment";
1+
import { loaderGenerator } from "@webpack-cli/generators";
2+
import yeoman from "yeoman-environment";
33

44
/**
55
* Runs a yeoman generator to create a new webpack loader project
@@ -10,7 +10,7 @@ export default function loaderCreator(): void {
1010
const env = yeoman.createEnv();
1111
const generatorName = "webpack-loader-generator";
1212

13-
env.registerStub(LoaderGenerator, generatorName);
13+
env.registerStub(loaderGenerator, generatorName);
1414

1515
env.run(generatorName);
1616
}
+12-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
{
2-
"extends": "../../tsconfig.packages.json"
3-
}
1+
{
2+
"extends": "../../tsconfig.packages.json",
3+
"compilerOptions": {
4+
"outDir": "./lib",
5+
"rootDir": "./src",
6+
"composite": true
7+
},
8+
"include": ["./src"],
9+
"references": [
10+
{"path": "../generators"}
11+
]
12+
}

packages/generate-plugin/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.js
2+
lib/

packages/generate-plugin/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@webpack-cli/generate-plugin",
33
"version": "1.0.1-alpha.0",
44
"description": "A scaffold for generating a plugin",
5-
"main": "index.js",
5+
"main": "src/index.js",
66
"directories": {
77
"example": "examples",
88
"test": "test"
@@ -24,5 +24,10 @@
2424
"scripts": {
2525
"build": "tsc",
2626
"watch": "npm run build && tsc -w"
27-
}
27+
},
28+
"files": [
29+
"lib",
30+
"templates",
31+
"examples"
32+
]
2833
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PluginGenerator from "@webpack-cli/generators/plugin-generator";
2-
import * as yeoman from "yeoman-environment";
1+
import { pluginGenerator } from "@webpack-cli/generators";
2+
import yeoman from "yeoman-environment";
33

44
/**
55
* Runs a yeoman generator to create a new webpack plugin project
@@ -10,7 +10,7 @@ export default function pluginCreator(): void {
1010
const env = yeoman.createEnv();
1111
const generatorName = "webpack-plugin-generator";
1212

13-
env.registerStub(PluginGenerator, generatorName);
13+
env.registerStub(pluginGenerator, generatorName);
1414

1515
env.run(generatorName);
1616
}
+10-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
{
2-
"extends": "../../tsconfig.packages.json"
3-
}
1+
{
2+
"extends": "../../tsconfig.packages.json",
3+
"compilerOptions": {
4+
"outDir": "./lib",
5+
"rootDir": "./src",
6+
"composite": true
7+
},
8+
"include": ["./src"],
9+
"references": [{ "path": "../generators" }]
10+
}

packages/generators/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
!*.test.js
44
!/**/*.test.js
55
!/templates/*.js
6+
lib/

packages/generators/__tests__/init-generator.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { run } from 'yeoman-test';
44
// fixme: unstable
55
describe('init generator', () => {
66
it('generates a webpack project config', async () => {
7-
const outputDir = await run(join(__dirname, '../init-generator')).withPrompts({
7+
const outputDir = await run(join(__dirname, '../src/init-generator')).withPrompts({
88
multiEntries: false,
99
singularEntry: 'src/index2',
1010
outputDir: 'dist2',

packages/generators/__tests__/loader-generator.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from 'path';
22
import { run } from 'yeoman-test';
33
import assert from 'yeoman-assert';
44

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

77
describe('loader generator', () => {
88
it.skip('generates a default loader', async () => {

packages/generators/__tests__/plugin-generator.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from 'path';
22
import { run } from 'yeoman-test';
33
import assert from 'yeoman-assert';
44

5-
import { generatePluginName } from '../utils';
5+
import { generatePluginName } from '../src/utils';
66

77
describe('plugin generator', () => {
88
it.skip('generates a default plugin', async () => {

packages/generators/addon-generator.ts

-80
This file was deleted.

packages/generators/package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "@webpack-cli/generators",
33
"version": "1.0.1-alpha.0",
44
"description": "Webpack-CLI generators",
5-
"main": "index.js",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
67
"keywords": [],
78
"author": "",
89
"license": "MIT",
@@ -12,7 +13,8 @@
1213
"dependencies": {
1314
"@webpack-cli/utils": "^1.0.1-alpha.0",
1415
"@webpack-cli/webpack-scaffold": "^1.0.1-alpha.0",
15-
"chalk": "2.4.2",
16+
"@webpack-cli/package-utils": "^1.0.0",
17+
"chalk": "3.0.0",
1618
"glob-all": "3.1.0",
1719
"inquirer-autocomplete-prompt": "1.0.1",
1820
"lodash": "4.17.15",
@@ -21,6 +23,7 @@
2123
"webpack": "4.x.x",
2224
"webpack-dev-server": "3.8.0",
2325
"yeoman-generator": "4.5.0"
26+
2427
},
2528
"peerDependencies": {
2629
"webpack": "4.x.x"
@@ -42,5 +45,9 @@
4245
"scripts": {
4346
"build": "tsc",
4447
"watch": "npm run build && tsc -w"
45-
}
48+
},
49+
"files": [
50+
"lib",
51+
"templates"
52+
]
4653
}
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import mkdirp from 'mkdirp';
2+
import path from 'path';
3+
import Generator from 'yeoman-generator';
4+
import { generatorCopy, generatorCopyTpl } from '@webpack-cli/utils';
5+
6+
/**
7+
* Creates a Yeoman Generator that generates a project conforming
8+
* to webpack-defaults.
9+
*
10+
* @param {Generator.Questions} prompts An array of Yeoman prompt objects
11+
*
12+
* @param {string} templateDir Absolute path to template directory
13+
*
14+
* @param {string[]} copyFiles An array of file paths (relative to `./templates`)
15+
* of files to be copied to the generated project. File paths should be of the
16+
* form `path/to/file.js.tpl`.
17+
*
18+
* @param {string[]} copyTemplateFiles An array of file paths (relative to
19+
* `./templates`) of files to be copied to the generated project. Template
20+
* file paths should be of the form `path/to/_file.js.tpl`.
21+
*
22+
* @param {Function} templateFn A function that is passed a generator instance and
23+
* returns an object containing data to be supplied to the template files.
24+
*
25+
* @returns {Generator} A class extending Generator
26+
*/
27+
const addonGenerator = (
28+
prompts: Generator.Questions,
29+
templateDir: string,
30+
copyFiles: string[],
31+
copyTemplateFiles: string[],
32+
templateFn: Function,
33+
): typeof Generator => {
34+
return class extends Generator {
35+
public props: Generator.Question;
36+
public copy: (value: string, index: number, array: string[]) => void;
37+
public copyTpl: (value: string, index: number, array: string[]) => void;
38+
39+
public prompting(): Promise<void | {}> {
40+
return this.prompt(prompts).then((props: Generator.Question): void => {
41+
this.props = props;
42+
});
43+
}
44+
45+
public default(): void {
46+
const currentDirName = path.basename(this.destinationPath());
47+
if (currentDirName !== this.props.name) {
48+
this.log(`
49+
Your project must be inside a folder named ${this.props.name}
50+
I will create this folder for you.
51+
`);
52+
mkdirp(this.props.name, (err: object): void => {
53+
if (err) console.error('Failed to create directory', err);
54+
});
55+
const pathToProjectDir: string = this.destinationPath(this.props.name);
56+
this.destinationRoot(pathToProjectDir);
57+
}
58+
}
59+
60+
public writing(): void {
61+
this.copy = generatorCopy(this, templateDir);
62+
this.copyTpl = generatorCopyTpl(this, templateDir, templateFn(this));
63+
64+
copyFiles.forEach(this.copy);
65+
copyTemplateFiles.forEach(this.copyTpl);
66+
}
67+
68+
public install(): void {
69+
this.npmInstall(['webpack-defaults', 'bluebird'], {
70+
'save-dev': true,
71+
});
72+
}
73+
74+
public end(): void {
75+
this.spawnCommand('npm', ['run', 'defaults']);
76+
}
77+
};
78+
};
79+
80+
export default addonGenerator;
File renamed without changes.

0 commit comments

Comments
 (0)