@teams-max/mwsp 1.0.2 → 2.0.1

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 (96) hide show
  1. package/bin/mwsp.js +2 -31
  2. package/es/cli/build.d.ts +0 -1
  3. package/es/cli/build.js +69 -61
  4. package/es/cli/cli.js +4 -12
  5. package/es/cli/start.d.ts +0 -1
  6. package/es/cli/start.js +48 -26
  7. package/es/index.d.ts +2 -0
  8. package/es/index.js +3 -1
  9. package/es/utils/chalk/LICENSE +9 -0
  10. package/es/utils/chalk/index.d.ts +416 -0
  11. package/es/utils/chalk/index.js +1719 -0
  12. package/es/utils/chalk/package.json +6 -0
  13. package/es/{cli/update.js → utils/changelog.js} +41 -34
  14. package/es/utils/cross-spawn/package.json +7 -0
  15. package/es/{internal → utils}/datetimeFormat.js +1 -3
  16. package/es/utils/defineConfig.js +20 -0
  17. package/es/{internal → utils}/exec.js +3 -2
  18. package/{lib/internal → es/utils}/execa/index.d.ts +41 -11
  19. package/es/utils/execa/package.json +11 -0
  20. package/es/utils/getPackages.js +9 -0
  21. package/es/{cli/dev.js → utils/git.js} +88 -36
  22. package/es/{internal/utils.js → utils/index.js} +270 -70
  23. package/es/utils/isNextVersion.js +3 -0
  24. package/{lib/internal → es/utils}/merge-stream/index.d.ts +3 -1
  25. package/es/utils/merge-stream/package.json +7 -0
  26. package/es/utils/parseDoc.js +33 -0
  27. package/es/utils/yargs-parser/index.d.ts +114 -0
  28. package/es/utils/yargs-parser/index.js +919 -0
  29. package/es/utils/yargs-parser/package.json +7 -0
  30. package/lib/cli/build.d.ts +0 -1
  31. package/lib/cli/build.js +54 -50
  32. package/lib/cli/cli.js +0 -8
  33. package/lib/cli/start.d.ts +0 -1
  34. package/lib/cli/start.js +25 -30
  35. package/lib/index.d.ts +2 -0
  36. package/lib/index.js +3 -0
  37. package/lib/utils/chalk/LICENSE +9 -0
  38. package/lib/utils/chalk/index.d.ts +416 -0
  39. package/lib/utils/chalk/index.js +1538 -0
  40. package/lib/utils/chalk/package.json +6 -0
  41. package/lib/utils/changelog.js +21 -0
  42. package/lib/{internal → utils}/cross-spawn/index.js +9 -3
  43. package/lib/utils/cross-spawn/package.json +7 -0
  44. package/lib/{internal → utils}/datetimeFormat.js +14 -30
  45. package/lib/utils/defineConfig.js +26 -0
  46. package/lib/utils/exec.js +23 -0
  47. package/{es/internal → lib/utils}/execa/index.d.ts +41 -11
  48. package/lib/{internal → utils}/execa/index.js +76 -18
  49. package/lib/utils/execa/package.json +11 -0
  50. package/lib/utils/getPackages.js +8 -0
  51. package/lib/utils/git.js +31 -0
  52. package/lib/utils/index.js +183 -0
  53. package/lib/utils/isNextVersion.js +4 -0
  54. package/{es/internal → lib/utils}/merge-stream/index.d.ts +3 -1
  55. package/lib/{internal → utils}/merge-stream/index.js +1 -1
  56. package/lib/utils/merge-stream/package.json +7 -0
  57. package/lib/utils/parseDoc.js +30 -0
  58. package/lib/utils/yargs-parser/index.d.ts +114 -0
  59. package/lib/utils/yargs-parser/index.js +919 -0
  60. package/lib/utils/yargs-parser/package.json +7 -0
  61. package/package.json +7 -14
  62. package/es/cli/dev.d.ts +0 -1
  63. package/es/cli/update.d.ts +0 -2
  64. package/es/internal/buildNotify.d.ts +0 -10
  65. package/es/internal/buildNotify.js +0 -123
  66. package/es/internal/cross-spawn/package.json +0 -1
  67. package/es/internal/datetimeFormat.d.ts +0 -9
  68. package/es/internal/exec.d.ts +0 -1
  69. package/es/internal/execa/package.json +0 -1
  70. package/es/internal/merge-stream/package.json +0 -1
  71. package/es/internal/utils.d.ts +0 -14
  72. package/lib/cli/dev.d.ts +0 -1
  73. package/lib/cli/dev.js +0 -62
  74. package/lib/cli/update.d.ts +0 -2
  75. package/lib/cli/update.js +0 -50
  76. package/lib/internal/buildNotify.d.ts +0 -10
  77. package/lib/internal/buildNotify.js +0 -112
  78. package/lib/internal/cross-spawn/package.json +0 -1
  79. package/lib/internal/datetimeFormat.d.ts +0 -9
  80. package/lib/internal/exec.d.ts +0 -1
  81. package/lib/internal/exec.js +0 -60
  82. package/lib/internal/execa/package.json +0 -1
  83. package/lib/internal/merge-stream/package.json +0 -1
  84. package/lib/internal/utils.d.ts +0 -14
  85. package/lib/internal/utils.js +0 -100
  86. /package/es/{internal → utils}/cross-spawn/LICENSE +0 -0
  87. /package/es/{internal → utils}/cross-spawn/index.d.ts +0 -0
  88. /package/es/{internal → utils}/cross-spawn/index.js +0 -0
  89. /package/es/{internal → utils}/execa/LICENSE +0 -0
  90. /package/es/{internal → utils}/execa/index.js +0 -0
  91. /package/es/{internal → utils}/merge-stream/LICENSE +0 -0
  92. /package/es/{internal → utils}/merge-stream/index.js +0 -0
  93. /package/lib/{internal → utils}/cross-spawn/LICENSE +0 -0
  94. /package/lib/{internal → utils}/cross-spawn/index.d.ts +0 -0
  95. /package/lib/{internal → utils}/execa/LICENSE +0 -0
  96. /package/lib/{internal → utils}/merge-stream/LICENSE +0 -0
