@apollion-dsi/scripts 0.7.7
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/.prettierignore +6 -0
- package/.prettierrc.js +1 -0
- package/CHANGELOG.md +8 -0
- package/README.MD +91 -0
- package/audit-ci.json +5 -0
- package/eslint.config.js +33 -0
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +34 -0
- package/lib/bin.js.map +1 -0
- package/lib/command/build.d.ts +3 -0
- package/lib/command/build.js +145 -0
- package/lib/command/build.js.map +1 -0
- package/lib/command/create/helper.d.ts +7 -0
- package/lib/command/create/helper.js +98 -0
- package/lib/command/create/helper.js.map +1 -0
- package/lib/command/create/index.d.ts +1 -0
- package/lib/command/create/index.js +149 -0
- package/lib/command/create/index.js.map +1 -0
- package/lib/command/dev.d.ts +3 -0
- package/lib/command/dev.js +85 -0
- package/lib/command/dev.js.map +1 -0
- package/lib/command/test.d.ts +1 -0
- package/lib/command/test.js +32 -0
- package/lib/command/test.js.map +1 -0
- package/lib/config/env.d.ts +15 -0
- package/lib/config/env.js +78 -0
- package/lib/config/env.js.map +1 -0
- package/lib/config/modules.d.ts +15 -0
- package/lib/config/modules.js +92 -0
- package/lib/config/modules.js.map +1 -0
- package/lib/config/paths.d.ts +22 -0
- package/lib/config/paths.js +61 -0
- package/lib/config/paths.js.map +1 -0
- package/lib/config/shared.d.ts +24 -0
- package/lib/config/shared.js +14 -0
- package/lib/config/shared.js.map +1 -0
- package/lib/config/webpack.config.d.ts +187 -0
- package/lib/config/webpack.config.js +300 -0
- package/lib/config/webpack.config.js.map +1 -0
- package/lib/config/webpackDevServer.config.d.ts +34 -0
- package/lib/config/webpackDevServer.config.js +67 -0
- package/lib/config/webpackDevServer.config.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/FileSizeReporter.d.ts +12 -0
- package/lib/utils/FileSizeReporter.js +151 -0
- package/lib/utils/FileSizeReporter.js.map +1 -0
- package/lib/utils/InlineChunkHtmlPlugin.d.ts +8 -0
- package/lib/utils/InlineChunkHtmlPlugin.js +54 -0
- package/lib/utils/InlineChunkHtmlPlugin.js.map +1 -0
- package/lib/utils/InterpolateHtmlPlugin.d.ts +7 -0
- package/lib/utils/InterpolateHtmlPlugin.js +21 -0
- package/lib/utils/InterpolateHtmlPlugin.js.map +1 -0
- package/lib/utils/ModuleNotFoundPlugin.d.ts +5 -0
- package/lib/utils/ModuleNotFoundPlugin.js +11 -0
- package/lib/utils/ModuleNotFoundPlugin.js.map +1 -0
- package/lib/utils/ModuleScopePlugin.d.ts +5 -0
- package/lib/utils/ModuleScopePlugin.js +11 -0
- package/lib/utils/ModuleScopePlugin.js.map +1 -0
- package/lib/utils/WebpackDevServerUtils.d.ts +22 -0
- package/lib/utils/WebpackDevServerUtils.js +154 -0
- package/lib/utils/WebpackDevServerUtils.js.map +1 -0
- package/lib/utils/checkRequiredFiles.d.ts +1 -0
- package/lib/utils/checkRequiredFiles.js +28 -0
- package/lib/utils/checkRequiredFiles.js.map +1 -0
- package/lib/utils/devServerMiddleware.d.ts +8 -0
- package/lib/utils/devServerMiddleware.js +19 -0
- package/lib/utils/devServerMiddleware.js.map +1 -0
- package/lib/utils/formatWebpackMessages.d.ts +5 -0
- package/lib/utils/formatWebpackMessages.js +32 -0
- package/lib/utils/formatWebpackMessages.js.map +1 -0
- package/lib/utils/getPublicUrlOrPath.d.ts +1 -0
- package/lib/utils/getPublicUrlOrPath.js +39 -0
- package/lib/utils/getPublicUrlOrPath.js.map +1 -0
- package/lib/utils/printBuildError.d.ts +1 -0
- package/lib/utils/printBuildError.js +14 -0
- package/lib/utils/printBuildError.js.map +1 -0
- package/lib/utils/printHostingInstructions.d.ts +1 -0
- package/lib/utils/printHostingInstructions.js +12 -0
- package/lib/utils/printHostingInstructions.js.map +1 -0
- package/package.json +81 -0
- package/scripts/validate.sh +16 -0
- package/src/bin.ts +41 -0
- package/src/command/build.ts +188 -0
- package/src/command/create/helper.ts +97 -0
- package/src/command/create/index.ts +200 -0
- package/src/command/dev.ts +95 -0
- package/src/command/test.ts +33 -0
- package/src/config/env.ts +82 -0
- package/src/config/modules.ts +115 -0
- package/src/config/paths.ts +88 -0
- package/src/config/shared.ts +27 -0
- package/src/config/webpack.config.js +308 -0
- package/src/config/webpackDevServer.config.ts +78 -0
- package/src/index.ts +3 -0
- package/src/utils/FileSizeReporter.ts +168 -0
- package/src/utils/InlineChunkHtmlPlugin.js +67 -0
- package/src/utils/InterpolateHtmlPlugin.js +27 -0
- package/src/utils/ModuleNotFoundPlugin.js +13 -0
- package/src/utils/ModuleScopePlugin.js +13 -0
- package/src/utils/WebpackDevServerUtils.ts +179 -0
- package/src/utils/checkRequiredFiles.ts +22 -0
- package/src/utils/devServerMiddleware.ts +20 -0
- package/src/utils/formatWebpackMessages.ts +30 -0
- package/src/utils/getPublicUrlOrPath.ts +39 -0
- package/src/utils/printBuildError.ts +8 -0
- package/src/utils/printHostingInstructions.ts +12 -0
- package/template/.editorconfig +43 -0
- package/template/.prettierignore +6 -0
- package/template/.prettierrc.js +1 -0
- package/template/audit-ci.json +5 -0
- package/template/commitlint.config.js +1 -0
- package/template/eslint.config.js +3 -0
- package/template/jest.config.js +4 -0
- package/template/public/index.html +20 -0
- package/template/src/App.test.tsx +10 -0
- package/template/src/App.tsx +35 -0
- package/template/src/index.tsx +10 -0
- package/template/tsconfig.json +25 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getPublicUrlOrPath;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
function getPublicUrlOrPath(isEnvDevelopment, homepage, envPublicUrl) {
|
|
6
|
+
const stubDomain = 'https://create-react-app.dev';
|
|
7
|
+
if (envPublicUrl) {
|
|
8
|
+
let normalized = envPublicUrl;
|
|
9
|
+
if (!normalized.endsWith('/'))
|
|
10
|
+
normalized += '/';
|
|
11
|
+
try {
|
|
12
|
+
const validPublicUrl = new url_1.URL(normalized, stubDomain);
|
|
13
|
+
return isEnvDevelopment ? (normalized.startsWith('.') ? '/' : validPublicUrl.pathname) : normalized;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return normalized;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (homepage) {
|
|
20
|
+
let normalized = homepage;
|
|
21
|
+
if (!normalized.endsWith('/'))
|
|
22
|
+
normalized += '/';
|
|
23
|
+
try {
|
|
24
|
+
const validHomepagePathname = new url_1.URL(normalized, stubDomain).pathname;
|
|
25
|
+
return isEnvDevelopment
|
|
26
|
+
? normalized.startsWith('.')
|
|
27
|
+
? '/'
|
|
28
|
+
: validHomepagePathname
|
|
29
|
+
: normalized.startsWith('.')
|
|
30
|
+
? normalized
|
|
31
|
+
: validHomepagePathname;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return normalized;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return '/';
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=getPublicUrlOrPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPublicUrlOrPath.js","sourceRoot":"","sources":["../../src/utils/getPublicUrlOrPath.ts"],"names":[],"mappings":";;AAEA,qCAoCC;AAtCD,6BAA0B;AAE1B,SAAwB,kBAAkB,CACxC,gBAAyB,EACzB,QAA4B,EAC5B,YAAgC;IAEhC,MAAM,UAAU,GAAG,8BAA8B,CAAC;IAElD,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,UAAU,GAAG,YAAY,CAAC;QAC9B,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,UAAU,IAAI,GAAG,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,IAAI,SAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACvD,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QACtG,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,UAAU,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,UAAU,IAAI,GAAG,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,qBAAqB,GAAG,IAAI,SAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC;YACvE,OAAO,gBAAgB;gBACrB,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC;oBAC1B,CAAC,CAAC,GAAG;oBACL,CAAC,CAAC,qBAAqB;gBACzB,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC;oBAC1B,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,qBAAqB,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function printBuildError(err: unknown): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = printBuildError;
|
|
4
|
+
function printBuildError(err) {
|
|
5
|
+
if (err instanceof Error) {
|
|
6
|
+
console.error(err.message);
|
|
7
|
+
if (err.stack)
|
|
8
|
+
console.error(err.stack);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
console.error(err);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=printBuildError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printBuildError.js","sourceRoot":"","sources":["../../src/utils/printBuildError.ts"],"names":[],"mappings":";;AAAA,kCAOC;AAPD,SAAwB,eAAe,CAAC,GAAY;IAClD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,GAAG,CAAC,KAAK;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function printHostingInstructions(_appPackage: unknown, _publicUrl: string, _publicPath: string | undefined, buildFolder: string, _useYarn: boolean): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = printHostingInstructions;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
function printHostingInstructions(_appPackage, _publicUrl, _publicPath, buildFolder, _useYarn) {
|
|
9
|
+
console.log(`The build is ready in the ${chalk_1.default.cyan(buildFolder)} folder.`);
|
|
10
|
+
console.log('You may serve it with any static file server.');
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=printHostingInstructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printHostingInstructions.js","sourceRoot":"","sources":["../../src/utils/printHostingInstructions.ts"],"names":[],"mappings":";;;;;AAEA,2CASC;AAXD,kDAA0B;AAE1B,SAAwB,wBAAwB,CAC9C,WAAoB,EACpB,UAAkB,EAClB,WAA+B,EAC/B,WAAmB,EACnB,QAAiB;IAEjB,OAAO,CAAC,GAAG,CAAC,6BAA6B,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;AAC/D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apollion-dsi/scripts",
|
|
3
|
+
"version": "0.7.7",
|
|
4
|
+
"description": "Apollion Framework CLI",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"bin": "lib/bin.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepare": "yarn build",
|
|
9
|
+
"audit-dependencies": "audit-ci --config audit-ci.json",
|
|
10
|
+
"lint": "eslint src --quiet",
|
|
11
|
+
"lint:full": "eslint src",
|
|
12
|
+
"lint:fix": "eslint src --fix",
|
|
13
|
+
"check-types": "tsc --noEmit",
|
|
14
|
+
"prettier": "prettier --check **/*.{ts,tsx} --ignore-path ../../.gitignore --no-error-on-unmatched-pattern",
|
|
15
|
+
"format": "yarn prettier --write",
|
|
16
|
+
"validate": "./scripts/validate.sh",
|
|
17
|
+
"test": "yarn validate",
|
|
18
|
+
"build": "tsc -p ."
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "Apollion DS Team",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@apollion-dsi/eslint-config": "0.6.0",
|
|
25
|
+
"@babel/core": "7.29.0",
|
|
26
|
+
"@babel/preset-env": "7.29.5",
|
|
27
|
+
"@babel/preset-react": "7.28.5",
|
|
28
|
+
"@babel/preset-typescript": "7.28.5",
|
|
29
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.6.2",
|
|
30
|
+
"@testing-library/jest-dom": "6.9.1",
|
|
31
|
+
"@testing-library/react": "16.3.2",
|
|
32
|
+
"babel-loader": "10.1.1",
|
|
33
|
+
"babel-plugin-named-asset-import": "0.3.8",
|
|
34
|
+
"babel-plugin-relay": "20.1.1",
|
|
35
|
+
"babel-plugin-styled-components": "2.1.4",
|
|
36
|
+
"bfj": "9.1.3",
|
|
37
|
+
"case-sensitive-paths-webpack-plugin": "2.4.0",
|
|
38
|
+
"chalk": "4.1.2",
|
|
39
|
+
"core-js": "3.40.0",
|
|
40
|
+
"cross-spawn": "7.0.6",
|
|
41
|
+
"deepmerge": "4.3.1",
|
|
42
|
+
"detect-port": "2.1.0",
|
|
43
|
+
"dotenv": "17.4.2",
|
|
44
|
+
"dotenv-expand": "13.0.0",
|
|
45
|
+
"fork-ts-checker-webpack-plugin": "9.1.0",
|
|
46
|
+
"fs-extra": "11.3.5",
|
|
47
|
+
"git-revision-webpack-plugin": "5.0.0",
|
|
48
|
+
"html-webpack-plugin": "5.6.7",
|
|
49
|
+
"husky": "9.1.7",
|
|
50
|
+
"inquirer": "13.4.3",
|
|
51
|
+
"jest": "30.4.2",
|
|
52
|
+
"jest-cli": "30.4.2",
|
|
53
|
+
"react-refresh": "0.18.0",
|
|
54
|
+
"resolve": "1.22.12",
|
|
55
|
+
"semver": "7.8.0",
|
|
56
|
+
"terser-webpack-plugin": "5.6.0",
|
|
57
|
+
"ts-jest": "29.4.9",
|
|
58
|
+
"tsconfig-paths-webpack-plugin": "4.2.0",
|
|
59
|
+
"update-notifier": "7.3.1",
|
|
60
|
+
"validate-npm-package-name": "8.0.0",
|
|
61
|
+
"webpack": "5.106.2",
|
|
62
|
+
"webpack-dev-server": "5.2.4",
|
|
63
|
+
"webpack-manifest-plugin": "6.0.1"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"typescript": "6.0.3"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@testing-library/dom": "10.4.1",
|
|
70
|
+
"@types/jest": "30.0.0",
|
|
71
|
+
"audit-ci": "7.1.0",
|
|
72
|
+
"eslint": "9.29.0",
|
|
73
|
+
"npm-run-all": "4.1.5",
|
|
74
|
+
"prettier": "3.8.3",
|
|
75
|
+
"react": "19.2.6",
|
|
76
|
+
"react-dom": "19.2.6",
|
|
77
|
+
"styled-components": "6.4.1",
|
|
78
|
+
"tslib": "2.8.1",
|
|
79
|
+
"typescript": "6.0.3"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
BRANCH=$(git symbolic-ref --short HEAD)
|
|
4
|
+
|
|
5
|
+
if [ "$BRANCH" = "main" ]; then
|
|
6
|
+
echo "Validating on production"
|
|
7
|
+
npm-run-all --parallel check-types prettier lint && yarn build
|
|
8
|
+
|
|
9
|
+
elif [ "$BRANCH" = "staging" ]; then
|
|
10
|
+
echo "Validating on staging"
|
|
11
|
+
npm-run-all --parallel check-types prettier lint && yarn build
|
|
12
|
+
|
|
13
|
+
else
|
|
14
|
+
echo "Validating on development"
|
|
15
|
+
npm-run-all --parallel check-types prettier lint
|
|
16
|
+
fi
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import spawn from 'cross-spawn';
|
|
5
|
+
import updateNotifier from 'update-notifier';
|
|
6
|
+
|
|
7
|
+
import { createTemplate } from './command/create';
|
|
8
|
+
|
|
9
|
+
const notifier = updateNotifier({
|
|
10
|
+
pkg: require('../package.json'),
|
|
11
|
+
updateCheckInterval: 1000 * 60 * 60, // 1hr
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
notifier.notify({
|
|
15
|
+
defer: false,
|
|
16
|
+
message: `Update available ${chalk.dim('{currentVersion}')} ${chalk.reset(' → ')} ${chalk.green(
|
|
17
|
+
'{latestVersion}',
|
|
18
|
+
)} \nRun ${chalk.cyan('yarn add {packageName}')} to update.`,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
(async (cmd: string[]) => {
|
|
22
|
+
const [command, ...options] = cmd;
|
|
23
|
+
|
|
24
|
+
if (['build', 'dev', 'test'].includes(command)) {
|
|
25
|
+
const result = spawn.sync(process.execPath, [require.resolve(`./command/${command}`), ...options], {
|
|
26
|
+
stdio: 'inherit',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return process.exit(result.status);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (command === 'create') {
|
|
33
|
+
await createTemplate(options[0]);
|
|
34
|
+
|
|
35
|
+
return process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log(`${chalk.red('Commando não reconhecido:')} ${chalk.yellow(command)}`);
|
|
39
|
+
|
|
40
|
+
process.exit(1);
|
|
41
|
+
})(process.argv.slice(2));
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
process.env.BABEL_ENV = 'production';
|
|
2
|
+
process.env.NODE_ENV = 'production';
|
|
3
|
+
|
|
4
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
5
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
6
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
7
|
+
process.on('unhandledRejection', (err) => {
|
|
8
|
+
throw err;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
import path from 'path';
|
|
12
|
+
|
|
13
|
+
import chalk from 'chalk';
|
|
14
|
+
import merge from 'deepmerge';
|
|
15
|
+
import fs from 'fs-extra';
|
|
16
|
+
import webpack, { Configuration } from 'webpack';
|
|
17
|
+
|
|
18
|
+
import { getEnviroment } from '../config/env';
|
|
19
|
+
import defaultPaths, { AppPaths } from '../config/paths';
|
|
20
|
+
import { CustomConfigType, defaultDevConfig } from '../config/shared';
|
|
21
|
+
import configFactory from '../config/webpack.config';
|
|
22
|
+
import checkRequiredFiles from '../utils/checkRequiredFiles';
|
|
23
|
+
import { measureFileSizesBeforeBuild, printFileSizesAfterBuild } from '../utils/FileSizeReporter';
|
|
24
|
+
import formatWebpackMessages from '../utils/formatWebpackMessages';
|
|
25
|
+
import printBuildError from '../utils/printBuildError';
|
|
26
|
+
import printHostingInstructions from '../utils/printHostingInstructions';
|
|
27
|
+
|
|
28
|
+
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
29
|
+
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
30
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
31
|
+
|
|
32
|
+
function copyPublicFolder(paths: AppPaths) {
|
|
33
|
+
fs.copySync(paths.appPublic, paths.appBuild, {
|
|
34
|
+
dereference: true,
|
|
35
|
+
filter: (file) => file !== paths.appHtml,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Generate configuration
|
|
40
|
+
// const config = configFactory('production', paths);
|
|
41
|
+
|
|
42
|
+
// Create the production build and print the deployment instructions.
|
|
43
|
+
function build(config: Configuration, previousFileSizes: unknown) {
|
|
44
|
+
console.log('Creating an optimized production build...');
|
|
45
|
+
|
|
46
|
+
const compiler = webpack(config);
|
|
47
|
+
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
compiler.run((err, stats) => {
|
|
50
|
+
let messages;
|
|
51
|
+
if (err) {
|
|
52
|
+
if (!err.message) {
|
|
53
|
+
return reject(err);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const errMessage = err.message;
|
|
57
|
+
|
|
58
|
+
messages = formatWebpackMessages({
|
|
59
|
+
errors: [errMessage],
|
|
60
|
+
warnings: [],
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
messages = formatWebpackMessages(stats?.toJson({ all: false, warnings: true, errors: true }));
|
|
64
|
+
}
|
|
65
|
+
if (messages.errors.length) {
|
|
66
|
+
// Only keep the first error. Others are often indicative
|
|
67
|
+
// of the same problem, but confuse the reader with noise.
|
|
68
|
+
if (messages.errors.length > 1) {
|
|
69
|
+
messages.errors.length = 1;
|
|
70
|
+
}
|
|
71
|
+
return reject(new Error(messages.errors.join('\n\n')));
|
|
72
|
+
}
|
|
73
|
+
if (
|
|
74
|
+
process.env.CI &&
|
|
75
|
+
(typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') &&
|
|
76
|
+
messages.warnings.length
|
|
77
|
+
) {
|
|
78
|
+
console.log(
|
|
79
|
+
chalk.yellow(
|
|
80
|
+
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
81
|
+
'Most CI servers set it automatically.\n',
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
return reject(new Error(messages.warnings.join('\n\n')));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const resolveArgs = {
|
|
88
|
+
stats,
|
|
89
|
+
previousFileSizes,
|
|
90
|
+
warnings: messages.warnings,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return resolve(resolveArgs);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function createProductionBuild(
|
|
99
|
+
paths: AppPaths,
|
|
100
|
+
userConfig: CustomConfigType = defaultDevConfig,
|
|
101
|
+
): Promise<void> {
|
|
102
|
+
// Warn and crash if required files are missing
|
|
103
|
+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const useCustomConfig = fs.existsSync(paths.appCustomConfig);
|
|
108
|
+
|
|
109
|
+
const { configureWebpack, ...options }: CustomConfigType = useCustomConfig
|
|
110
|
+
? merge.all([defaultDevConfig, userConfig, require(paths.appCustomConfig) ?? {}])
|
|
111
|
+
: Object.assign(defaultDevConfig, userConfig);
|
|
112
|
+
|
|
113
|
+
const baseConfig = configFactory('production', paths, options) as Configuration;
|
|
114
|
+
|
|
115
|
+
const config =
|
|
116
|
+
configureWebpack && typeof configureWebpack === 'function'
|
|
117
|
+
? configureWebpack(baseConfig, 'production')
|
|
118
|
+
: baseConfig;
|
|
119
|
+
|
|
120
|
+
const previousSizes = await measureFileSizesBeforeBuild(paths.appBuild);
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
// Remove all content but keep the directory so that
|
|
124
|
+
// if you're in it, you don't end up in Trash
|
|
125
|
+
fs.emptyDirSync(paths.appBuild);
|
|
126
|
+
|
|
127
|
+
// Merge with the public folder
|
|
128
|
+
copyPublicFolder(paths);
|
|
129
|
+
|
|
130
|
+
if (useCustomConfig) {
|
|
131
|
+
console.log(`${chalk.cyan('Using custom config from:')} ${chalk.yellow(paths.appCustomConfig)}\n`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Start the webpack build
|
|
135
|
+
const { stats, previousFileSizes, warnings } = (await build(config, previousSizes)) as any;
|
|
136
|
+
|
|
137
|
+
if (warnings.length) {
|
|
138
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
139
|
+
console.log(warnings.join('\n\n'));
|
|
140
|
+
console.log(`\nSearch for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`);
|
|
141
|
+
console.log(`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`);
|
|
142
|
+
} else {
|
|
143
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('File sizes after gzip:\n');
|
|
147
|
+
printFileSizesAfterBuild(
|
|
148
|
+
stats,
|
|
149
|
+
previousFileSizes,
|
|
150
|
+
paths.appBuild,
|
|
151
|
+
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
152
|
+
WARN_AFTER_CHUNK_GZIP_SIZE,
|
|
153
|
+
);
|
|
154
|
+
console.log();
|
|
155
|
+
|
|
156
|
+
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
157
|
+
const appPackage = require(paths.appPackageJson);
|
|
158
|
+
const publicUrl = paths.publicUrlOrPath;
|
|
159
|
+
const { publicPath } = config.output!;
|
|
160
|
+
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
|
161
|
+
printHostingInstructions(
|
|
162
|
+
appPackage,
|
|
163
|
+
publicUrl,
|
|
164
|
+
typeof publicPath === 'string' ? publicPath : '',
|
|
165
|
+
buildFolder,
|
|
166
|
+
useYarn,
|
|
167
|
+
);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
|
|
170
|
+
if (tscCompileOnError) {
|
|
171
|
+
console.log(
|
|
172
|
+
chalk.yellow(
|
|
173
|
+
'Compiled with the following type errors (you may want to check these before deploying your app):\n',
|
|
174
|
+
),
|
|
175
|
+
);
|
|
176
|
+
printBuildError(err);
|
|
177
|
+
} else {
|
|
178
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
179
|
+
printBuildError(err);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (require.main === module) {
|
|
186
|
+
getEnviroment(defaultPaths);
|
|
187
|
+
createProductionBuild(defaultPaths);
|
|
188
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import spawn from 'cross-spawn';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import validateProjectName from 'validate-npm-package-name';
|
|
6
|
+
|
|
7
|
+
// inquirer is ESM-only — use dynamic import to bridge CommonJS.
|
|
8
|
+
const importInquirer = new Function('m', 'return import(m)') as (m: string) => Promise<any>;
|
|
9
|
+
const inquirerPromise = importInquirer('inquirer').then((m: any) => m.default);
|
|
10
|
+
|
|
11
|
+
export const templateFolder = path.resolve(__dirname, '../../template');
|
|
12
|
+
export const templateDependencies = [
|
|
13
|
+
'react',
|
|
14
|
+
'react-dom',
|
|
15
|
+
'typescript',
|
|
16
|
+
'react-router-dom',
|
|
17
|
+
'@types/react',
|
|
18
|
+
'@types/react-dom',
|
|
19
|
+
'@types/react-router-dom',
|
|
20
|
+
'styled-components',
|
|
21
|
+
'@types/styled-components',
|
|
22
|
+
'@apollion-dsi/core',
|
|
23
|
+
'@apollion-dsi/scripts',
|
|
24
|
+
'@apollion-dsi/eslint-config',
|
|
25
|
+
'audit-ci',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export async function projectNameInput() {
|
|
29
|
+
const inquirer = await inquirerPromise;
|
|
30
|
+
return inquirer.prompt({
|
|
31
|
+
type: 'input',
|
|
32
|
+
name: 'inputName',
|
|
33
|
+
message: 'Nome do Projeto: ',
|
|
34
|
+
validate: (query: string) => {
|
|
35
|
+
const [result, reason] = validProjectName(query);
|
|
36
|
+
return result || `Nome Invalido: ${reason}`;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function validProjectName(appName: string) {
|
|
42
|
+
const validationResult = validateProjectName(appName);
|
|
43
|
+
|
|
44
|
+
if (!validationResult.validForNewPackages) {
|
|
45
|
+
return [false, 'npm naming restrictions'];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (templateDependencies.includes(appName)) {
|
|
49
|
+
return [false, 'dependency with the same name exists'];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (fs.existsSync(appName)) {
|
|
53
|
+
const currentDirectory = process.cwd();
|
|
54
|
+
|
|
55
|
+
const files = fs.readdirSync(path.resolve(currentDirectory, appName));
|
|
56
|
+
|
|
57
|
+
return files.length === 0 ? [true] : [false, `folder with the same name exist in ${currentDirectory}`];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return [true];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function shouldUseYarn() {
|
|
64
|
+
try {
|
|
65
|
+
spawn.sync('yarnpkg', ['--version']);
|
|
66
|
+
return true;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function tryGitInit() {
|
|
73
|
+
try {
|
|
74
|
+
spawn.sync('git', ['init'], { stdio: 'ignore' });
|
|
75
|
+
return true;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function tryGitCommit(appPath: string) {
|
|
82
|
+
try {
|
|
83
|
+
spawn.sync('git', ['add', '-A'], { stdio: 'ignore' });
|
|
84
|
+
spawn.sync('git', ['commit', '-m', 'chore: project started'], {
|
|
85
|
+
stdio: 'ignore',
|
|
86
|
+
});
|
|
87
|
+
return true;
|
|
88
|
+
} catch (e) {
|
|
89
|
+
try {
|
|
90
|
+
fs.removeSync(path.join(appPath, '.git'));
|
|
91
|
+
} catch (removeErr) {
|
|
92
|
+
// Do nothing
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|