Skip to content

Commit

Permalink
chore: project maintanance and typescript fix (#1247)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ematipico committed Feb 22, 2020
1 parent 7748472 commit a7cba2f
Show file tree
Hide file tree
Showing 269 changed files with 3,603 additions and 3,284 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Expand Up @@ -16,8 +16,9 @@ test/**/**/dist/
test/**/**/**/dist/
test/**/**/index.js
test/binCases/config-location/webpack-babel-config/bin/es6.js
packages/**/*.js
packages/**/lib
packages/utils/validate-identifier.ts


lib/utils/interactive.js
lib/utils/interactive.js
test/typescript/webpack.config.ts
7 changes: 2 additions & 5 deletions package.json
Expand Up @@ -23,21 +23,18 @@
"bundler",
"web"
],
"files": [
"lib",
"bin/cli.js"
],
"workspaces": [
"./packages/*"
],
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "tsc",
"build": "node scripts/buildPackages.js",
"clean:all": "rimraf node_modules packages/*/{node_modules}",
"commit": "git-cz",
"docs": "typedoc",
"format": "eslint --fix . --ext .js,.ts",
"lint": "eslint . --ext .js,.ts",
"lint:fix": "eslint . --ext .js,.ts --fix",
"pretest": "yarn build && yarn lint",
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
"smoketest": "smoketests/smoketests.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/generate-loader/.gitignore
@@ -1 +1,2 @@
*.js
lib/
File renamed without changes.
File renamed without changes.
10 changes: 8 additions & 2 deletions packages/generate-loader/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "@webpack-cli/generate-loader",
"version": "1.0.1-alpha.0",
"description": "A scaffold for generating a loader",
"main": "index.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"directories": {
"example": "examples",
"test": "test"
Expand All @@ -24,5 +25,10 @@
"scripts": {
"build": "tsc",
"watch": "npm run build && tsc -w"
}
},
"files": [
"lib",
"templates",
"examples"
]
}
@@ -1,5 +1,5 @@
import LoaderGenerator from "@webpack-cli/generators/loader-generator";
import * as yeoman from "yeoman-environment";
import { loaderGenerator } from "@webpack-cli/generators";
import yeoman from "yeoman-environment";

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

env.registerStub(LoaderGenerator, generatorName);
env.registerStub(loaderGenerator, generatorName);

env.run(generatorName);
}
15 changes: 12 additions & 3 deletions packages/generate-loader/tsconfig.json
@@ -1,3 +1,12 @@
{
"extends": "../../tsconfig.packages.json"
}
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./src",
"composite": true
},
"include": ["./src"],
"references": [
{"path": "../generators"}
]
}
1 change: 1 addition & 0 deletions packages/generate-plugin/.gitignore
@@ -1 +1,2 @@
*.js
lib/
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions packages/generate-plugin/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@webpack-cli/generate-plugin",
"version": "1.0.1-alpha.0",
"description": "A scaffold for generating a plugin",
"main": "index.js",
"main": "src/index.js",
"directories": {
"example": "examples",
"test": "test"
Expand All @@ -24,5 +24,10 @@
"scripts": {
"build": "tsc",
"watch": "npm run build && tsc -w"
}
},
"files": [
"lib",
"templates",
"examples"
]
}
@@ -1,5 +1,5 @@
import PluginGenerator from "@webpack-cli/generators/plugin-generator";
import * as yeoman from "yeoman-environment";
import { pluginGenerator } from "@webpack-cli/generators";
import yeoman from "yeoman-environment";

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

env.registerStub(PluginGenerator, generatorName);
env.registerStub(pluginGenerator, generatorName);