@@ -0,0 +1,183 @@
1
+ // src/utils/index.js
2
+ var fs = require("fs");
3
+ var { join } = require("path");
4
+ var inquirer = require("inquirer");
5
+ var yParser = require("./yargs-parser");
6
+ var execa = require("./execa");
7
+ var exec = require("./exec");
8
+ var chalk = require("./chalk");
9
+ var cwd = process.cwd() || process.env.INIT_CWD || process.env.PWD;
10
+ var asgDir = join(cwd, ".asg");
11
+ function logStep(...args) {
12
+ const name = `${chalk.magenta.bold(args == null ? void 0 : args[0])}`;
13
+ const desc = (args == null ? void 0 : args[1]) ? `${chalk.greenBright(args.slice(1).join(" "))}` : "";
14
+ console.log(`${chalk.gray("[MWSP] ")} ${name} ${desc}`);
15
+ }
16
+ function printError(...args) {
17
+ const name = `${chalk.red.bold(args == null ? void 0 : args[0])}`;
18
+ const desc = (args == null ? void 0 : args[1]) ? `${chalk.greenBright(args.slice(1).join(" "))}` : "";
19
+ console.error(`${chalk.gray(" >> Error: [MWSP] ")} ${name} ${desc}`);
20
+ }
21
+ function printErrorAndExit(...args) {
22
+ printError(args);
23
+ process.exit(1);
24
+ }
25
+ function pickDependencies(dependencies, isDev) {
26
+ const pkgs = require(join(cwd, "package.json"));
27
+ return dependencies.filter((p) => {
28
+ if (isDev) {
29
+ return !pkgs.devDependencies[p];
30
+ } else {
31
+ return !pkgs.dependencies[p];
32
+ }
33
+ });
34
+ }
35
+ function getCfg() {
36
+ const pkgs = require(join(cwd, "package.json"));
37
+ const { infra = {}, appKey } = pkgs;
38
+ if (!(infra == null ? void 0 : infra.url) || !appKey) {
39
+ printErrorAndExit("Please check the infra and appKey in package.json.");
40
+ }
41
+ const args = yParser(process.argv.slice(2));
42
+ const JENKINS_BUILD = args.jenkinsBuild || args.JENKINSBUILD || args.jenkins_build || args.JENKINS_BUILD;
43
+ const APP_ENV = args.env || args.ENV || "";
44
+ const ASG_BRAHCH = args.asg_branch || args.ASG_BRAHCH || "";
45
+ let RESOURCE_URL = "";
46
+ let SUB_APP = "";
47
+ let archStr = "unknown";
48
+ if (infra.url.includes("teams-pro")) {
49
+ archStr = "PRO";
50
+ } else if (infra.url.includes("teams-max")) {
51
+ archStr = "MAX";
52
+ RESOURCE_URL = args.versionUrl || args.RESOURCE_URL || "";
53
+ SUB_APP = args.subApp || args.SUB_APP || "";
54
+ }
55
+ return {
56
+ appKey,
57
+ infra: {
58
+ url: infra.url,
59
+ arch: archStr
60
+ },
61
+ ASG_DIR: asgDir,
62
+ JENKINS_BUILD,
63
+ ASG_BRAHCH,
64
+ APP_ENV,
65
+ RESOURCE_URL,
66
+ SUB_APP
67
+ };
68
+ }
69
+ function checkDirectoryExistsSync(dirPath) {
70
+ try {
71
+ const stats = fs.statSync(dirPath);
72
+ return stats.isDirectory();
73
+ } catch (err) {
74
+ if (err.code === "ENOENT") {
75
+ return false;
76
+ } else {
77
+ printErrorAndExit(err);
78
+ }
79
+ }
80
+ }
81
+ async function fetchRemoteRepository() {
82
+ const cfg = getCfg();
83
+ const { infra, ASG_DIR: directory, ASG_BRAHCH, JENKINS_BUILD } = cfg;
84
+ const remoteUrl = infra.url;
85
+ const doesExist = checkDirectoryExistsSync(directory);
86
+ if (!doesExist) {
87
+ logStep("Cloning the repository from GitHub...");
88
+ execa.sync("git", ["clone", "-b", "feature-asg", remoteUrl, directory]);
89
+ logStep("Cloning completed.");
90
+ logStep("Installing dependencies...");
91
+ if ((infra == null ? void 0 : infra.arch) === "PRO") {
92
+ const proDevDeps = pickDependencies(["snb-mock-middleware", "lodash-webpack-plugin"], true);
93
+ !!proDevDeps.length && await exec("yarn", ["add", ...proDevDeps, "-D"]);
94
+ const proDeps = pickDependencies(["@teams-max/skynet", "history"]);
95
+ !!proDeps.length && await exec("yarn", ["add", ...proDeps]);
96
+ } else if ((infra == null ? void 0 : infra.arch) === "MAX") {
97
+ const maxDevDeps = pickDependencies(["axios"], true);
98
+ !!maxDevDeps.length && await exec("pnpm", ["add", ...maxDevDeps, "-D"]);
99
+ const maxDeps = pickDependencies(["@teams-max/skynet", "classnames", "qs", "uuid", "react-draggable", "lodash", "moment", "dayjs"]);
100
+ !!maxDeps.length && await exec("pnpm", ["add", ...maxDeps]);
101
+ }
102
+ logStep("Installation completed.");
103
+ } else if (JENKINS_BUILD && !ASG_BRAHCH) {
104
+ logStep("Jenkins build detected. Skipping sync up.");
105
+ return;
106
+ } else {
107
+ if (!JENKINS_BUILD) {
108
+ const { syncUp } = await inquirer.prompt([
109
+ {
110
+ type: "confirm",
111
+ name: "syncUp",
112
+ message: "\u540C\u6B65\u8FDC\u7AEF\u4ED3\u5E93",
113
+ default: "Y"
114
+ }
115
+ ]);
116
+ if (!syncUp)
117
+ return;
118
+ }
119
+ }
120
+ if (!doesExist && JENKINS_BUILD && !ASG_BRAHCH) {
121
+ printErrorAndExit(
122
+ "Jenkins build detected. The branch parameter is missing!"
123
+ );
124
+ return;
125
+ }
126
+ logStep("Synchronizing with the remote repository...");
127
+ process.chdir(directory);
128
+ try {
129
+ execa.sync("git", ["fetch", "origin", "--prune"]);
130
+ if (JENKINS_BUILD && ASG_BRAHCH) {
131
+ execa.sync("git", ["checkout", ASG_BRAHCH]);
132
+ logStep(`Anto switched to branch:`, ASG_BRAHCH);
133
+ } else {
134
+ const infraBranchsOutput = execa.sync("git", ["branch", "-r"]).stdout;
135
+ const infraBranchArray = infraBranchsOutput.trim().split("\n");
136
+ const filteredBranches = infraBranchArray.map((b) => b.trim()).filter(
137
+ (b) => !(b.startsWith("origin/HEA") || b.startsWith("origin/app-") || b.startsWith("app-"))
138
+ );
139
+ const defaultBrancheIdx = filteredBranches.indexOf("origin/feature-asg");
140
+ if (defaultBrancheIdx !== -1) {
141
+ filteredBranches.splice(defaultBrancheIdx, 1);
142
+ filteredBranches.unshift("origin/feature-asg");
143
+ }
144
+ if (filteredBranches.length === 0) {
145
+ printErrorAndExit("No branches available for selection.");
146
+ }
147
+ const questions = await inquirer.prompt([
148
+ {
149
+ type: "list",
150
+ name: "branch",
151
+ message: "Please select the branch first: ",
152
+ choices: filteredBranches,
153
+ validate: function(val) {
154
+ if (!val || !val.length) {
155
+ return "Please select a branch!";
156
+ }
157
+ return true;
158
+ }
159
+ }
160
+ ]);
161
+ try {
162
+ execa.sync("git", ["checkout", "-q", questions.branch]);
163
+ logStep(`Switched to branch:`, questions.branch);
164
+ } catch (error) {
165
+ printErrorAndExit(
166
+ `Failed to switch to branch '${questions.branch}'. Reason: ${error.message}`
167
+ );
168
+ }
169
+ }
170
+ } catch (error) {
171
+ printErrorAndExit(
172
+ `An error occurred while fetching remote branches: ${error.message}`
173
+ );
174
+ }
175
+ process.chdir(cwd);
176
+ }
177
+ module.exports.yParser = yParser;
178
+ module.exports.execa = execa;
179
+ module.exports.chalk = chalk;
180
+ module.exports.logStep = logStep;
181
+ module.exports.printErrorAndExit = printErrorAndExit;
182
+ module.exports.getCfg = getCfg;
183
+ module.exports.fetchRemoteRepository = fetchRemoteRepository;
@@ -0,0 +1,4 @@
1
+ // src/utils/isNextVersion.js
2
+ module.exports = function(version) {
3
+ return version.includes("-rc.") || version.includes("-beta.") || version.includes("-alpha.");
4
+ };
@@ -9,7 +9,9 @@
9
9
  /// <reference types="node"/>
