@xfe-repo/web-app 1.0.0 → 1.0.2

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.
@@ -10,8 +10,9 @@ spec:
10
10
  - "{{ . }}"
11
11
  {{- end }}
12
12
  gateways:
13
- {{- range $.Values.gateways }}
14
- - {{ . }}
13
+ {{- $gateways := $.Values.gateways }}
14
+ {{- range $gateways }}
15
+ - "{{ . }}"
15
16
  {{- end }}
16
17
  http:
17
18
  - match:
@@ -7,10 +7,10 @@ envType: '<<ENV_TYPE>>'
7
7
  hostPrefix: '<<HOST_PREFIX>>'
8
8
  hosts:
9
9
  test:
10
- - '<<HOST_PREFIX>>.jarvis.t.eshetang.com'
10
+ - '<<HOST_PREFIX>>.pc.t.eshetang.com'
11
11
  stage:
12
- - stage.jarvis.t.eshetang.com
12
+ - 'stage.pc.t.eshetang.com'
13
13
  prod:
14
- - jarvis.eshetang.com
14
+ - 'pc.eshetang.com'
15
15
  gateways:
16
- - common-gateway-eshetang
16
+ - 'common-gateway-eshetang'
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-app",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "bin": {
5
5
  "xfe-web": "./bin/index.js"
6
6
  },
7
7
  "files": [
8
8
  "bin",
9
9
  "config",
10
- "deploy"
10
+ "deploy",
11
+ "scripts"
11
12
  ],
12
13
  "dependencies": {
13
14
  "@babel/core": "^7.16.0",
@@ -31,7 +32,6 @@
31
32
  "css-minimizer-webpack-plugin": "^3.2.0",
32
33
  "dotenv": "^10.0.0",
33
34
  "dotenv-expand": "^5.1.0",
34
- "eslint": "^8.3.0",
35
35
  "eslint-config-react-app": "^7.0.1",
36
36
  "eslint-webpack-plugin": "^3.1.1",
37
37
  "file-loader": "^6.2.0",
@@ -66,14 +66,14 @@
66
66
  "style-loader": "^3.3.1",
67
67
  "tailwindcss": "^3.0.2",
68
68
  "terser-webpack-plugin": "^5.2.5",
69
- "typescript": "^5.2.2",
70
69
  "web-vitals": "^2.1.4",
71
70
  "webpack": "^5.64.4",
72
71
  "webpack-bundle-analyzer": "^4.8.0",
73
72
  "webpack-dev-server": "^4.6.0",
74
73
  "webpack-manifest-plugin": "^4.0.2",
75
74
  "workbox-webpack-plugin": "^7.0.0",
76
- "@xfe-repo/typescript-config": "0.0.0",
77
- "@xfe-repo/eslint-config": "0.0.0"
75
+ "yaml": "^2.3.4",
76
+ "@xfe-repo/eslint-config": "0.0.1",
77
+ "@xfe-repo/typescript-config": "0.0.2"
78
78
  }