env.run(generatorName);
}
13 changes: 10 additions & 3 deletions packages/generate-plugin/tsconfig.json
@@ -1,3 +1,10 @@
{
"extends": "../../tsconfig.packages.json"
}
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./src",
"composite": true
},
"include": ["./src"],
"references": [{ "path": "../generators" }]
}
1 change: 1 addition & 0 deletions packages/generators/.gitignore
Expand Up @@ -3,3 +3,4 @@
!*.test.js
!/**/*.test.js
!/templates/*.js
lib/
2 changes: 1 addition & 1 deletion packages/generators/__tests__/init-generator.test.ts
Expand Up @@ -4,7 +4,7 @@ import { run } from 'yeoman-test';
// fixme: unstable
describe('init generator', () => {
it('generates a webpack project config', async () => {
const outputDir = await run(join(__dirname, '../init-generator')).withPrompts({
const outputDir = await run(join(__dirname, '../src/init-generator')).withPrompts({
multiEntries: false,
singularEntry: 'src/index2',
outputDir: 'dist2',
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/__tests__/loader-generator.test.ts
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path';
import { run } from 'yeoman-test';
import assert from 'yeoman-assert';

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

describe('loader generator', () => {
it.skip('generates a default loader', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/__tests__/plugin-generator.test.ts
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path';
import { run } from 'yeoman-test';
import assert from 'yeoman-assert';

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

describe('plugin generator', () => {
it.skip('generates a default plugin', async () => {
Expand Down
80 changes: 0 additions & 80 deletions packages/generators/addon-generator.ts

This file was deleted.

13 changes: 10 additions & 3 deletions packages/generators/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "@webpack-cli/generators",
"version": "1.0.1-alpha.0",
"description": "Webpack-CLI generators",
"main": "index.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [],
"author": "",
"license": "MIT",
Expand All @@ -12,7 +13,8 @@
"dependencies": {
"@webpack-cli/utils": "^1.0.1-alpha.0",
"@webpack-cli/webpack-scaffold": "^1.0.1-alpha.0",
"chalk": "2.4.2",
"@webpack-cli/package-utils": "^1.0.0",
"chalk": "3.0.0",
"glob-all": "3.1.0",
"inquirer-autocomplete-prompt": "1.0.1",
"lodash": "4.17.15",
Expand All @@ -21,6 +23,7 @@
"webpack": "4.x.x",
"webpack-dev-server": "3.8.0",
"yeoman-generator": "4.5.0"

},
"peerDependencies": {
"webpack": "4.x.x"
Expand All @@ -42,5 +45,9 @@
"scripts": {
"build": "tsc",
"watch": "npm run build && tsc -w"
}
},
"files": [
"lib",
"templates"
]
}
80 changes: 80 additions & 0 deletions packages/generators/src/addon-generator.ts
@@ -0,0 +1,80 @@
import mkdirp from 'mkdirp';
import path from 'path';
import Generator from 'yeoman-generator';
import { generatorCopy, generatorCopyTpl } from '@webpack-cli/utils';

/**
* Creates a Yeoman Generator that generates a project conforming
* to webpack-defaults.
*
* @param {Generator.Questions} prompts An array of Yeoman prompt objects
*
* @param {string} templateDir Absolute path to template directory
*
* @param {string[]} copyFiles An array of file paths (relative to `./templates`)
* of files to be copied to the generated project. File paths should be of the
* form `path/to/file.js.tpl`.
*
* @param {string[]} copyTemplateFiles An array of file paths (relative to
* `./templates`) of files to be copied to the generated project. Template
* file paths should be of the form `path/to/_file.js.tpl`.
*
* @param {Function} templateFn A function that is passed a generator instance and
* returns an object containing data to be supplied to the template files.
*
* @returns {Generator} A class extending Generator
*/
const addonGenerator = (
prompts: Generator.Questions,
templateDir: string,
copyFiles: string[],
copyTemplateFiles: string[],
templateFn: Function,
): typeof Generator => {
return class extends Generator {
public props: Generator.Question;
public copy: (value: string, index: number, array: string[]) => void;
public copyTpl: (value: string, index: number, array: string[]) => void;

public prompting(): Promise<void | {}> {
return this.prompt(prompts).then((props: Generator.Question): void => {
this.props = props;
});
}

public default(): void {
const currentDirName = path.basename(this.destinationPath());
if (currentDirName !== this.props.name) {
this.log(`
Your project must be inside a folder named ${this.props.name}
I will create this folder for you.
`);
mkdirp(this.props.name, (err: object): void => {
if (err) console.error('Failed to create directory', err);
});
const pathToProjectDir: string = this.destinationPath(this.props.name);
this.destinationRoot(pathToProjectDir);
}
}

public writing(): void {
this.copy = generatorCopy(this, templateDir);
this.copyTpl = generatorCopyTpl(this, templateDir, templateFn(this));

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

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

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

export default addonGenerator;
File renamed without changes.

0 comments on commit a7cba2f

Please sign in to comment.