10
10
 
11
11
  interface MergedStream extends NodeJS.ReadWriteStream {
12
- add(source: NodeJS.ReadableStream | ReadonlyArray<NodeJS.ReadableStream>): MergedStream;
12
+ add(
13
+ source: NodeJS.ReadableStream | ReadonlyArray<NodeJS.ReadableStream>,
14
+ ): MergedStream;
13
15
  isEmpty(): boolean;
14
16
  }
15
17
 
@@ -1,4 +1,4 @@
1
- // src/internal/merge-stream/index.js
1
+ // src/utils/merge-stream/index.js
2
2
  module.exports = (() => {
3
3
  "use strict";
4
4
  var e = {
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "merge-stream",
3
+ "license": "MIT",
4
+ "author": "Stephen Sugden <me@stephensugden.com>",
5
+ "main": "index.js",
6
+ "types": "index.d.ts"
7
+ }
@@ -0,0 +1,30 @@
1
+ // src/utils/parseDoc.js
2
+ module.exports = function(docStr) {
3
+ docStr = docStr.trim();
4
+ const hasYamlConfig = docStr.startsWith("---");
5
+ const docArr = docStr.split("\n");
6
+ let title = null;
7
+ let titleIndex = null;
8
+ let yamlEndIndex = null;
9
+ let i = hasYamlConfig ? 1 : 0;
10
+ while (i < docArr.length) {
11
+ const line = docArr[i];
12
+ if (line.startsWith("---")) {
13
+ yamlEndIndex = i;
14
+ }
15
+ if (line.startsWith("# ") && titleIndex === null) {
16
+ title = line.replace("# ", "");
17
+ titleIndex = i;
18
+ }
19
+ i += 1;
20
+ }
21
+ if (titleIndex === null && yamlEndIndex !== null) {
22
+ titleIndex = yamlEndIndex;
23
+ }
24
+ return {
25
+ hasYamlConfig,
26
+ title,
27
+ yamlConfig: hasYamlConfig ? docArr.slice(1, yamlEndIndex) : [],
28
+ body: docArr.slice(titleIndex === null ? titleIndex : titleIndex + 1)
29
+ };
30
+ };
@@ -0,0 +1,114 @@
1
+ // Type definitions for yargs-parser 20.2
2
+ // Project: https://github.com/yargs/yargs-parser#readme
3
+ // Definitions by: Miles Johnson <https://github.com/milesj>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+ // TypeScript Version: 2.2
6
+
7
+ declare namespace yargsParser {
8
+ interface Arguments {
9
+ /** Non-option arguments */
10
+ _: string[];
11
+ /** The script name or node command */
12
+ $0: string;
13
+ /** All remaining options */
14
+ [argName: string]: any;
15
+ }
16
+
17
+ interface DetailedArguments {
18
+ /** An object representing the parsed value of `args` */
19
+ argv: Arguments;
20
+ /** Populated with an error object if an exception occurred during parsing. */
21
+ error: Error | null;
22
+ /** The inferred list of aliases built by combining lists in opts.alias. */
23
+ aliases: { [alias: string]: string[] };
24
+ /** Any new aliases added via camel-case expansion. */
25
+ newAliases: { [alias: string]: boolean };
26
+ /** The configuration loaded from the yargs stanza in package.json. */
27
+ configuration: Configuration;
28
+ }
29
+
30
+ interface Configuration {
31
+ /** Should variables prefixed with --no be treated as negations? Default is `true` */
32
+ 'boolean-negation': boolean;
33
+ /** Should hyphenated arguments be expanded into camel-case aliases? Default is `true` */
34
+ 'camel-case-expansion': boolean;
35
+ /** Should arrays be combined when provided by both command line arguments and a configuration file. Default is `false` */
36
+ 'combine-arrays': boolean;
37
+ /** Should keys that contain . be treated as objects? Default is `true` */
38
+ 'dot-notation': boolean;
39
+ /** Should arguments be coerced into an array when duplicated. Default is `true` */
40
+ 'duplicate-arguments-array': boolean;
41
+ /** Should array arguments be coerced into a single array when duplicated. Default is `true` */
42
+ 'flatten-duplicate-arrays': boolean;
43
+ /** Should arrays consume more than one positional argument following their flag. Default is `true` */
44
+ 'greedy-arrays': boolean;
45
+ /** Should nargs consume dash options as well as positional arguments. Default is `false` */
46
+ 'nargs-eats-options': boolean;
47
+ /** Should parsing stop at the first text argument? This is similar to how e.g. ssh parses its command line. Default is `false` */
48
+ 'halt-at-non-option': boolean;
49
+ /** The prefix to use for negated boolean variables. Default is `'no-'` */
50
+ 'negation-prefix': string;
51
+ /** Should keys that look like numbers be treated as such? Default is `true` */
52
+ 'parse-numbers': boolean;
53
+ /** Should positional keys that look like numbers be treated as such? Default is `true` */
54
+ 'parse-positional-numbers': boolean;
55
+ /** Should unparsed flags be stored in -- or _. Default is `false` */
56
+ 'populate--': boolean;
57
+ /** Should a placeholder be added for keys not set via the corresponding CLI argument? Default is `false` */
58
+ 'set-placeholder-key': boolean;
59
+ /** Should a group of short-options be treated as boolean flags? Default is `true` */
60
+ 'short-option-groups': boolean;
61
+ /** Should aliases be removed before returning results? Default is `false` */
62
+ 'strip-aliased': boolean;
63
+ /** Should dashed keys be removed before returning results? This option has no effect if camel-case-expansion is disabled. Default is `false` */
64
+ 'strip-dashed': boolean;
65
+ /** Should unknown options be treated like regular arguments? An unknown option is one that is not configured in opts. Default is `false` */
66
+ 'unknown-options-as-args': boolean;
67
+ }
68
+
69
+ interface Options {
70
+ /** An object representing the set of aliases for a key: `{ alias: { foo: ['f']} }`. */
71
+ alias?: { [key: string]: string | string[] };
72
+ /**
73
+ * Indicate that keys should be parsed as an array: `{ array: ['foo', 'bar'] }`.
74
+ * Indicate that keys should be parsed as an array and coerced to booleans / numbers:
75
+ * { array: [ { key: 'foo', boolean: true }, {key: 'bar', number: true} ] }`.
76
+ */
77
+ array?:
78
+ | string[]
79
+ | Array<{ key: string; boolean?: boolean; number?: boolean }>;
80
+ /** Arguments should be parsed as booleans: `{ boolean: ['x', 'y'] }`. */
81
+ boolean?: string[];
82
+ /** Indicate a key that represents a path to a configuration file (this file will be loaded and parsed). */
83
+ config?: string | string[] | { [key: string]: boolean };
84
+ /** Provide configuration options to the yargs-parser. */
85
+ configuration?: Partial<Configuration>;
86
+ /**
87
+ * Provide a custom synchronous function that returns a coerced value from the argument provided (or throws an error), e.g.
88
+ * `{ coerce: { foo: function (arg) { return modifiedArg } } }`.
89
+ */
90
+ coerce?: { [key: string]: (arg: any) => any };
91
+ /** Indicate a key that should be used as a counter, e.g., `-vvv = {v: 3}`. */
92
+ count?: string[];
93
+ /** Provide default values for keys: `{ default: { x: 33, y: 'hello world!' } }`. */
94
+ default?: { [key: string]: any };
95
+ /** Environment variables (`process.env`) with the prefix provided should be parsed. */
96
+ envPrefix?: string;
97
+ /** Specify that a key requires n arguments: `{ narg: {x: 2} }`. */
98
+ narg?: { [key: string]: number };
99
+ /** `path.normalize()` will be applied to values set to this key. */
100
+ normalize?: string[];
101
+ /** Keys should be treated as strings (even if they resemble a number `-x 33`). */
102
+ string?: string[];
103
+ /** Keys should be treated as numbers. */
104
+ number?: string[];
105
+ }
106
+
107
+ interface Parser {
108
+ (argv: string | string[], opts?: Options): Arguments;
109
+ detailed(argv: string | string[], opts?: Options): DetailedArguments;
110
+ }
111
+ }
112
+
113
+ declare var yargsParser: yargsParser.Parser;
114
+ export = yargsParser;