@pinnacle0/webpack-util 0.3.26 → 0.3.27

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.
Files changed (139) hide show
  1. package/package.json +1 -1
  2. package/src/CanadyarnRunner.d.ts +14 -0
  3. package/src/CanadyarnRunner.js +38 -0
  4. package/src/CanadyarnRunner.js.map +1 -0
  5. package/src/CodeStyleChecker.d.ts +10 -0
  6. package/src/CodeStyleChecker.js +44 -0
  7. package/src/CodeStyleChecker.js.map +1 -0
  8. package/src/Constant.d.ts +21 -0
  9. package/src/{Constant.ts → Constant.js} +5 -1
  10. package/src/Constant.js.map +1 -0
  11. package/src/CoreUtil.d.ts +11 -0
  12. package/src/CoreUtil.js +26 -0
  13. package/src/CoreUtil.js.map +1 -0
  14. package/src/ProjectStructureChecker.d.ts +18 -0
  15. package/src/ProjectStructureChecker.js +113 -0
  16. package/src/ProjectStructureChecker.js.map +1 -0
  17. package/src/TestRunner.d.ts +8 -0
  18. package/src/TestRunner.js +30 -0
  19. package/src/TestRunner.js.map +1 -0
  20. package/src/TypescriptTypeChecker.d.ts +11 -0
  21. package/src/TypescriptTypeChecker.js +32 -0
  22. package/src/TypescriptTypeChecker.js.map +1 -0
  23. package/src/WebpackBuilder.d.ts +38 -0
  24. package/src/{WebpackBuilder.ts → WebpackBuilder.js} +51 -71
  25. package/src/WebpackBuilder.js.map +1 -0
  26. package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.d.ts +13 -0
  27. package/src/WebpackConfigGenerator/{ConfigEntryDescriptorsFactory.ts → ConfigEntryDescriptorsFactory.js} +29 -36
  28. package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.js.map +1 -0
  29. package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.d.ts +9 -0
  30. package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js +20 -0
  31. package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js.map +1 -0
  32. package/src/WebpackConfigGenerator/Plugin/css.plugin.d.ts +16 -0
  33. package/src/WebpackConfigGenerator/Plugin/css.plugin.js +33 -0
  34. package/src/WebpackConfigGenerator/Plugin/css.plugin.js.map +1 -0
  35. package/src/WebpackConfigGenerator/Plugin/html.plugin.d.ts +16 -0
  36. package/src/WebpackConfigGenerator/Plugin/html.plugin.js +48 -0
  37. package/src/WebpackConfigGenerator/Plugin/html.plugin.js.map +1 -0
  38. package/src/WebpackConfigGenerator/Plugin/index.d.ts +27 -0
  39. package/src/WebpackConfigGenerator/Plugin/index.js +32 -0
  40. package/src/WebpackConfigGenerator/Plugin/index.js.map +1 -0
  41. package/src/WebpackConfigGenerator/Plugin/moment.plugin.d.ts +10 -0
  42. package/src/WebpackConfigGenerator/Plugin/{moment.plugin.ts → moment.plugin.js} +12 -5
  43. package/src/WebpackConfigGenerator/Plugin/moment.plugin.js.map +1 -0
  44. package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.d.ts +4 -0
  45. package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js +28 -0
  46. package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js.map +1 -0
  47. package/src/WebpackConfigGenerator/Plugin/ts.plugin.d.ts +16 -0
  48. package/src/WebpackConfigGenerator/Plugin/ts.plugin.js +31 -0
  49. package/src/WebpackConfigGenerator/Plugin/ts.plugin.js.map +1 -0
  50. package/src/WebpackConfigGenerator/Plugin/webpack.plugin.d.ts +14 -0
  51. package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js +24 -0
  52. package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js.map +1 -0
  53. package/src/WebpackConfigGenerator/Rule/RegExpUtil.d.ts +4 -0
  54. package/src/WebpackConfigGenerator/Rule/{RegExpUtil.ts → RegExpUtil.js} +14 -8
  55. package/src/WebpackConfigGenerator/Rule/RegExpUtil.js.map +1 -0
  56. package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.d.ts +13 -0
  57. package/src/WebpackConfigGenerator/Rule/{core-fe-hmr-babel-plugin.ts → core-fe-hmr-babel-plugin.js} +9 -43
  58. package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.js.map +1 -0
  59. package/src/WebpackConfigGenerator/Rule/image.rule.d.ts +9 -0
  60. package/src/WebpackConfigGenerator/Rule/{image.rule.ts → image.rule.js} +8 -5
  61. package/src/WebpackConfigGenerator/Rule/image.rule.js.map +1 -0
  62. package/src/WebpackConfigGenerator/Rule/index.d.ts +13 -0
  63. package/src/WebpackConfigGenerator/Rule/index.js +18 -0
  64. package/src/WebpackConfigGenerator/Rule/index.js.map +1 -0
  65. package/src/WebpackConfigGenerator/Rule/other.rule.d.ts +12 -0
  66. package/src/WebpackConfigGenerator/Rule/other.rule.js +22 -0
  67. package/src/WebpackConfigGenerator/Rule/other.rule.js.map +1 -0
  68. package/src/WebpackConfigGenerator/Rule/stylesheet.rule.d.ts +17 -0
  69. package/src/WebpackConfigGenerator/Rule/{stylesheet.rule.ts → stylesheet.rule.js} +30 -34
  70. package/src/WebpackConfigGenerator/Rule/stylesheet.rule.js.map +1 -0
  71. package/src/WebpackConfigGenerator/Rule/ts.rule.d.ts +18 -0
  72. package/src/WebpackConfigGenerator/Rule/{ts.rule.ts → ts.rule.js} +16 -18
  73. package/src/WebpackConfigGenerator/Rule/ts.rule.js.map +1 -0
  74. package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.d.ts +10 -0
  75. package/src/WebpackConfigGenerator/{WebpackConfigSerializationUtil.ts → WebpackConfigSerializationUtil.js} +22 -23
  76. package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.js.map +1 -0
  77. package/src/WebpackConfigGenerator/WebpackEntryFactory.d.ts +9 -0
  78. package/src/WebpackConfigGenerator/WebpackEntryFactory.js +14 -0
  79. package/src/WebpackConfigGenerator/WebpackEntryFactory.js.map +1 -0
  80. package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.d.ts +11 -0
  81. package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js +16 -0
  82. package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js.map +1 -0
  83. package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.d.ts +11 -0
  84. package/src/WebpackConfigGenerator/{WebpackResolveAliasFactory.ts → WebpackResolveAliasFactory.js} +13 -16
  85. package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.js.map +1 -0
  86. package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.d.ts +7 -0
  87. package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js +16 -0
  88. package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js.map +1 -0
  89. package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.d.ts +7 -0
  90. package/src/WebpackConfigGenerator/{WebpackResolveModulesFactory.ts → WebpackResolveModulesFactory.js} +7 -9
  91. package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.js.map +1 -0
  92. package/src/WebpackConfigGenerator/index.d.ts +31 -0
  93. package/src/WebpackConfigGenerator/index.js +191 -0
  94. package/src/WebpackConfigGenerator/index.js.map +1 -0
  95. package/src/WebpackServerStarter.d.ts +28 -0
  96. package/src/WebpackServerStarter.js +111 -0
  97. package/src/WebpackServerStarter.js.map +1 -0
  98. package/src/index.d.ts +10 -0
  99. package/src/index.js +8 -0
  100. package/src/index.js.map +1 -0
  101. package/src/{type.ts → type.d.ts} +4 -8
  102. package/src/type.js +3 -0
  103. package/src/type.js.map +1 -0
  104. package/config/jest.config.ts +0 -35
  105. package/config/tsconfig.script.json +0 -10
  106. package/config/tsconfig.src.json +0 -12
  107. package/config/tsconfig.test.json +0 -11
  108. package/script/build.ts +0 -65
  109. package/script/format.ts +0 -7
  110. package/src/CanadyarnRunner.ts +0 -35
  111. package/src/CodeStyleChecker.ts +0 -44
  112. package/src/CoreUtil.ts +0 -24
  113. package/src/ProjectStructureChecker.ts +0 -119
  114. package/src/TestRunner.ts +0 -28
  115. package/src/TypescriptTypeChecker.ts +0 -29
  116. package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.ts +0 -24
  117. package/src/WebpackConfigGenerator/Plugin/css.plugin.ts +0 -31
  118. package/src/WebpackConfigGenerator/Plugin/html.plugin.ts +0 -47
  119. package/src/WebpackConfigGenerator/Plugin/index.ts +0 -33
  120. package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.ts +0 -22
  121. package/src/WebpackConfigGenerator/Plugin/ts.plugin.ts +0 -29
  122. package/src/WebpackConfigGenerator/Plugin/webpack.plugin.ts +0 -21
  123. package/src/WebpackConfigGenerator/Rule/index.ts +0 -17
  124. package/src/WebpackConfigGenerator/Rule/other.rule.ts +0 -23
  125. package/src/WebpackConfigGenerator/WebpackEntryFactory.ts +0 -22
  126. package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.ts +0 -22
  127. package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.ts +0 -19
  128. package/src/WebpackConfigGenerator/index.ts +0 -213
  129. package/src/WebpackServerStarter.ts +0 -138
  130. package/src/index.ts +0 -9
  131. package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldIgnore.test.ts.snap +0 -21
  132. package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldTransform.test.ts.snap +0 -53
  133. package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldIgnore.test.ts +0 -36
  134. package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldTransform.test.ts +0 -72
  135. package/test/WebpackConfigGenerator/plugin/fixture/script.js +0 -2
  136. package/test/WebpackConfigGenerator/plugin/fixture/script1.js +0 -1
  137. package/test/WebpackConfigGenerator/plugin/script-tag-crossorigin-plugin.test.ts +0 -58
  138. package/test/test-project/package.json +0 -5
  139. package/tsconfig.json +0 -15
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.WebpackServerStarter = void 0;
16
+ const devtool_util_1 = require("@pinnacle0/devtool-util");
17
+ const path_1 = __importDefault(require("path"));
18
+ const webpack_1 = __importDefault(require("webpack"));
19
+ const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
20
+ const WebpackConfigGenerator_1 = require("./WebpackConfigGenerator");
21
+ /**
22
+ * Start webpack dev server, by creating WebpackServerStarter instance and then run.
23
+ *
24
+ ***************************************
25
+ *
26
+ * Add "--env envName" to command line, if you want to switch config folder dynamically.
27
+ */
28
+ class WebpackServerStarter {
29
+ constructor({ projectDirectory, port, apiProxy, interceptExpressApp, dynamicPathResolvers, extraEntries, prioritizedExtensionPrefixes, defineVars, extraExtensionsForOtherRule, }) {
30
+ this.logger = devtool_util_1.Utility.createConsoleLogger("WebpackServerStarter");
31
+ this.devServerConfigContentBase = path_1.default.join(projectDirectory, "static");
32
+ this.port = port;
33
+ this.apiProxy = apiProxy
34
+ ? [
35
+ {
36
+ context: apiProxy.context,
37
+ target: apiProxy.target,
38
+ secure: false,
39
+ changeOrigin: true,
40
+ },
41
+ ]
42
+ : undefined;
43
+ this.onBeforeSetupMiddleware = interceptExpressApp ? devServer => (devServer.app ? interceptExpressApp(devServer.app) : undefined) : undefined;
44
+ this.webpackConfig = new WebpackConfigGenerator_1.WebpackConfigGenerator({
45
+ projectDirectory,
46
+ dynamicPathResolvers,
47
+ extraEntries,
48
+ prioritizedExtensionPrefixes,
49
+ defineVars,
50
+ extraExtensionsForOtherRule,
51
+ }).development();
52
+ }
53
+ run() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ try {
56
+ this.logger.info(["Starting dev server on port", String(this.port)]);
57
+ const server = this.createDevServerInstance();
58
+ const signals = ["SIGINT", "SIGTERM"];
59
+ for (const signal of signals) {
60
+ process.on(signal, () => {
61
+ // force stop webpack dev server
62
+ server.stopCallback(() => { });
63
+ process.exit();
64
+ });
65
+ }
66
+ yield server.start();
67
+ }
68
+ catch (e) {
69
+ this.logger.error(e);
70
+ console.error(e);
71
+ process.exit(1);
72
+ }
73
+ });
74
+ }
75
+ createDevServerInstance() {
76
+ return new webpack_dev_server_1.default({
77
+ host: "0.0.0.0",
78
+ port: this.port,
79
+ static: {
80
+ directory: this.devServerConfigContentBase,
81
+ },
82
+ historyApiFallback: true,
83
+ server: {
84
+ type: "https",
85
+ },
86
+ compress: true,
87
+ hot: true,
88
+ client: {
89
+ overlay: {
90
+ errors: true,
91
+ },
92
+ },
93
+ onBeforeSetupMiddleware: this.onBeforeSetupMiddleware,
94
+ devMiddleware: {
95
+ stats: {
96
+ colors: true,
97
+ // https://github.com/webpack/webpack/blob/b65d060040a26255cbf6f50350fef4d4ffcce4d7/lib/stats/DefaultStatsPresetPlugin.js#L96-L103
98
+ all: false,
99
+ errors: true,
100
+ errorsCount: true,
101
+ warnings: true,
102
+ warningsCount: true,
103
+ logging: "warn",
104
+ },
105
+ },
106
+ proxy: this.apiProxy,
107
+ }, (0, webpack_1.default)(this.webpackConfig));
108
+ }
109
+ }
110
+ exports.WebpackServerStarter = WebpackServerStarter;
111
+ //# sourceMappingURL=WebpackServerStarter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebpackServerStarter.js","sourceRoot":"","sources":["../../src/WebpackServerStarter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAA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B,OAAO,EAAE,MAAM;iBAClB;aACJ;YACD,KAAK,EAAE,IAAI,CAAC,QAAQ;SACvB,EACD,IAAA,iBAAO,EAAC,IAAI,CAAC,aAAa,CAAC,CAC9B,CAAC;IACN,CAAC;CACJ;AA1GD,oDA0GC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { WebpackBuilder } from "./WebpackBuilder";
2
+ import { WebpackServerStarter } from "./WebpackServerStarter";
3
+ export declare const WebpackUtil: Readonly<{
4
+ currentEnv: () => string | null;
5
+ profilingEnabled: () => boolean;
6
+ isFastMode: () => boolean;
7
+ verbose: () => boolean;
8
+ Builder: typeof WebpackBuilder;
9
+ ServerStarter: typeof WebpackServerStarter;
10
+ }>;
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebpackUtil = void 0;
4
+ const WebpackBuilder_1 = require("./WebpackBuilder");
5
+ const WebpackServerStarter_1 = require("./WebpackServerStarter");
6
+ const CoreUtil_1 = require("./CoreUtil");
7
+ exports.WebpackUtil = Object.freeze(Object.assign({ Builder: WebpackBuilder_1.WebpackBuilder, ServerStarter: WebpackServerStarter_1.WebpackServerStarter }, CoreUtil_1.CoreUtil));
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAChD,iEAA4D;AAC5D,yCAAoC;AAEvB,QAAA,WAAW,GAAG,MAAM,CAAC,MAAM,iBACpC,OAAO,EAAE,+BAAc,EACvB,aAAa,EAAE,2CAAoB,IAChC,mBAAQ,EACb,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import type webpack from "webpack";
2
-
3
2
  export interface WebpackConfigGeneratorOptions {
4
3
  /**
5
4
  * Directory of containing the application code.
@@ -89,11 +88,12 @@ export interface WebpackConfigGeneratorOptions {
89
88
  /**
90
89
  * Ref: https://webpack.js.org/plugins/define-plugin/
91
90
  */
92
- defineVars?: {[key: string]: string} | undefined;
91
+ defineVars?: {
92
+ [key: string]: string;
93
+ } | undefined;
93
94
  onSuccess?: () => void;
94
95
  extraExtensionsForOtherRule?: string[] | undefined;
95
96
  }