79
79
  }
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+
3
+ // Do this as the first thing so that any code reading it knows the right env.
4
+ process.env.BABEL_ENV = "production";
5
+ process.env.NODE_ENV = "production";
6
+
7
+ // Makes the script crash on unhandled rejections instead of silently
8
+ // ignoring them. In the future, promise rejections that are not handled will
9
+ // terminate the Node.js process with a non-zero exit code.
10
+ process.on("unhandledRejection", (err) => {
11
+ throw err;
12
+ });
13
+
14
+ // 加载配置
15
+ require("./config");
16
+
17
+ // Ensure environment variables are read.
18
+ require("../config/env");
19
+
20
+ const path = require("path");
21
+ const chalk = require("react-dev-utils/chalk");
22
+ const fs = require("fs-extra");
23
+ const bfj = require("bfj");
24
+ const webpack = require("webpack");
25
+ const configFactory = require("../config/webpack/webpack.config");
26
+ const paths = require("../config/paths");
27
+ const checkRequiredFiles = require("react-dev-utils/checkRequiredFiles");
28
+ const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
29
+ const printHostingInstructions = require("react-dev-utils/printHostingInstructions");
30
+ const FileSizeReporter = require("react-dev-utils/FileSizeReporter");
31
+ const printBuildError = require("react-dev-utils/printBuildError");
32
+
33
+ const measureFileSizesBeforeBuild =
34
+ FileSizeReporter.measureFileSizesBeforeBuild;
35
+ const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
36
+ const useYarn = fs.existsSync(paths.yarnLockFile);
37
+
38
+ // These sizes are pretty large. We'll warn for bundles exceeding them.
39
+ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
40
+ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
41
+
42
+ const isInteractive = process.stdout.isTTY;
43
+
44
+ // Warn and crash if required files are missing
45
+ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
46
+ process.exit(1);
47
+ }
48
+
49
+ const argv = process.argv.slice(2);
50
+ const writeStatsJson = argv.indexOf("--stats") !== -1;
51
+
52
+ // Generate configuration
53
+ const config = configFactory("production");
54
+
55
+ // We require that you explicitly set browsers and do not fall back to
56
+ // browserslist defaults.
57
+ const { checkBrowsers } = require("react-dev-utils/browsersHelper");
58
+ checkBrowsers(paths.appPath, isInteractive)
59
+ .then(() => {
60
+ // First, read the current file sizes in build directory.
61
+ // This lets us display how much they changed later.
62
+ return measureFileSizesBeforeBuild(paths.appBuild);
63
+ })
64
+ .then((previousFileSizes) => {
65
+ // Remove all content but keep the directory so that
66
+ // if you're in it, you don't end up in Trash
67
+ fs.emptyDirSync(paths.appBuild);
68
+ // Merge with the public folder
69
+ copyPublicFolder();
70
+ // Start the webpack build
71
+ return build(previousFileSizes);
72
+ })
73
+ .then(
74
+ ({ stats, previousFileSizes, warnings }) => {
75
+ if (warnings.length) {
76
+ console.log(chalk.yellow("Compiled with warnings.\n"));
77
+ console.log(warnings.join("\n\n"));
78
+ console.log(
79
+ "\nSearch for the " +
80
+ chalk.underline(chalk.yellow("keywords")) +
81
+ " to learn more about each warning."
82
+ );
83
+ console.log(
84
+ "To ignore, add " +
85
+ chalk.cyan("// eslint-disable-next-line") +
86
+ " to the line before.\n"
87
+ );
88
+ } else {
89
+ console.log(chalk.green("Compiled successfully.\n"));
90
+ }
91
+
92
+ console.log("File sizes after gzip:\n");
93
+ printFileSizesAfterBuild(
94
+ stats,
95
+ previousFileSizes,
96
+ paths.appBuild,
97
+ WARN_AFTER_BUNDLE_GZIP_SIZE,
98
+ WARN_AFTER_CHUNK_GZIP_SIZE
99
+ );
100
+ console.log();
101
+
102
+ const appPackage = require(paths.appPackageJson);
103
+ const publicUrl = paths.publicUrlOrPath;
104
+ const publicPath = config.output.publicPath;
105
+ const buildFolder = path.relative(process.cwd(), paths.appBuild);
106
+ printHostingInstructions(
107
+ appPackage,
108
+ publicUrl,
109
+ publicPath,
110
+ buildFolder,
111
+ useYarn
112
+ );
113
+ },
114
+ (err) => {
115
+ const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === "true";
116
+ if (tscCompileOnError) {
117
+ console.log(
118
+ chalk.yellow(
119
+ "Compiled with the following type errors (you may want to check these before deploying your app):\n"
120
+ )
121
+ );
122
+ printBuildError(err);
123
+ } else {
124
+ console.log(chalk.red("Failed to compile.\n"));
125
+ printBuildError(err);
126
+ process.exit(1);
127
+ }
128
+ }
129
+ )
130
+ .catch((err) => {
131
+ if (err && err.message) {
132
+ console.log(err.message);
133
+ }
134
+ process.exit(1);
135
+ });
136
+
137
+ // Create the production build and print the deployment instructions.
138
+ function build(previousFileSizes) {
139
+ console.log("Creating an optimized production build...");
140
+
141
+ const compiler = webpack(config);
142
+ return new Promise((resolve, reject) => {
143
+ compiler.run((err, stats) => {
144
+ let messages;
145
+ if (err) {
146
+ if (!err.message) {
147
+ return reject(err);
148
+ }
149
+
150
+ let errMessage = err.message;
151
+
152
+ // Add additional information for postcss errors
153
+ if (Object.prototype.hasOwnProperty.call(err, "postcssNode")) {
154
+ errMessage +=
155
+ "\nCompileError: Begins at CSS selector " +
156
+ err["postcssNode"].selector;
157
+ }
158
+
159
+ messages = formatWebpackMessages({
160
+ errors: [errMessage],
161
+ warnings: [],
162
+ });
163
+ } else {
164
+ messages = formatWebpackMessages(
165
+ stats.toJson({ all: false, warnings: true, errors: true })
166
+ );
167
+ }
168
+ if (messages.errors.length) {
169
+ // Only keep the first error. Others are often indicative
170
+ // of the same problem, but confuse the reader with noise.
171
+ if (messages.errors.length > 1) {
172
+ messages.errors.length = 1;
173
+ }
174
+ return reject(new Error(messages.errors.join("\n\n")));
175
+ }
176
+ if (
177
+ process.env.CI &&
178
+ (typeof process.env.CI !== "string" ||
179
+ process.env.CI.toLowerCase() !== "false") &&
180
+ messages.warnings.length
181
+ ) {
182
+ // Ignore sourcemap warnings in CI builds. See #8227 for more info.
183
+ const filteredWarnings = messages.warnings.filter(
184
+ (w) => !/Failed to parse source map/.test(w)
185
+ );
186
+ if (filteredWarnings.length) {
187
+ console.log(
188
+ chalk.yellow(
189
+ "\nTreating warnings as errors because process.env.CI = true.\n" +
190
+ "Most CI servers set it automatically.\n"
191
+ )
192
+ );
193
+ return reject(new Error(filteredWarnings.join("\n\n")));
194
+ }
195
+ }
196
+
197
+ const resolveArgs = {
198
+ stats,
199
+ previousFileSizes,
200
+ warnings: messages.warnings,
201
+ };
202
+
203
+ if (writeStatsJson) {
204
+ return bfj
205
+ .write(paths.appBuild + "/bundle-stats.json", stats.toJson())
206
+ .then(() => resolve(resolveArgs))
207
+ .catch((error) => reject(new Error(error)));
208
+ }
209
+
210
+ return resolve(resolveArgs);
211
+ });
212
+ });
213
+ }
214
+
215
+ function copyPublicFolder() {
216
+ fs.copySync(paths.appPublic, paths.appBuild, {
217
+ dereference: true,
218
+ filter: (file) => file !== paths.appHtml,
219
+ });
220
+ }
@@ -0,0 +1,33 @@
1
+ // 读取配置并作出相应的处理
2
+ const fs = require('fs')
3
+ const yaml = require('yaml')
4
+ const path = require('path')
5
+
6
+ /* deploy 相关配置写入 */
7
+ const configDeploy = () => {
8
+ // 读取xfe.json
9
+ const xfeConfig = JSON.parse(fs.readFileSync('./xfe.json', 'utf8'))
10
+
11
+ if (!xfeConfig?.deploy) return
12
+
13
+ // 处理写入deploy values配置
14
+ const valuesYamlFilePath = path.resolve(__dirname, '../deploy/helm/values.yaml')
15
+ const valuesYamlFile = fs.readFileSync(valuesYamlFilePath, 'utf8')
16
+ const valuesYaml = yaml.parse(valuesYamlFile)
17
+
18
+ if(!valuesYaml.hosts) valuesYaml.hosts = { test: [], stage: [], prod: [] }
19
+
20
+ valuesYaml.hosts.prod = xfeConfig.deploy.hostsProd || []
21
+ valuesYaml.hosts.stage = xfeConfig.deploy.hostsStage || []
22
+ valuesYaml.hosts.test = xfeConfig.deploy.hostsTest || []
23
+
24
+ // gateways 默认为 common-gateway-eshetang
25
+ valuesYaml.gateways = xfeConfig.deploy.gateways || ["common-gateway-eshetang"]
26
+
27
+ // 写入values.yaml
28
+ const valuesYamlStr = yaml.stringify(valuesYaml, { defaultStringType: 'QUOTE_SINGLE', defaultKeyType: 'PLAIN' })
29
+ fs.writeFileSync(valuesYamlFilePath, valuesYamlStr, 'utf8')
30
+ }
31
+
32
+ /* 其他配置待扩展 */
33
+ configDeploy()
package/scripts/dev.js ADDED
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ // Do this as the first thing so that any code reading it knows the right env.
4
+ process.env.BABEL_ENV = "development";
5
+ process.env.NODE_ENV = "development";
6
+
7
+ // Makes the script crash on unhandled rejections instead of silently
8
+ // ignoring them. In the future, promise rejections that are not handled will
9
+ // terminate the Node.js process with a non-zero exit code.
10
+ process.on("unhandledRejection", (err) => {
11
+ throw err;
12
+ });
13
+
14
+ // 加载配置
15
+ require("./config");
16
+
17
+ // Ensure environment variables are read.
18
+ require("../config/env");
19
+
20
+ const fs = require("fs");
21
+ const chalk = require("react-dev-utils/chalk");
22
+ const webpack = require("webpack");
23
+ const WebpackDevServer = require("webpack-dev-server");
24
+ const clearConsole = require("react-dev-utils/clearConsole");
25
+ const checkRequiredFiles = require("react-dev-utils/checkRequiredFiles");
26
+ const {
27
+ choosePort,
28
+ createCompiler,
29
+ prepareProxy,
30
+ prepareUrls,
31
+ } = require("react-dev-utils/WebpackDevServerUtils");
32
+ const openBrowser = require("react-dev-utils/openBrowser");
33
+ const semver = require("semver");
34
+ const paths = require("../config/paths");
35
+ const configFactory = require("../config/webpack/webpack.config");
36
+ const createDevServerConfig = require("../config/webpack/webpackDevServer.config");
37
+ const getClientEnvironment = require("../config/env");
38
+ const react = require(require.resolve("react", { paths: [paths.appPath] }));
39
+
40
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
41
+ const useYarn = fs.existsSync(paths.yarnLockFile);
42
+ const isInteractive = process.stdout.isTTY;
43
+
44
+ // Warn and crash if required files are missing
45
+ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
46
+ process.exit(1);
47
+ }
48
+
49
+ // Tools like Cloud9 rely on this.
50
+ const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
51
+ const HOST = process.env.HOST || "0.0.0.0";
52
+
53
+ if (process.env.HOST) {
54
+ console.log(
55
+ chalk.cyan(
56
+ `Attempting to bind to HOST environment variable: ${chalk.yellow(
57
+ chalk.bold(process.env.HOST)
58
+ )}`
59
+ )
60
+ );
61
+ console.log(
62
+ `If this was unintentional, check that you haven't mistakenly set it in your shell.`
63
+ );
64
+ console.log(
65
+ `Learn more here: ${chalk.yellow("https://cra.link/advanced-config")}`
66
+ );
67
+ console.log();
68
+ }
69
+
70
+ // We require that you explicitly set browsers and do not fall back to
71
+ // browserslist defaults.
72
+ const { checkBrowsers } = require("react-dev-utils/browsersHelper");
73
+ checkBrowsers(paths.appPath, isInteractive)
74
+ .then(() => {
75
+ // We attempt to use the default port but if it is busy, we offer the user to
76
+ // run on a different port. `choosePort()` Promise resolves to the next free port.
77
+ return choosePort(HOST, DEFAULT_PORT);
78
+ })
79
+ .then((port) => {
80
+ if (port == null) {
81
+ // We have not found a port.
82
+ return;
83
+ }
84
+
85
+ const config = configFactory("development");
86
+ const protocol = process.env.HTTPS === "true" ? "https" : "http";
87
+ const appName = require(paths.appPackageJson).name;
88
+
89
+ const useTypeScript = fs.existsSync(paths.appTsConfig);
90
+ const urls = prepareUrls(
91
+ protocol,
92
+ HOST,
93
+ port,
94
+ paths.publicUrlOrPath.slice(0, -1)
95
+ );
96
+ // Create a webpack compiler that is configured with custom messages.
97
+ const compiler = createCompiler({
98
+ appName,
99
+ config,
100
+ urls,
101
+ useYarn,
102
+ useTypeScript,
103
+ webpack,
104
+ });
105
+ // Load proxy config
106
+ const proxySetting = require(paths.appPackageJson).proxy;
107
+ const proxyConfig = prepareProxy(
108
+ proxySetting,
109
+ paths.appPublic,
110
+ paths.publicUrlOrPath
111
+ );
112
+ // Serve webpack assets generated by the compiler over a web server.
113
+ const serverConfig = {
114
+ ...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
115
+ host: HOST,
116
+ port,
117
+ };
118
+ const devServer = new WebpackDevServer(serverConfig, compiler);
119
+ // Launch WebpackDevServer.
120
+ devServer.startCallback(() => {
121
+ if (isInteractive) {
122
+ clearConsole();
123
+ }
124
+
125
+ if (env.raw.FAST_REFRESH && semver.lt(react.version, "16.10.0")) {
126
+ console.log(
127
+ chalk.yellow(
128
+ `Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
129
+ )
130
+ );
131
+ }
132
+
133
+ console.log(chalk.cyan("Starting the development server...\n"));
134
+ openBrowser(urls.localUrlForBrowser);
135
+ });
136
+
137
+ ["SIGINT", "SIGTERM"].forEach(function (sig) {
138
+ process.on(sig, function () {
139
+ devServer.close();
140
+ process.exit();
141
+ });
142
+ });
143
+
144
+ if (process.env.CI !== "true") {
145
+ // Gracefully exit when stdin ends
146
+ process.stdin.on("end", function () {
147
+ devServer.close();
148
+ process.exit();
149
+ });
150
+ }
151
+ })
152
+ .catch((err) => {
153
+ if (err && err.message) {
154
+ console.log(err.message);
155
+ }
156
+ process.exit(1);
157
+ });
@@ -0,0 +1,81 @@
1
+ 'use strict'
2
+
3
+ process.env.NODE_ENV = 'development'
4
+
5
+ // 加载配置
6
+ require("./config");
7
+
8
+ const chalk = require('chalk')
9
+ const webpack = require('webpack')
10
+ const nodemon = require('nodemon')
11
+ const configFactory = require('../config/webpack/webpack.config.ssr')
12
+
13
+ console.log(
14
+ chalk.magenta('\n[INFO]') +
15
+ ' You need to open the ' +
16
+ chalk.underline('dev server') +
17
+ ' with ' +
18
+ chalk.underline('npm start') +
19
+ ' command first.'
20
+ )
21
+
22
+ console.log(chalk.cyan('\nWebpack starts to build and watch your files...\n'))
23
+
24
+ const config = configFactory('development')
25
+
26
+ const compiler = webpack(config)
27
+
28
+ let nm
29
+
30
+ compiler.watch('./src/**/*.[js,jsx,ts,tsx]', (err, stats) => {
31
+ if (err) {
32
+ console.error(err.stack || err)
33
+
34
+ if (err.details) console.error(err.details)
35
+
36
+ return
37
+ }
38
+
39
+ const statsString = stats.toString({
40
+ colors: true,
41
+ })
42
+
43
+ console.log(statsString)
44
+
45
+ console.log(chalk.magenta('[Webpack]') + ' Compiled' + chalk.grey(' [timestamp:' + Date.now() + ']'))
46
+
47
+ // spawn nodemon process if it wasn't already spawned
48
+ if (!nm) {
49
+ console.log(chalk.cyan('\nStarting nodemon...\n'))
50
+ nm = spawnNodemon('./server/index.js')
51
+ } else {
52
+ nm.restart()
53
+ }
54
+ })
55
+
56
+ function spawnNodemon(filePath) {
57
+ nodemon({
58
+ script: filePath,
59
+ watch: ['./server/'],
60
+ ext: 'js,json',
61
+ })
62
+
63
+ nodemon
64
+ .on('start', function () {
65
+ console.log(chalk.yellow('[nodemon]') + ' App has started')
66
+ })
67
+ .on('quit', function () {
68
+ console.log(chalk.yellow('[nodemon]') + ' App has quit')
69
+ })
70
+ .on('restart', function (files) {
71
+ console.log(chalk.yellow('[nodemon]') + ' App restarted due to: ' + files)
72
+ })
73
+
74
+ process.once('SIGINT', function () {
75
+ nodemon.once('exit', function () {
76
+ process.exit()
77
+ })
78
+ })
79
+
80
+ return nodemon
81
+ }
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ // Do this as the first thing so that any code reading it knows the right env.
4
+ process.env.BABEL_ENV = 'test';
5
+ process.env.NODE_ENV = 'test';
6
+ process.env.PUBLIC_URL = '';
7
+
8
+ // Makes the script crash on unhandled rejections instead of silently
9
+ // ignoring them. In the future, promise rejections that are not handled will
10
+ // terminate the Node.js process with a non-zero exit code.
11
+ process.on('unhandledRejection', err => {
12
+ throw err;
13
+ });
14
+
15
+ // Ensure environment variables are read.
16
+ require('../config/env');
17
+
18
+ const jest = require('jest');
19
+ const execSync = require('child_process').execSync;
20
+ let argv = process.argv.slice(2);
21
+
22
+ function isInGitRepository() {
23
+ try {
24
+ execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
25
+ return true;
26
+ } catch (e) {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ function isInMercurialRepository() {
32
+ try {
33
+ execSync('hg --cwd . root', { stdio: 'ignore' });
34
+ return true;
35
+ } catch (e) {
36
+ return false;
37
+ }
38
+ }
39
+
40
+ // Watch unless on CI or explicitly running all tests
41
+ if (
42
+ !process.env.CI &&
43
+ argv.indexOf('--watchAll') === -1 &&
44
+ argv.indexOf('--watchAll=false') === -1
45
+ ) {
46
+ // https://github.com/facebook/create-react-app/issues/5210
47
+ const hasSourceControl = isInGitRepository() || isInMercurialRepository();
48
+ argv.push(hasSourceControl ? '--watch' : '--watchAll');
49
+ }
50
+
51
+
52
+ jest.run(argv);