@teams-max/mwsp 1.0.2 → 2.0.0
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/bin/mwsp.js +0 -29
- package/es/cli/build.d.ts +0 -1
- package/es/cli/build.js +69 -61
- package/es/cli/cli.js +4 -12
- package/es/cli/start.d.ts +0 -1
- package/es/cli/start.js +48 -26
- package/es/index.d.ts +2 -0
- package/es/index.js +3 -1
- package/es/utils/chalk/LICENSE +9 -0
- package/es/utils/chalk/index.d.ts +416 -0
- package/es/utils/chalk/index.js +1719 -0
- package/es/utils/chalk/package.json +1 -0
- package/es/{cli/update.js → utils/changelog.js} +41 -34
- package/es/{internal → utils}/datetimeFormat.js +1 -3
- package/es/utils/defineConfig.js +20 -0
- package/es/{internal → utils}/exec.js +3 -2
- package/es/utils/getPackages.js +9 -0
- package/es/{cli/dev.js → utils/git.js} +88 -36
- package/es/{internal/buildNotify.js → utils/index.js} +220 -97
- package/es/utils/isNextVersion.js +3 -0
- package/es/utils/parseDoc.js +33 -0
- package/es/utils/yargs-parser/index.d.ts +112 -0
- package/es/utils/yargs-parser/index.js +919 -0
- package/es/utils/yargs-parser/package.json +1 -0
- package/lib/cli/build.d.ts +0 -1
- package/lib/cli/build.js +54 -50
- package/lib/cli/cli.js +0 -8
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +25 -30
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/utils/chalk/LICENSE +9 -0
- package/lib/utils/chalk/index.d.ts +416 -0
- package/lib/utils/chalk/index.js +1495 -0
- package/lib/utils/chalk/package.json +1 -0
- package/lib/utils/changelog.js +21 -0
- package/lib/{internal → utils}/cross-spawn/index.js +1 -1
- package/lib/{internal → utils}/datetimeFormat.js +10 -29
- package/lib/utils/defineConfig.js +19 -0
- package/lib/utils/exec.js +23 -0
- package/lib/{internal → utils}/execa/index.js +1 -1
- package/lib/utils/getPackages.js +6 -0
- package/lib/utils/git.js +23 -0
- package/lib/utils/index.js +159 -0
- package/lib/utils/isNextVersion.js +4 -0
- package/lib/{internal → utils}/merge-stream/index.js +1 -1
- package/lib/utils/parseDoc.js +30 -0
- package/lib/utils/yargs-parser/index.d.ts +112 -0
- package/lib/utils/yargs-parser/index.js +905 -0
- package/lib/utils/yargs-parser/package.json +1 -0
- package/package.json +4 -11
- package/es/cli/dev.d.ts +0 -1
- package/es/cli/update.d.ts +0 -2
- package/es/internal/buildNotify.d.ts +0 -10
- package/es/internal/datetimeFormat.d.ts +0 -9
- package/es/internal/exec.d.ts +0 -1
- package/es/internal/utils.d.ts +0 -14
- package/es/internal/utils.js +0 -90
- package/lib/cli/dev.d.ts +0 -1
- package/lib/cli/dev.js +0 -62
- package/lib/cli/update.d.ts +0 -2
- package/lib/cli/update.js +0 -50
- package/lib/internal/buildNotify.d.ts +0 -10
- package/lib/internal/buildNotify.js +0 -112
- package/lib/internal/datetimeFormat.d.ts +0 -9
- package/lib/internal/exec.d.ts +0 -1
- package/lib/internal/exec.js +0 -60
- package/lib/internal/utils.d.ts +0 -14
- package/lib/internal/utils.js +0 -100
- /package/es/{internal → utils}/cross-spawn/LICENSE +0 -0
- /package/es/{internal → utils}/cross-spawn/index.d.ts +0 -0
- /package/es/{internal → utils}/cross-spawn/index.js +0 -0
- /package/es/{internal → utils}/cross-spawn/package.json +0 -0
- /package/es/{internal → utils}/execa/LICENSE +0 -0
- /package/es/{internal → utils}/execa/index.d.ts +0 -0
- /package/es/{internal → utils}/execa/index.js +0 -0
- /package/es/{internal → utils}/execa/package.json +0 -0
- /package/es/{internal → utils}/merge-stream/LICENSE +0 -0
- /package/es/{internal → utils}/merge-stream/index.d.ts +0 -0
- /package/es/{internal → utils}/merge-stream/index.js +0 -0
- /package/es/{internal → utils}/merge-stream/package.json +0 -0
- /package/lib/{internal → utils}/cross-spawn/LICENSE +0 -0
- /package/lib/{internal → utils}/cross-spawn/index.d.ts +0 -0
- /package/lib/{internal → utils}/cross-spawn/package.json +0 -0
- /package/lib/{internal → utils}/execa/LICENSE +0 -0
- /package/lib/{internal → utils}/execa/index.d.ts +0 -0
- /package/lib/{internal → utils}/execa/package.json +0 -0
- /package/lib/{internal → utils}/merge-stream/LICENSE +0 -0
- /package/lib/{internal → utils}/merge-stream/index.d.ts +0 -0
- /package/lib/{internal → utils}/merge-stream/package.json +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"chalk","main":"index.js","license":"MIT","types":"index.d.ts"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/utils/changelog.js
|
|
2
|
+
var { htmlEscape } = require("escape-goat");
|
|
3
|
+
var git = require("./git");
|
|
4
|
+
exports.getChangelog = async () => {
|
|
5
|
+
const repoUrl = "https://v.src.corp.qihoo.net/it_informatization/pro-teams";
|
|
6
|
+
const latest = await git.latestTagOrFirstCommit();
|
|
7
|
+
const log = await git.commitLogFromRevision(latest);
|
|
8
|
+
if (!log) {
|
|
9
|
+
throw new Error(`get changelog failed, no new commits was found.`);
|
|
10
|
+
}
|
|
11
|
+
const commits = log.split("\n").map((commit) => {
|
|
12
|
+
const splitIndex = commit.lastIndexOf(" ");
|
|
13
|
+
return {
|
|
14
|
+
message: commit.slice(0, splitIndex),
|
|
15
|
+
id: commit.slice(splitIndex + 1)
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
return (nextTag) => commits.map((commit) => `- ${htmlEscape(commit.message)} ${commit.id}`).join("\n") + `
|
|
19
|
+
|
|
20
|
+
${repoUrl}/compare/${latest}...${nextTag}`;
|
|
21
|
+
};
|
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/internal/datetimeFormat.ts
|
|
20
|
-
var datetimeFormat_exports = {};
|
|
21
|
-
__export(datetimeFormat_exports, {
|
|
22
|
-
default: () => datetimeFormat_default
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(datetimeFormat_exports);
|
|
1
|
+
// src/utils/datetimeFormat.js
|
|
25
2
|
function isValidDate(value) {
|
|
26
3
|
const date = new Date(value);
|
|
27
4
|
return date instanceof Date && !isNaN(date.valueOf());
|
|
@@ -92,15 +69,19 @@ function datetimeFormat(value, format, isCoerce) {
|
|
|
92
69
|
6: "\u516D"
|
|
93
70
|
};
|
|
94
71
|
if (/(E+)/.test(format)) {
|
|
95
|
-
format = format.replace(
|
|
72
|
+
format = format.replace(
|
|
73
|
+
RegExp.$1,
|
|
74
|
+
(RegExp.$1.length > 1 ? RegExp.$1.length > 2 ? "\u661F\u671F" : "\u5468" : "") + week[date.getDay() + ""]
|
|
75
|
+
);
|
|
96
76
|
}
|
|
97
77
|
for (const k in o) {
|
|
98
78
|
if (new RegExp("(" + k + ")").test(format)) {
|
|
99
|
-
format = format.replace(
|
|
79
|
+
format = format.replace(
|
|
80
|
+
RegExp.$1,
|
|
81
|
+
RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
|
|
82
|
+
);
|
|
100
83
|
}
|
|
101
84
|
}
|
|
102
85
|
return format;
|
|
103
86
|
}
|
|
104
|
-
|
|
105
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
-
0 && (module.exports = {});
|
|
87
|
+
module.exports = datetimeFormat;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/utils/defineConfig.js
|
|
2
|
+
var path = require("path");
|
|
3
|
+
var { logStep, printErrorAndExit } = require("./index");
|
|
4
|
+
function defineConfig(config) {
|
|
5
|
+
if (!process.env.ASG_DIR) {
|
|
6
|
+
logStep("The Asgard directory does not exist, using default config...");
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
let iConfigFromPlugins = null;
|
|
10
|
+
try {
|
|
11
|
+
iConfigFromPlugins = require(path.join(process.env.ASG_DIR, "base", "pluginConfig.js"));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
printErrorAndExit("The Asgard directory does not exist.", `Reason: ${error.message}`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
logStep("The Asgard directory exists, using config from plugins...");
|
|
17
|
+
return iConfigFromPlugins(config);
|
|
18
|
+
}
|
|
19
|
+
module.exports = defineConfig;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/utils/exec.js
|
|
2
|
+
var { spawn } = require("child_process");
|
|
3
|
+
module.exports = function exec(command, args, opts) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const child = spawn(command, args, {
|
|
6
|
+
shell: true,
|
|
7
|
+
stdio: "inherit",
|
|
8
|
+
env: process.env,
|
|
9
|
+
...opts
|
|
10
|
+
});
|
|
11
|
+
child.once("error", (err) => {
|
|
12
|
+
console.log(err);
|
|
13
|
+
reject(err);
|
|
14
|
+
});
|
|
15
|
+
child.once("close", (code) => {
|
|
16
|
+
if (code === 1) {
|
|
17
|
+
process.exit(1);
|
|
18
|
+
} else {
|
|
19
|
+
resolve();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
};
|
package/lib/utils/git.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/utils/git.js
|
|
2
|
+
var { execa, chalk, yParser } = require("./index");
|
|
3
|
+
exports.latestTag = async () => {
|
|
4
|
+
const { stdout } = await execa("git", ["describe", "--abbrev=0", "--tags"]);
|
|
5
|
+
return stdout;
|
|
6
|
+
};
|
|
7
|
+
var firstCommit = async () => {
|
|
8
|
+
const { stdout } = await execa("git", ["rev-list", "--max-parents=0", "HEAD"]);
|
|
9
|
+
return stdout;
|
|
10
|
+
};
|
|
11
|
+
exports.latestTagOrFirstCommit = async () => {
|
|
12
|
+
let latest;
|
|
13
|
+
try {
|
|
14
|
+
latest = await exports.latestTag();
|
|
15
|
+
} catch (_) {
|
|
16
|
+
latest = await firstCommit();
|
|
17
|
+
}
|
|
18
|
+
return latest;
|
|
19
|
+
};
|
|
20
|
+
exports.commitLogFromRevision = async (revision) => {
|
|
21
|
+
const { stdout } = await execa("git", ["log", "--format=%s %h", `${revision}..HEAD`]);
|
|
22
|
+
return stdout;
|
|
23
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
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 getCfg() {
|
|
26
|
+
const pkgs = require(join(cwd, "package.json"));
|
|
27
|
+
const { infra = {}, appKey } = pkgs;
|
|
28
|
+
if (!(infra == null ? void 0 : infra.url) || !appKey) {
|
|
29
|
+
printErrorAndExit("Please check the infra and appKey in package.json.");
|
|
30
|
+
}
|
|
31
|
+
const args = yParser(process.argv.slice(2));
|
|
32
|
+
const JENKINS_BUILD = args.jenkinsBuild || args.JENKINSBUILD || args.jenkins_build || args.JENKINS_BUILD;
|
|
33
|
+
const APP_ENV = args.env || args.ENV || "";
|
|
34
|
+
const ASG_BRAHCH = args.asg_branch || args.ASG_BRAHCH || "";
|
|
35
|
+
let RESOURCE_URL = "";
|
|
36
|
+
let SUB_APP = "";
|
|
37
|
+
let archStr = "unknown";
|
|
38
|
+
if (infra.url.includes("teams-pro")) {
|
|
39
|
+
archStr = "PRO";
|
|
40
|
+
} else if (infra.url.includes("teams-max")) {
|
|
41
|
+
archStr = "MAX";
|
|
42
|
+
RESOURCE_URL = args.versionUrl || args.RESOURCE_URL || "";
|
|
43
|
+
SUB_APP = args.subApp || args.SUB_APP || "";
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
appKey,
|
|
47
|
+
infra: {
|
|
48
|
+
url: infra.url,
|
|
49
|
+
arch: archStr
|
|
50
|
+
},
|
|
51
|
+
ASG_DIR: asgDir,
|
|
52
|
+
JENKINS_BUILD,
|
|
53
|
+
ASG_BRAHCH,
|
|
54
|
+
APP_ENV,
|
|
55
|
+
RESOURCE_URL,
|
|
56
|
+
SUB_APP
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function checkDirectoryExistsSync(dirPath) {
|
|
60
|
+
try {
|
|
61
|
+
const stats = fs.statSync(dirPath);
|
|
62
|
+
return stats.isDirectory();
|
|
63
|
+
} catch (err) {
|
|
64
|
+
if (err.code === "ENOENT") {
|
|
65
|
+
return false;
|
|
66
|
+
} else {
|
|
67
|
+
printErrorAndExit(err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function fetchRemoteRepository() {
|
|
72
|
+
const cfg = getCfg();
|
|
73
|
+
const { infra, ASG_DIR: directory, ASG_BRAHCH, JENKINS_BUILD } = cfg;
|
|
74
|
+
const remoteUrl = infra.url;
|
|
75
|
+
const doesExist = checkDirectoryExistsSync(directory);
|
|
76
|
+
if (!doesExist) {
|
|
77
|
+
logStep("Cloning the repository from GitHub...");
|
|
78
|
+
execa.sync("git", ["clone", "-b", "feature-asg", remoteUrl, directory]);
|
|
79
|
+
logStep("Cloning completed.");
|
|
80
|
+
logStep("Installing dependencies...");
|
|
81
|
+
if ((infra == null ? void 0 : infra.arch) === "PRO") {
|
|
82
|
+
await exec("yarn", ["add", "snb-mock-middleware", "lodash-webpack-plugin", "-D"]);
|
|
83
|
+
await exec("yarn", ["add", "@teams-max/skynet", "history"]);
|
|
84
|
+
} else if ((infra == null ? void 0 : infra.arch) === "MAX") {
|
|
85
|
+
await exec("pnpm", ["add", "axios", "-D"]);
|
|
86
|
+
await exec("pnpm", ["add", "@teams-max/skynet", "classnames", "qs", "uuid", "react-draggable"]);
|
|
87
|
+
}
|
|
88
|
+
logStep("Installation completed.");
|
|
89
|
+
} else if (JENKINS_BUILD && !ASG_BRAHCH) {
|
|
90
|
+
logStep("Jenkins build detected. Skipping sync up.");
|
|
91
|
+
return;
|
|
92
|
+
} else {
|
|
93
|
+
const { syncUp } = await inquirer.prompt([
|
|
94
|
+
{
|
|
95
|
+
type: "confirm",
|
|
96
|
+
name: "syncUp",
|
|
97
|
+
message: "\u540C\u6B65\u8FDC\u7AEF\u4ED3\u5E93",
|
|
98
|
+
default: "Y"
|
|
99
|
+
}
|
|
100
|
+
]);
|
|
101
|
+
if (!syncUp)
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!doesExist && JENKINS_BUILD && !ASG_BRAHCH) {
|
|
105
|
+
printErrorAndExit("Jenkins build detected. The branch parameter is missing!");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
logStep("Synchronizing with the remote repository...");
|
|
109
|
+
process.chdir(directory);
|
|
110
|
+
try {
|
|
111
|
+
execa.sync("git", ["pull", "origin", "master"]);
|
|
112
|
+
if (JENKINS_BUILD && ASG_BRAHCH) {
|
|
113
|
+
execa.sync("git", ["checkout", ASG_BRAHCH]);
|
|
114
|
+
logStep(`Anto switched to branch:`, ASG_BRAHCH);
|
|
115
|
+
} else {
|
|
116
|
+
const infraBranchsOutput = execa.sync("git", ["branch", "-r"]).stdout;
|
|
117
|
+
const infraBranchArray = infraBranchsOutput.trim().split("\n");
|
|
118
|
+
const filteredBranches = infraBranchArray.map((b) => b.trim()).filter((b) => !(b.startsWith("origin/HEA") || b.startsWith("origin/app-") || b.startsWith("app-")));
|
|
119
|
+
const defaultBrancheIdx = filteredBranches.indexOf("origin/feature-asg");
|
|
120
|
+
if (defaultBrancheIdx !== -1) {
|
|
121
|
+
filteredBranches.splice(defaultBrancheIdx, 1);
|
|
122
|
+
filteredBranches.unshift("origin/feature-asg");
|
|
123
|
+
}
|
|
124
|
+
if (filteredBranches.length === 0) {
|
|
125
|
+
printErrorAndExit("No branches available for selection.");
|
|
126
|
+
}
|
|
127
|
+
const questions = await inquirer.prompt([
|
|
128
|
+
{
|
|
129
|
+
type: "list",
|
|
130
|
+
name: "branch",
|
|
131
|
+
message: "Please select the branch first: ",
|
|
132
|
+
choices: filteredBranches,
|
|
133
|
+
validate: function(val) {
|
|
134
|
+
if (!val || !val.length) {
|
|
135
|
+
return "Please select a branch!";
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]);
|
|
141
|
+
try {
|
|
142
|
+
execa.sync("git", ["checkout", "-q", questions.branch]);
|
|
143
|
+
logStep(`Switched to branch:`, questions.branch);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
printErrorAndExit(`Failed to switch to branch '${questions.branch}'. Reason: ${error.message}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
printErrorAndExit(`An error occurred while fetching remote branches: ${error.message}`);
|
|
150
|
+
}
|
|
151
|
+
process.chdir(cwd);
|
|
152
|
+
}
|
|
153
|
+
module.exports.yParser = yParser;
|
|
154
|
+
module.exports.execa = execa;
|
|
155
|
+
module.exports.chalk = chalk;
|
|
156
|
+
module.exports.logStep = logStep;
|
|
157
|
+
module.exports.printErrorAndExit = printErrorAndExit;
|
|
158
|
+
module.exports.getCfg = getCfg;
|
|
159
|
+
module.exports.fetchRemoteRepository = fetchRemoteRepository;
|
|
@@ -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,112 @@
|
|
|
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?: string[] | Array<{ key: string; boolean?: boolean; number?: boolean }>;
|
|
78
|
+
/** Arguments should be parsed as booleans: `{ boolean: ['x', 'y'] }`. */
|
|
79
|
+
boolean?: string[];
|
|
80
|
+
/** Indicate a key that represents a path to a configuration file (this file will be loaded and parsed). */
|
|
81
|
+
config?: string | string[] | { [key: string]: boolean };
|
|
82
|
+
/** Provide configuration options to the yargs-parser. */
|
|
83
|
+
configuration?: Partial<Configuration>;
|
|
84
|
+
/**
|
|
85
|
+
* Provide a custom synchronous function that returns a coerced value from the argument provided (or throws an error), e.g.
|
|
86
|
+
* `{ coerce: { foo: function (arg) { return modifiedArg } } }`.
|
|
87
|
+
*/
|
|
88
|
+
coerce?: { [key: string]: (arg: any) => any };
|
|
89
|
+
/** Indicate a key that should be used as a counter, e.g., `-vvv = {v: 3}`. */
|
|
90
|
+
count?: string[];
|
|
91
|
+
/** Provide default values for keys: `{ default: { x: 33, y: 'hello world!' } }`. */
|
|
92
|
+
default?: { [key: string]: any };
|
|
93
|
+
/** Environment variables (`process.env`) with the prefix provided should be parsed. */
|
|
94
|
+
envPrefix?: string;
|
|
95
|
+
/** Specify that a key requires n arguments: `{ narg: {x: 2} }`. */
|
|
96
|
+
narg?: { [key: string]: number };
|
|
97
|
+
/** `path.normalize()` will be applied to values set to this key. */
|
|
98
|
+
normalize?: string[];
|
|
99
|
+
/** Keys should be treated as strings (even if they resemble a number `-x 33`). */
|
|
100
|
+
string?: string[];
|
|
101
|
+
/** Keys should be treated as numbers. */
|
|
102
|
+
number?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface Parser {
|
|
106
|
+
(argv: string | string[], opts?: Options): Arguments;
|
|
107
|
+
detailed(argv: string | string[], opts?: Options): DetailedArguments;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare var yargsParser: yargsParser.Parser;
|
|
112
|
+
export = yargsParser;
|