@pinnacle0/webpack-util 0.3.16-beta1 → 0.3.16-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/CanadyarnRunner.d.ts +14 -0
- package/src/CanadyarnRunner.js +38 -0
- package/src/CanadyarnRunner.js.map +1 -0
- package/src/CodeStyleChecker.d.ts +10 -0
- package/src/CodeStyleChecker.js +44 -0
- package/src/CodeStyleChecker.js.map +1 -0
- package/src/Constant.d.ts +21 -0
- package/src/{Constant.ts → Constant.js} +5 -1
- package/src/Constant.js.map +1 -0
- package/src/CoreUtil.d.ts +11 -0
- package/src/CoreUtil.js +26 -0
- package/src/CoreUtil.js.map +1 -0
- package/src/ProjectStructureChecker.d.ts +18 -0
- package/src/ProjectStructureChecker.js +113 -0
- package/src/ProjectStructureChecker.js.map +1 -0
- package/src/TestRunner.d.ts +8 -0
- package/src/TestRunner.js +30 -0
- package/src/TestRunner.js.map +1 -0
- package/src/WebpackBuilder.d.ts +38 -0
- package/src/{WebpackBuilder.ts → WebpackBuilder.js} +49 -69
- package/src/WebpackBuilder.js.map +1 -0
- package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.d.ts +13 -0
- package/src/WebpackConfigGenerator/{ConfigEntryDescriptorsFactory.ts → ConfigEntryDescriptorsFactory.js} +29 -36
- package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.d.ts +9 -0
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js +20 -0
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.d.ts +16 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.js +33 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.d.ts +2 -0
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.js +14 -0
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.d.ts +16 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.js +48 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/index.d.ts +29 -0
- package/src/WebpackConfigGenerator/Plugin/index.js +34 -0
- package/src/WebpackConfigGenerator/Plugin/index.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/moment.plugin.d.ts +10 -0
- package/src/WebpackConfigGenerator/Plugin/{moment.plugin.ts → moment.plugin.js} +12 -5
- package/src/WebpackConfigGenerator/Plugin/moment.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.d.ts +4 -0
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js +28 -0
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.d.ts +16 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.js +31 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.d.ts +14 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js +24 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/RegExpUtil.d.ts +4 -0
- package/src/WebpackConfigGenerator/Rule/{RegExpUtil.ts → RegExpUtil.js} +14 -8
- package/src/WebpackConfigGenerator/Rule/RegExpUtil.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.d.ts +13 -0
- package/src/WebpackConfigGenerator/Rule/{core-fe-hmr-babel-plugin.ts → core-fe-hmr-babel-plugin.js} +9 -43
- package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/image.rule.d.ts +9 -0
- package/src/WebpackConfigGenerator/Rule/{image.rule.ts → image.rule.js} +8 -5
- package/src/WebpackConfigGenerator/Rule/image.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/index.d.ts +13 -0
- package/src/WebpackConfigGenerator/Rule/index.js +18 -0
- package/src/WebpackConfigGenerator/Rule/index.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.d.ts +12 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.js +22 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/stylesheet.rule.d.ts +17 -0
- package/src/WebpackConfigGenerator/Rule/{stylesheet.rule.ts → stylesheet.rule.js} +30 -34
- package/src/WebpackConfigGenerator/Rule/stylesheet.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/ts.rule.d.ts +19 -0
- package/src/WebpackConfigGenerator/Rule/{ts.rule.ts → ts.rule.js} +16 -19
- package/src/WebpackConfigGenerator/Rule/ts.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.d.ts +10 -0
- package/src/WebpackConfigGenerator/{WebpackConfigSerializationUtil.ts → WebpackConfigSerializationUtil.js} +22 -23
- package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackEntryFactory.d.ts +9 -0
- package/src/WebpackConfigGenerator/WebpackEntryFactory.js +14 -0
- package/src/WebpackConfigGenerator/WebpackEntryFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.d.ts +11 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js +16 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.d.ts +11 -0
- package/src/WebpackConfigGenerator/{WebpackResolveAliasFactory.ts → WebpackResolveAliasFactory.js} +13 -16
- package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.d.ts +7 -0
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js +16 -0
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.d.ts +7 -0
- package/src/WebpackConfigGenerator/{WebpackResolveModulesFactory.ts → WebpackResolveModulesFactory.js} +7 -9
- package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/index.d.ts +31 -0
- package/src/WebpackConfigGenerator/index.js +191 -0
- package/src/WebpackConfigGenerator/index.js.map +1 -0
- package/src/WebpackServerStarter.d.ts +28 -0
- package/src/WebpackServerStarter.js +111 -0
- package/src/WebpackServerStarter.js.map +1 -0
- package/src/index.d.ts +10 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/{type.ts → type.d.ts} +4 -8
- package/src/type.js +3 -0
- package/src/type.js.map +1 -0
- package/config/jest.config.ts +0 -35
- package/config/tsconfig.script.json +0 -11
- package/config/tsconfig.src.json +0 -12
- package/config/tsconfig.test.json +0 -12
- package/script/build.ts +0 -65
- package/script/format.ts +0 -7
- package/src/CanadyarnRunner.ts +0 -35
- package/src/CodeStyleChecker.ts +0 -44
- package/src/CoreUtil.ts +0 -24
- package/src/ProjectStructureChecker.ts +0 -119
- package/src/TestRunner.ts +0 -28
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.ts +0 -24
- package/src/WebpackConfigGenerator/Plugin/css.plugin.ts +0 -31
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.ts +0 -11
- package/src/WebpackConfigGenerator/Plugin/html.plugin.ts +0 -47
- package/src/WebpackConfigGenerator/Plugin/index.ts +0 -35
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.ts +0 -22
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.ts +0 -29
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.ts +0 -21
- package/src/WebpackConfigGenerator/Rule/index.ts +0 -17
- package/src/WebpackConfigGenerator/Rule/other.rule.ts +0 -23
- package/src/WebpackConfigGenerator/WebpackEntryFactory.ts +0 -22
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.ts +0 -22
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.ts +0 -19
- package/src/WebpackConfigGenerator/index.ts +0 -213
- package/src/WebpackServerStarter.ts +0 -138
- package/src/index.ts +0 -9
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldIgnore.test.ts.snap +0 -21
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldTransform.test.ts.snap +0 -53
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldIgnore.test.ts +0 -36
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldTransform.test.ts +0 -72
- package/test/WebpackConfigGenerator/plugin/fixture/script.js +0 -2
- package/test/WebpackConfigGenerator/plugin/fixture/script1.js +0 -1
- package/test/WebpackConfigGenerator/plugin/script-tag-crossorigin-plugin.test.ts +0 -58
- package/test/test-project/package.json +0 -5
- package/tsconfig.json +0 -15
package/config/tsconfig.src.json
DELETED
package/script/build.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {PrettierUtil, TaskRunner, Utility} from "@pinnacle0/devtool-util";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
const FilePath = {
|
|
6
|
-
config: path.join(__dirname, "../config"),
|
|
7
|
-
build: path.join(__dirname, "../build"),
|
|
8
|
-
script: path.join(__dirname, "../script"),
|
|
9
|
-
src: path.join(__dirname, "../src"),
|
|
10
|
-
|
|
11
|
-
jestConfig: path.join(__dirname, "../config/jest.config.ts"),
|
|
12
|
-
tsConfigForSrc: path.join(__dirname, "../config/tsconfig.src.json"),
|
|
13
|
-
projectPackageJSON: path.join(__dirname, "../package.json"),
|
|
14
|
-
projectReadMe: path.join(__dirname, "../README.md"),
|
|
15
|
-
projectLicense: path.join(__dirname, "../LICENSE.md"),
|
|
16
|
-
buildPackageJSON: path.join(__dirname, "../build/package.json"),
|
|
17
|
-
buildReadMe: path.join(__dirname, "../build/README.md"),
|
|
18
|
-
buildLicense: path.join(__dirname, "../build/LICENSE.md"),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
new TaskRunner("build").execute([
|
|
22
|
-
{
|
|
23
|
-
name: "code style check",
|
|
24
|
-
skipInFastMode: true,
|
|
25
|
-
execute: () => {
|
|
26
|
-
PrettierUtil.check(FilePath.config);
|
|
27
|
-
PrettierUtil.check(FilePath.script);
|
|
28
|
-
PrettierUtil.check(FilePath.src);
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: "lint",
|
|
33
|
-
skipInFastMode: true,
|
|
34
|
-
execute: () => {
|
|
35
|
-
Utility.runCommand("eslint", ["--ext=.js,.jsx,.ts,.tsx", FilePath.src]);
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "test",
|
|
40
|
-
skipInFastMode: true,
|
|
41
|
-
execute: () => {
|
|
42
|
-
Utility.runCommand("jest", ["--config", FilePath.jestConfig, "--bail"]);
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "prepare build directory",
|
|
47
|
-
execute: () => {
|
|
48
|
-
Utility.prepareEmptyDirectory(FilePath.build);
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "compile with tsc",
|
|
53
|
-
execute: () => {
|
|
54
|
-
Utility.runCommand("tsc", ["--project", FilePath.tsConfigForSrc]);
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: "copy package.json, markdown files",
|
|
59
|
-
execute: () => {
|
|
60
|
-
fs.copyFileSync(FilePath.projectPackageJSON, FilePath.buildPackageJSON);
|
|
61
|
-
fs.copyFileSync(FilePath.projectReadMe, FilePath.buildReadMe);
|
|
62
|
-
fs.copyFileSync(FilePath.projectLicense, FilePath.buildLicense);
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
]);
|
package/script/format.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import {PrettierUtil} from "@pinnacle0/devtool-util";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
PrettierUtil.format(path.join(__dirname, "../config"));
|
|
5
|
-
PrettierUtil.format(path.join(__dirname, "../script"));
|
|
6
|
-
PrettierUtil.format(path.join(__dirname, "../src"));
|
|
7
|
-
PrettierUtil.format(path.join(__dirname, "../test"));
|
package/src/CanadyarnRunner.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {Utility} from "@pinnacle0/devtool-util";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* `canadyarn` is a mono-repo package version checker for single version installation, developed by Pinnacle team.
|
|
6
|
-
*
|
|
7
|
-
* Ref: https://www.npmjs.com/package/canadyarn
|
|
8
|
-
*/
|
|
9
|
-
export class CanadyarnRunner {
|
|
10
|
-
private readonly rootDirectory: string;
|
|
11
|
-
private readonly logger = Utility.createConsoleLogger("CanadyarnRunner");
|
|
12
|
-
|
|
13
|
-
constructor({rootDirectory}: {rootDirectory: string}) {
|
|
14
|
-
this.rootDirectory = rootDirectory;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
run() {
|
|
18
|
-
this.runCanadyarn();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private runCanadyarn() {
|
|
22
|
-
const packageJSONPath = this.rootDirectory + "/package.json";
|
|
23
|
-
|
|
24
|
-
if (fs.existsSync(packageJSONPath) && fs.statSync(packageJSONPath).isFile()) {
|
|
25
|
-
const packageJSONContents: Record<string, any> = JSON.parse(fs.readFileSync(packageJSONPath, {encoding: "utf8"}));
|
|
26
|
-
|
|
27
|
-
if (packageJSONContents?.scripts?.canadyarn) {
|
|
28
|
-
this.logger.task("Running `canadyarn` at " + this.rootDirectory);
|
|
29
|
-
Utility.runCommand("yarn", ["--cwd", this.rootDirectory, "canadyarn"]);
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error(`Cannot load root directory [${this.rootDirectory}] package.json`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/CodeStyleChecker.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {PrettierUtil, Utility} from "@pinnacle0/devtool-util";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import type {InternalCheckerOptions} from "./type";
|
|
5
|
-
|
|
6
|
-
export class CodeStyleChecker {
|
|
7
|
-
private readonly checkableSrcDirectories: [string, ...string[]];
|
|
8
|
-
private readonly logger = Utility.createConsoleLogger("CodeStyleChecker");
|
|
9
|
-
|
|
10
|
-
constructor({projectDirectory, extraCheckDirectories = []}: InternalCheckerOptions) {
|
|
11
|
-
this.checkableSrcDirectories = [path.join(projectDirectory, "src")];
|
|
12
|
-
for (const directory of extraCheckDirectories) {
|
|
13
|
-
const others = ["test", "script"].map(folder => path.join(directory, folder)).filter(path => fs.existsSync(path));
|
|
14
|
-
this.checkableSrcDirectories.push(path.join(directory, "src"), ...others);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
run() {
|
|
19
|
-
this.checkPrettier();
|
|
20
|
-
this.checkESLint();
|
|
21
|
-
this.checkStylelint();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private checkPrettier() {
|
|
25
|
-
this.logger.task("Checking Prettier");
|
|
26
|
-
for (const srcDirectory of this.checkableSrcDirectories) {
|
|
27
|
-
PrettierUtil.check(srcDirectory);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private checkESLint() {
|
|
32
|
-
this.logger.task("Checking ESLint");
|
|
33
|
-
for (const srcDirectory of this.checkableSrcDirectories) {
|
|
34
|
-
Utility.runCommand("eslint", ["--no-error-on-unmatched-pattern", "--max-warnings=1", "--ext=.js,.jsx,.ts,.tsx", srcDirectory]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private checkStylelint() {
|
|
39
|
-
this.logger.task("Checking Stylelint");
|
|
40
|
-
for (const srcDirectory of this.checkableSrcDirectories) {
|
|
41
|
-
Utility.runCommand("stylelint", ["--allow-empty-input", "--max-warnings=1", path.join(srcDirectory, "**/*.{css,less}")]);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/CoreUtil.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import yargs from "yargs";
|
|
2
|
-
|
|
3
|
-
function currentEnv(): string | null {
|
|
4
|
-
return (yargs.parseSync().env as string) || null;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function profilingEnabled(): boolean {
|
|
8
|
-
return Boolean(yargs.parseSync().profile);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function isFastMode(): boolean {
|
|
12
|
-
return yargs.parseSync().mode === "fast";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function verbose(): boolean {
|
|
16
|
-
return Boolean(yargs.parseSync().verbose);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const CoreUtil = Object.freeze({
|
|
20
|
-
currentEnv,
|
|
21
|
-
profilingEnabled,
|
|
22
|
-
isFastMode,
|
|
23
|
-
verbose,
|
|
24
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import {Constant} from "./Constant";
|
|
4
|
-
import type {InternalCheckerOptions} from "./type";
|
|
5
|
-
|
|
6
|
-
export class ProjectStructureChecker {
|
|
7
|
-
private readonly projectDirectory: string;
|
|
8
|
-
private readonly extraCheckDirectories: string[];
|
|
9
|
-
private readonly packageJSONPath: string;
|
|
10
|
-
private readonly tsConfigPath: string;
|
|
11
|
-
|
|
12
|
-
constructor(private readonly options: InternalCheckerOptions) {
|
|
13
|
-
this.projectDirectory = options.projectDirectory;
|
|
14
|
-
this.extraCheckDirectories = options.extraCheckDirectories ?? [];
|
|
15
|
-
this.packageJSONPath = path.join(options.projectDirectory, "package.json");
|
|
16
|
-
this.tsConfigPath = path.join(options.projectDirectory, "tsconfig.json");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
run() {
|
|
20
|
-
this.checkMainProjectDirectory();
|
|
21
|
-
this.checkMainProjectSrcDirectory();
|
|
22
|
-
this.checkExtraDirectories();
|
|
23
|
-
this.checkPackageJSON();
|
|
24
|
-
this.checkTSConfig();
|
|
25
|
-
|
|
26
|
-
this.checkPrettierInstallation();
|
|
27
|
-
this.checkESLintInstallation();
|
|
28
|
-
this.checkStyleLintInstallation();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private checkMainProjectDirectory() {
|
|
32
|
-
if (!(fs.existsSync(this.projectDirectory) && fs.statSync(this.projectDirectory).isDirectory())) {
|
|
33
|
-
throw new Error(`Cannot check project directory at "${this.projectDirectory}" because it is not a folder.`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const mainProjectStaticDirectory = path.join(this.projectDirectory, "static");
|
|
37
|
-
if (!(fs.existsSync(mainProjectStaticDirectory) && fs.statSync(mainProjectStaticDirectory).isDirectory())) {
|
|
38
|
-
throw new Error(`Cannot find "static" directory in project at "${this.projectDirectory}"`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private checkMainProjectSrcDirectory() {
|
|
43
|
-
const mainProjectSrcDirectory = path.join(this.projectDirectory, "src");
|
|
44
|
-
if (!(fs.existsSync(mainProjectSrcDirectory) && fs.statSync(mainProjectSrcDirectory).isDirectory())) {
|
|
45
|
-
throw new Error(`Cannot find "src" folder inside directory at "${this.projectDirectory}".`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let isMainEntryFound = false;
|
|
49
|
-
Constant.mainEntryFilenames
|
|
50
|
-
.map(entryName => path.join(mainProjectSrcDirectory, entryName))
|
|
51
|
-
.forEach(entryPath => {
|
|
52
|
-
if (fs.existsSync(entryPath) && fs.statSync(entryPath).isFile()) {
|
|
53
|
-
isMainEntryFound = true;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
if (!isMainEntryFound) {
|
|
57
|
-
throw new Error(`Cannot find main entry file in src/ at "${mainProjectSrcDirectory}"; checked: ${Constant.mainEntryFilenames.map(_ => `"${_}"`).join(" / ")}.`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private checkExtraDirectories() {
|
|
62
|
-
for (const extraCheckDirectory of this.extraCheckDirectories) {
|
|
63
|
-
if (!(fs.existsSync(extraCheckDirectory) && fs.statSync(extraCheckDirectory).isDirectory())) {
|
|
64
|
-
throw new Error(`Cannot check extra directory at "${extraCheckDirectory}" because it is not a folder.`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private checkPackageJSON() {
|
|
70
|
-
if (!(fs.existsSync(this.packageJSONPath) && fs.statSync(this.packageJSONPath).isFile())) {
|
|
71
|
-
throw new Error(`Cannot find package.json at "${this.packageJSONPath}".`);
|
|
72
|
-
}
|
|
73
|
-
const packageJSONContents: Record<string, any> = JSON.parse(fs.readFileSync(this.packageJSONPath, {encoding: "utf8"}));
|
|
74
|
-
for (const [depName, depVersion] of Object.entries<string>(packageJSONContents.dependencies || {})) {
|
|
75
|
-
if (!/^\d/.test(depVersion)) {
|
|
76
|
-
throw new Error(`Dependency "${depName}" must be an exact version, but found "${depVersion}" in package.json at "${this.packageJSONPath}".`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
for (const [depName, depVersion] of Object.entries<string>(packageJSONContents.devDependencies || {})) {
|
|
80
|
-
if (!/^\d/.test(depVersion)) {
|
|
81
|
-
throw new Error(`Dependency "${depName}" must be an exact version, but found "${depVersion}" in package.json at "${this.packageJSONPath}".`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private checkTSConfig() {
|
|
87
|
-
const mainProjectSrcDirectory = path.join(this.projectDirectory, "src");
|
|
88
|
-
// Checking the first-level of src/* is enough here
|
|
89
|
-
const hasTSFiles = fs.readdirSync(mainProjectSrcDirectory).some(fileName => fileName.endsWith(".ts") || fileName.endsWith(".tsx"));
|
|
90
|
-
const hasTSConfigFile = fs.existsSync(this.tsConfigPath) && fs.statSync(this.tsConfigPath).isFile();
|
|
91
|
-
if (hasTSFiles && !hasTSConfigFile) {
|
|
92
|
-
throw new Error(`Cannot find tsconfig.json at "${this.tsConfigPath}".`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private checkPrettierInstallation() {
|
|
97
|
-
try {
|
|
98
|
-
require("prettier");
|
|
99
|
-
} catch {
|
|
100
|
-
throw new Error(`Cannot load prettier module (requiring from "webpack-util"), make sure prettier is installed.`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private checkESLintInstallation() {
|
|
105
|
-
try {
|
|
106
|
-
require("eslint");
|
|
107
|
-
} catch {
|
|
108
|
-
throw new Error(`Cannot load eslint module (requiring from "webpack-util"), make sure eslint is installed.`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private checkStyleLintInstallation() {
|
|
113
|
-
try {
|
|
114
|
-
require("stylelint");
|
|
115
|
-
} catch {
|
|
116
|
-
throw new Error(`Cannot load stylelint module (requiring from "webpack-util"), make sure stylelint is installed.`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
package/src/TestRunner.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {Utility} from "@pinnacle0/devtool-util";
|
|
2
|
-
import type {InternalCheckerOptions} from "./type";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
export class TestRunner {
|
|
6
|
-
private readonly directories: [string, ...string[]];
|
|
7
|
-
private readonly logger = Utility.createConsoleLogger("TestRunner");
|
|
8
|
-
|
|
9
|
-
constructor({projectDirectory, extraCheckDirectories = []}: InternalCheckerOptions) {
|
|
10
|
-
this.directories = [projectDirectory, ...extraCheckDirectories];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
run() {
|
|
14
|
-
this.directories.forEach(dir => this.runTestScript(dir));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private runTestScript(directory: string) {
|
|
18
|
-
const packageJSONPath = directory + "/package.json";
|
|
19
|
-
if (fs.existsSync(packageJSONPath) && fs.statSync(packageJSONPath).isFile()) {
|
|
20
|
-
const packageJSONContents: Record<string, any> = JSON.parse(fs.readFileSync(packageJSONPath, {encoding: "utf8"}));
|
|
21
|
-
|
|
22
|
-
if (packageJSONContents?.scripts?.test) {
|
|
23
|
-
this.logger.task("Running `yarn test` at " + directory);
|
|
24
|
-
Utility.runCommand("yarn", ["--cwd", directory, "test"]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type webpack from "webpack";
|
|
2
|
-
import type {EntryDescriptor} from "../type";
|
|
3
|
-
import {Plugin} from "./Plugin";
|
|
4
|
-
|
|
5
|
-
interface HTMLWebpackPluginsFactoryOptions {
|
|
6
|
-
configEntryDescriptors: EntryDescriptor[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class HTMLWebpackPluginsFactory {
|
|
10
|
-
static generate({configEntryDescriptors}: HTMLWebpackPluginsFactoryOptions): webpack.Plugin[] {
|
|
11
|
-
const htmlPlugins: webpack.Plugin[] = [];
|
|
12
|
-
|
|
13
|
-
for (const {name, entryPath, htmlPath} of configEntryDescriptors) {
|
|
14
|
-
if (htmlPath !== undefined) {
|
|
15
|
-
const plugin = Plugin.fileOutput.html({
|
|
16
|
-
entry: {name, entryPath, htmlPath},
|
|
17
|
-
});
|
|
18
|
-
htmlPlugins.push(plugin);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return htmlPlugins;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import CssMinimizerWebpackPlugin from "css-minimizer-webpack-plugin";
|
|
2
|
-
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
3
|
-
import type webpack from "webpack";
|
|
4
|
-
import {WebpackConfigSerializationUtil} from "../WebpackConfigSerializationUtil";
|
|
5
|
-
|
|
6
|
-
interface ExtractCssPluginOptions {
|
|
7
|
-
enableProfiling: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Applies CssNano to minimize stylesheets
|
|
12
|
-
* after bundles/chunks are built.
|
|
13
|
-
*/
|
|
14
|
-
export function cssMinimizerPlugin(): webpack.WebpackPluginInstance {
|
|
15
|
-
return WebpackConfigSerializationUtil.serializablePlugin("CssMinimizerWebpackPlugin", CssMinimizerWebpackPlugin);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extract output of css transformation pipeline to standalone css files.
|
|
20
|
-
* Must be used with `MiniCssExtractPlugin.loader`, which is included with
|
|
21
|
-
* `Rule.stylesheet({minimize: true})`.
|
|
22
|
-
*/
|
|
23
|
-
export function miniCssExtractPlugin({enableProfiling}: ExtractCssPluginOptions): webpack.WebpackPluginInstance {
|
|
24
|
-
return WebpackConfigSerializationUtil.serializablePlugin("MiniCssExtractPlugin", MiniCssExtractPlugin, {
|
|
25
|
-
filename: enableProfiling ? "static/css/[name].[contenthash:8].css" : "static/css/[contenthash:8].css",
|
|
26
|
-
// order of css output depends on the order of imports in js,
|
|
27
|
-
// unless all imports in js are sorted (e.g. by alphabetical order),
|
|
28
|
-
// this flag must be set to true to avoid error
|
|
29
|
-
ignoreOrder: true,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type webpack from "webpack";
|
|
2
|
-
import {ESBuildMinifyPlugin} from "esbuild-loader";
|
|
3
|
-
import {WebpackConfigSerializationUtil} from "../WebpackConfigSerializationUtil";
|
|
4
|
-
|
|
5
|
-
export function esbuildMinimizer(): webpack.WebpackPluginInstance {
|
|
6
|
-
return WebpackConfigSerializationUtil.serializablePlugin("ESBuildMinifyPlugin", ESBuildMinifyPlugin, {
|
|
7
|
-
// Disable Esbuild minify for JS. it is unstable when targeting es5 minify
|
|
8
|
-
minify: false,
|
|
9
|
-
css: true,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import HTMLWebpackPlugin from "html-webpack-plugin";
|
|
2
|
-
import {ScriptTagCrossOriginPlugin} from "./script-tag-crossorigin-plugin";
|
|
3
|
-
import type webpack from "webpack";
|
|
4
|
-
import type {HTMLEntryDescriptor} from "../../type";
|
|
5
|
-
import {WebpackConfigSerializationUtil} from "../WebpackConfigSerializationUtil";
|
|
6
|
-
|
|
7
|
-
interface HTMLPluginOptions {
|
|
8
|
-
entry: HTMLEntryDescriptor;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a html file from a template with <script> and <link> injected
|
|
13
|
-
* with the respective hashed output filenames.
|
|
14
|
-
*/
|
|
15
|
-
export function htmlPlugin({entry}: HTMLPluginOptions): webpack.WebpackPluginInstance {
|
|
16
|
-
return WebpackConfigSerializationUtil.serializablePlugin("HTMLWebpackPlugin", HTMLWebpackPlugin, {
|
|
17
|
-
template: entry.htmlPath,
|
|
18
|
-
filename: `${entry.name}.html`,
|
|
19
|
-
chunks: [entry.name],
|
|
20
|
-
minify: {
|
|
21
|
-
collapseBooleanAttributes: true,
|
|
22
|
-
collapseInlineTagWhitespace: true,
|
|
23
|
-
collapseWhitespace: true,
|
|
24
|
-
includeAutoGeneratedTags: false,
|
|
25
|
-
keepClosingSlash: true,
|
|
26
|
-
minifyCSS: true,
|
|
27
|
-
minifyJS: true,
|
|
28
|
-
minifyURLs: true,
|
|
29
|
-
removeAttributeQuotes: true,
|
|
30
|
-
removeComments: true,
|
|
31
|
-
removeEmptyAttributes: true,
|
|
32
|
-
removeRedundantAttributes: true,
|
|
33
|
-
removeScriptTypeAttributes: true,
|
|
34
|
-
removeStyleLinkTypeAttributes: true,
|
|
35
|
-
removeTagWhitespace: true,
|
|
36
|
-
useShortDoctype: true,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Adds attributes to `<script>` tag inside html file generated by
|
|
43
|
-
* HTMLWebpackPlugin. Used to add `crossorigin="anonymous"`.
|
|
44
|
-
*/
|
|
45
|
-
export function scriptTagCrossOriginPlugin(): webpack.WebpackPluginInstance {
|
|
46
|
-
return WebpackConfigSerializationUtil.serializablePlugin("ScriptTagCrossOriginPlugin", ScriptTagCrossOriginPlugin);
|
|
47
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {cssMinimizerPlugin, miniCssExtractPlugin} from "./css.plugin";
|
|
2
|
-
import {esbuildMinimizer} from "./esbuild.plugin";
|
|
3
|
-
import {scriptTagCrossOriginPlugin, htmlPlugin} from "./html.plugin";
|
|
4
|
-
import {ignoreMomentLocalePlugin} from "./moment.plugin";
|
|
5
|
-
import {reactRefreshPlugin, terserPlugin} from "./ts.plugin";
|
|
6
|
-
import {webpackDefinePlugin, webpackProgressPlugin} from "./webpack.plugin";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Static factories to create \`webpack.config#plugins\` items.
|
|
10
|
-
*
|
|
11
|
-
* Plugins with similar functionality are grouped under a js object (as a namespace).
|
|
12
|
-
*/
|
|
13
|
-
export class Plugin {
|
|
14
|
-
static readonly scriptTagCrossOriginPlugin = scriptTagCrossOriginPlugin;
|
|
15
|
-
|
|
16
|
-
static readonly ignoreMomentLocale = ignoreMomentLocalePlugin;
|
|
17
|
-
|
|
18
|
-
static readonly reactRefresh = reactRefreshPlugin;
|
|
19
|
-
|
|
20
|
-
static readonly fileOutput = {
|
|
21
|
-
html: htmlPlugin,
|
|
22
|
-
miniCssExtract: miniCssExtractPlugin,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
static readonly minimizer = {
|
|
26
|
-
cssMinimizer: cssMinimizerPlugin,
|
|
27
|
-
terser: terserPlugin,
|
|
28
|
-
esbuildMinimizer,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
static readonly webpack = {
|
|
32
|
-
progress: webpackProgressPlugin,
|
|
33
|
-
define: webpackDefinePlugin,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
2
|
-
import type webpack from "webpack";
|
|
3
|
-
|
|
4
|
-
const PLUGIN_NAME = "ScriptTagCrossOriginPlugin";
|
|
5
|
-
|
|
6
|
-
// This plugin adds crossorigin="anonymous" to html-webpack-plugin generated <script> tags, only work with html-webpack-plugin@4.0.0+
|
|
7
|
-
export class ScriptTagCrossOriginPlugin implements webpack.WebpackPluginInstance {
|
|
8
|
-
apply(compiler: webpack.Compiler): void {
|
|
9
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
|
10
|
-
const hook = HtmlWebpackPlugin.getHooks(compilation).alterAssetTags;
|
|
11
|
-
hook.tap(PLUGIN_NAME, result => {
|
|
12
|
-
const {assetTags} = result;
|
|
13
|
-
for (const scriptTag of assetTags.scripts) {
|
|
14
|
-
if (scriptTag.attributes?.src && /.js$/.test(scriptTag.attributes.src.toString())) {
|
|
15
|
-
scriptTag.attributes.crossorigin = "anonymous";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
2
|
-
import TerserWebpackPlugin from "terser-webpack-plugin";
|
|
3
|
-
import type webpack from "webpack";
|
|
4
|
-
import {WebpackConfigSerializationUtil} from "../WebpackConfigSerializationUtil";
|
|
5
|
-
|
|
6
|
-
interface TerserPluginOptions {
|
|
7
|
-
sourceMap: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Applies Terser to minimize javascript
|
|
12
|
-
* after bundles/chunks are built.
|
|
13
|
-
*/
|
|
14
|
-
export function terserPlugin({sourceMap}: TerserPluginOptions): webpack.WebpackPluginInstance {
|
|
15
|
-
return WebpackConfigSerializationUtil.serializablePlugin("TerserWebpackPlugin", TerserWebpackPlugin, {
|
|
16
|
-
terserOptions: {
|
|
17
|
-
sourceMap,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Adds react fast refresh functionality.
|
|
24
|
-
* Requires babel plugin "react-refresh/babel".
|
|
25
|
-
* Should not be used in production.
|
|
26
|
-
*/
|
|
27
|
-
export function reactRefreshPlugin(): webpack.WebpackPluginInstance {
|
|
28
|
-
return WebpackConfigSerializationUtil.serializablePlugin("ReactRefreshPlugin", ReactRefreshWebpackPlugin);
|
|
29
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import webpack from "webpack";
|
|
2
|
-
import {WebpackConfigSerializationUtil} from "../WebpackConfigSerializationUtil";
|
|
3
|
-
|
|
4
|
-
interface WebpackProgressPluginOptions {
|
|
5
|
-
enableProfiling: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reports progress during compilation.
|
|
10
|
-
* Basically the same behavior as running webpack-cli with:
|
|
11
|
-
* `$ webpack --progress`
|
|
12
|
-
*/
|
|
13
|
-
export function webpackProgressPlugin({enableProfiling}: WebpackProgressPluginOptions): webpack.WebpackPluginInstance {
|
|
14
|
-
return WebpackConfigSerializationUtil.serializablePlugin("webpack.ProgressPlugin", webpack.ProgressPlugin, {
|
|
15
|
-
profile: enableProfiling,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function webpackDefinePlugin(map: {[key: string]: string}): webpack.WebpackPluginInstance {
|
|
20
|
-
return WebpackConfigSerializationUtil.serializablePlugin("webpack.DefinePlugin", webpack.DefinePlugin, map);
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {imageRule} from "./image.rule";
|
|
2
|
-
import {otherRule} from "./other.rule";
|
|
3
|
-
import {stylesheetRule} from "./stylesheet.rule";
|
|
4
|
-
import {tsRule} from "./ts.rule";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Static factories to create `webpack.config#modules.rules` items.
|
|
8
|
-
*/
|
|
9
|
-
export class Rule {
|
|
10
|
-
static readonly image = imageRule;
|
|
11
|
-
|
|
12
|
-
static readonly other = otherRule;
|
|
13
|
-
|
|
14
|
-
static readonly ts = tsRule;
|
|
15
|
-
|
|
16
|
-
static readonly stylesheet = stylesheetRule;
|
|
17
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type webpack from "webpack";
|
|
2
|
-
import {Constant} from "../../Constant";
|
|
3
|
-
import {RegExpUtil} from "./RegExpUtil";
|
|
4
|
-
|
|
5
|
-
interface OtherRuleDeps {
|
|
6
|
-
extraExtensionsForOtherRule: string[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Handles dependency requests to file assets
|
|
11
|
-
* by emitting as separate files.
|
|
12
|
-
*
|
|
13
|
-
* @see https://webpack.js.org/guides/asset-modules/
|
|
14
|
-
*/
|
|
15
|
-
export function otherRule({extraExtensionsForOtherRule}: OtherRuleDeps): webpack.RuleSetRule {
|
|
16
|
-
return {
|
|
17
|
-
test: RegExpUtil.fileExtension(".ico", ...Constant.mediaExtensions, ...Constant.fontExtensions, ...extraExtensionsForOtherRule),
|
|
18
|
-
type: "asset",
|
|
19
|
-
generator: {
|
|
20
|
-
filename: "static/other/[name].[hash:8][ext][query]",
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type webpack from "webpack";
|
|
2
|
-
import type {EntryDescriptor} from "../type";
|
|
3
|
-
|
|
4
|
-
interface StrictWebpackEntry {
|
|
5
|
-
[entryName: string]: [string];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface WebpackEntryFactoryOptions {
|
|
9
|
-
configEntryDescriptors: EntryDescriptor[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class WebpackEntryFactory {
|
|
13
|
-
static generate({configEntryDescriptors}: WebpackEntryFactoryOptions): NonNullable<webpack.Configuration["entry"]> {
|
|
14
|
-
const entry: StrictWebpackEntry = {};
|
|
15
|
-
|
|
16
|
-
for (const {name, entryPath} of configEntryDescriptors) {
|
|
17
|
-
entry[name] = [entryPath];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return entry;
|
|
21
|
-
}
|
|
22
|
-
}
|