96
-
97
97
  export interface EntryDescriptor {
98
98
  name: string;
99
99
  /**
@@ -114,7 +114,6 @@ export interface EntryDescriptor {
114
114
  */
115
115
  htmlPath?: string;
116
116
  }
117
-
118
117
  /**
119
118
  * Same as EntryDescriptor, but guaranteed to have an htmlPath.
120
119
  * Used for creating HTMLWebpackPlugin instances.
@@ -125,7 +124,6 @@ export interface HTMLEntryDescriptor {
125
124
  entryPath: string;
126
125
  htmlPath: string;
127
126
  }
128
-
129
127
  export interface DynamicPathResolver {
130
128
  /**
131
129
  * Prefix of the dependencies that should be aliased.
@@ -144,7 +142,6 @@ export interface DynamicPathResolver {
144
142
  */
145
143
  resolver: string | null | ((env: string | null) => string | null);
146
144
  }
147
-
148
145
  export interface InternalCheckerOptions {
149
146
  /**
150
147
  * Directory of containing the application code.
@@ -163,7 +160,6 @@ export interface InternalCheckerOptions {
163
160
  */
164
161
  extraCheckDirectories?: string[];
165
162
  }
166
-
167
163
  declare module "webpack" {
168
164
  interface TapablePlugin {
169
165
  apply(...args: any[]): void;
@@ -180,7 +176,7 @@ declare module "webpack" {
180
176
  * This is a workaround to allow "@types/*-plugin" packages to work before their
181
177
  * type definitions are properly upgraded.
182
178
  */
183
- export abstract class Plugin {
179
+ abstract class Plugin {
184
180
  apply(compiler: webpack.Compiler): void;
185
181
  }
186
182
  }
package/src/type.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":""}
@@ -1,35 +0,0 @@
1
- import type {Config} from "@jest/types";
2
-
3
- const config: Config.InitialOptionsWithRootDir = {
4
- // Stop running tests after `n` failures
5
- bail: 1,
6
-
7
- // A preset that is used as a base for Jest's configuration
8
- preset: "ts-jest",
9
-
10
- // A set of global variables that need to be available in all test environments
11
- globals: {
12
- "ts-jest": {
13
- tsconfig: "<rootDir>/config/tsconfig.test.json",
14
- },
15
- },
16
-
17
- // The root directory that Jest should scan for tests and modules within
18
- rootDir: "../",
19
-
20
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
21
- testPathIgnorePatterns: ["/node_modules/", "<rootDir>/build/"],
22
-
23
- // A map from regular expressions to paths to transformers
24
- transform: {
25
- [String.raw`\.(ts|tsx)$`]: "ts-jest",
26
- },
27
-
28
- // Indicates whether each individual test should be reported during the run
29
- verbose: true,
30
-
31
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
32
- watchPathIgnorePatterns: ["<rootDir>/build/", "dist/"],
33
- };
34
-
35
- export default config;
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "lib": ["ES2020"],
5
- "module": "CommonJS",
6
- "target": "ES2015",
7
- "noEmit": true
8
- },
9
- "include": ["../config", "../script/"]
10
- }
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "lib": ["ES2020"],
5
- "module": "CommonJS",
6
- "target": "ES2015",
7
- "rootDir": "../",
8
- "outDir": "../build/",
9
- "isolatedModules": true
10
- },
11
- "include": ["../src/"]
12
- }
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "lib": ["ES2020"],
5
- "module": "CommonJS",
6
- "target": "ES2015",
7
- "rootDir": "../",
8
- "isolatedModules": true
9
- },
10
- "include": ["../test/"]
11
- }
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"));
@@ -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
- }
@@ -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,29 +0,0 @@
1
- import {Utility} from "@pinnacle0/devtool-util";
2
- import path from "path";
3
- import type {InternalCheckerOptions} from "./type";
4
-
5
- /**
6
- * Check typescript type for both projectDirectory src, extraCheckDirectories src using their own tsconfig inside their directory
7
- */
8
- export class TypescriptTypeChecker {
9
- private readonly logger = Utility.createConsoleLogger("TypescriptTypeChecker");
10
- private tsconfigPaths: string[] = [];
11
-
12
- constructor({projectDirectory, extraCheckDirectories}: InternalCheckerOptions) {
13
- const checkableDirectories = [projectDirectory, ...(extraCheckDirectories ?? [])];
14
- for (const directory of checkableDirectories) {
15
- this.tsconfigPaths.push(path.join(directory, "tsconfig.json"));
16
- }
17
- }
18
-
19
- run() {
20
- this.checkTypeScriptTyping();
21
- }
22
-
23
- private checkTypeScriptTyping() {
24
- this.logger.task("Checking TypeScript");
25
- for (const tsconfigPath of this.tsconfigPaths) {
26
- Utility.runCommand("tsc", ["--noEmit", "--emitDeclarationOnly", "false", "-P", tsconfigPath]);
27
- }
28
- }
29
- }
@@ -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
- }