@canyonjs/cli 1.0.32 → 1.0.33
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/canyon.js +1 -1
- package/dist/index.js +27 -27
- package/package.json +14 -14
package/bin/canyon.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import node_fs from "node:fs";
|
|
|
4
4
|
import node_path from "node:path";
|
|
5
5
|
import axios from "axios";
|
|
6
6
|
var package_namespaceObject = {
|
|
7
|
-
rE: "1.0.
|
|
7
|
+
rE: "1.0.33"
|
|
8
8
|
};
|
|
9
9
|
function mergeNumberMaps(a = {}, b = {}) {
|
|
10
10
|
const result = {
|
|
@@ -60,26 +60,26 @@ function mergeCoverageMaps(target = {}, source = {}) {
|
|
|
60
60
|
return out;
|
|
61
61
|
}
|
|
62
62
|
async function mapCommand(params, options) {
|
|
63
|
-
console.log(
|
|
64
|
-
const isGitHubActions =
|
|
63
|
+
console.log("Current working directory:", process.cwd());
|
|
64
|
+
const isGitHubActions = "true" === process.env.GITHUB_ACTIONS || !!process.env.GITHUB_EVENT_PATH;
|
|
65
65
|
let githubEvent;
|
|
66
66
|
if (isGitHubActions && process.env.GITHUB_EVENT_PATH) try {
|
|
67
|
-
if (node_fs.existsSync(process.env.GITHUB_EVENT_PATH)) githubEvent = node_fs.readFileSync(process.env.GITHUB_EVENT_PATH,
|
|
68
|
-
else console.log(
|
|
67
|
+
if (node_fs.existsSync(process.env.GITHUB_EVENT_PATH)) githubEvent = node_fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8");
|
|
68
|
+
else console.log("GITHUB_EVENT_PATH file not found:", process.env.GITHUB_EVENT_PATH);
|
|
69
69
|
} catch (error) {
|
|
70
|
-
console.warn(
|
|
70
|
+
console.warn("Failed to read GITHUB_EVENT_PATH:", error);
|
|
71
71
|
}
|
|
72
72
|
const { dsn, repo_id: repoID, sha, provider, build_target, debug, instrument_cwd, filter, scene } = params;
|
|
73
|
-
if (!node_fs.existsSync(node_path.resolve(process.cwd(),
|
|
74
|
-
const files = node_fs.readdirSync(node_path.resolve(process.cwd(),
|
|
73
|
+
if (!node_fs.existsSync(node_path.resolve(process.cwd(), ".canyon_output"))) return void console.log("No .canyon_output directory found, skipping upload.");
|
|
74
|
+
const files = node_fs.readdirSync(node_path.resolve(process.cwd(), ".canyon_output"));
|
|
75
75
|
let data = {};
|
|
76
76
|
for(let i = 0; i < files.length; i++){
|
|
77
77
|
const fileName = files[i];
|
|
78
78
|
const isCoverageFinalFile = /^coverage-final-.*\.json$/.test(fileName);
|
|
79
|
-
const fileCoverageString = node_fs.readFileSync(node_path.resolve(process.cwd(),
|
|
79
|
+
const fileCoverageString = node_fs.readFileSync(node_path.resolve(process.cwd(), ".canyon_output", fileName), "utf-8");
|
|
80
80
|
const fileCoverage = JSON.parse(fileCoverageString);
|
|
81
81
|
let toMerge = fileCoverage;
|
|
82
|
-
if (filter &&
|
|
82
|
+
if (filter && "string" == typeof filter && isCoverageFinalFile) {
|
|
83
83
|
const filteredEntries = Object.entries(fileCoverage).filter(([filePath])=>filePath.includes(filter));
|
|
84
84
|
if (0 === filteredEntries.length) continue;
|
|
85
85
|
toMerge = Object.fromEntries(filteredEntries);
|
|
@@ -88,11 +88,11 @@ async function mapCommand(params, options) {
|
|
|
88
88
|
}
|
|
89
89
|
const env_branch = process.env.CI_COMMIT_BRANCH;
|
|
90
90
|
const env_buildID = process.env.CI_JOB_ID;
|
|
91
|
-
const env_buildProvider =
|
|
91
|
+
const env_buildProvider = "gitlab_runner";
|
|
92
92
|
let diffData;
|
|
93
|
-
const diffJsonPath = node_path.resolve(process.cwd(),
|
|
93
|
+
const diffJsonPath = node_path.resolve(process.cwd(), "diff.json");
|
|
94
94
|
if (node_fs.existsSync(diffJsonPath)) try {
|
|
95
|
-
const diffJsonContent = node_fs.readFileSync(diffJsonPath,
|
|
95
|
+
const diffJsonContent = node_fs.readFileSync(diffJsonPath, "utf-8");
|
|
96
96
|
diffData = JSON.parse(diffJsonContent);
|
|
97
97
|
console.log(`Found diff.json file: ${diffJsonPath}`);
|
|
98
98
|
} catch (error) {
|
|
@@ -102,8 +102,8 @@ async function mapCommand(params, options) {
|
|
|
102
102
|
if (scene && Array.isArray(scene)) {
|
|
103
103
|
sceneMap = {};
|
|
104
104
|
for (const pair of scene){
|
|
105
|
-
if (
|
|
106
|
-
const equalIndex = pair.indexOf(
|
|
105
|
+
if ("string" != typeof pair) return void console.error(`Invalid scene parameter: ${pair}. Expected format: key=value`);
|
|
106
|
+
const equalIndex = pair.indexOf("=");
|
|
107
107
|
if (-1 === equalIndex || 0 === equalIndex) return void console.error(`Invalid scene parameter format: ${pair}. Expected format: key=value`);
|
|
108
108
|
const key = pair.substring(0, equalIndex);
|
|
109
109
|
const value = pair.substring(equalIndex + 1);
|
|
@@ -113,16 +113,16 @@ async function mapCommand(params, options) {
|
|
|
113
113
|
}
|
|
114
114
|
const p = {
|
|
115
115
|
dsn,
|
|
116
|
-
provider: provider ||
|
|
116
|
+
provider: provider || "gitlab",
|
|
117
117
|
repoID: repoID || process.env.CI_PROJECT_ID,
|
|
118
118
|
sha: sha || process.env.CI_COMMIT_SHA,
|
|
119
|
-
instrumentCwd: instrument_cwd ||
|
|
120
|
-
reportID:
|
|
121
|
-
reportProvider:
|
|
122
|
-
buildTarget: build_target ||
|
|
119
|
+
instrumentCwd: instrument_cwd || '',
|
|
120
|
+
reportID: "initial_coverage_data",
|
|
121
|
+
reportProvider: "ci",
|
|
122
|
+
buildTarget: build_target || "",
|
|
123
123
|
coverage: Object.keys(data),
|
|
124
124
|
build: {
|
|
125
|
-
provider: isGitHubActions ?
|
|
125
|
+
provider: isGitHubActions ? "github_actions" : env_buildProvider,
|
|
126
126
|
event: isGitHubActions ? githubEvent : void 0,
|
|
127
127
|
buildID: env_buildID,
|
|
128
128
|
branch: env_branch
|
|
@@ -134,7 +134,7 @@ async function mapCommand(params, options) {
|
|
|
134
134
|
diff: diffData
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
|
-
if (
|
|
137
|
+
if ("true" === debug) console.log(p);
|
|
138
138
|
await axios.post(dsn, {
|
|
139
139
|
...p,
|
|
140
140
|
coverage: data
|
|
@@ -148,17 +148,17 @@ async function mapCommand(params, options) {
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
const accent = chalk.greenBright;
|
|
151
|
-
const CLI_BEFORE_ALL_TXT = `canyon: The ${accent(
|
|
152
|
-
const CLI_AFTER_ALL_TXT = `\nFor more help, head on to ${accent(
|
|
153
|
-
program.name(
|
|
151
|
+
const CLI_BEFORE_ALL_TXT = `canyon: The ${accent("Canyon")} CLI - Version ${package_namespaceObject.rE} (${accent("https://github.com/canyon-project/canyon")}) ${chalk.black.bold.bgYellowBright(" ALPHA ")} \n`;
|
|
152
|
+
const CLI_AFTER_ALL_TXT = `\nFor more help, head on to ${accent("https://github.com/canyon-project/canyon")}`;
|
|
153
|
+
program.name("canyon").version(package_namespaceObject.rE, "-v, --version", "see the current version of canyon-uploader").usage("[options or commands] arguments").addHelpText("beforeAll", CLI_BEFORE_ALL_TXT).addHelpText("after", CLI_AFTER_ALL_TXT).configureHelp({
|
|
154
154
|
optionTerm: (option)=>accent(option.flags),
|
|
155
155
|
subcommandTerm: (cmd)=>accent(cmd.name(), cmd.usage()),
|
|
156
156
|
argumentTerm: (arg)=>accent(arg.name())
|
|
157
157
|
}).showHelpAfterError(true);
|
|
158
|
-
program.command(
|
|
158
|
+
program.command("upload").option("--debug <dsn>", "debug").option("--dsn <dsn>", "dsn of the canyon server").option("--repo_id <repo_id>", "repo id of the canyon server").option("--filter <filter>", "仅合并路径包含该子串的文件覆盖率").option("--instrument_cwd <instrument_cwd>", "instrument cwd of the canyon server").option("--sha <sha>", "sha of the canyon server").option("--branch <branch>", "branch of the canyon server").option("--provider <provider>", "provider of the canyon server").option("--build_target <build_target>", "build target of the canyon server").option("--coverage <coverage>", "coverage of the canyon server").option("--scene <key=value>", "scene key-value pair, can be used multiple times, e.g. --scene env=prod --scene type=e2e", (value, previous = [])=>{
|
|
159
159
|
previous.push(value);
|
|
160
160
|
return previous;
|
|
161
|
-
}, []).allowExcessArguments(false).allowUnknownOption(false).description(
|
|
161
|
+
}, []).allowExcessArguments(false).allowUnknownOption(false).description("modify react native project code to adapt to canyon").addHelpText("after", `\nFor help, head on to ${accent("https://github.com/canyon-project/canyon")}`).action(async (params, options)=>await mapCommand(params, options));
|
|
162
162
|
const cli = async (args)=>{
|
|
163
163
|
try {
|
|
164
164
|
await program.parseAsync(args);
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canyonjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
|
+
"bin": {
|
|
5
|
+
"canyon": "bin/canyon.js"
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"bin"
|
|
10
|
+
],
|
|
4
11
|
"type": "module",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
5
13
|
"exports": {
|
|
6
14
|
".": {
|
|
7
15
|
"types": "./dist/index.d.ts",
|
|
8
16
|
"import": "./dist/index.js"
|
|
9
17
|
}
|
|
10
18
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
],
|
|
16
|
-
"bin": {
|
|
17
|
-
"canyon": "bin/canyon.js"
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"axios": "^1.12.2",
|
|
21
|
+
"chalk": "^5.6.2",
|
|
22
|
+
"commander": "^14.0.1"
|
|
18
23
|
},
|
|
19
24
|
"devDependencies": {
|
|
20
25
|
"@rslib/core": "^0.15.1",
|
|
21
26
|
"@rstest/core": "^0.5.1",
|
|
22
27
|
"@types/node": "^24.10.1",
|
|
23
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"axios": "^1.12.2",
|
|
27
|
-
"chalk": "^5.6.2",
|
|
28
|
-
"commander": "^14.0.1"
|
|
28
|
+
"@typescript/native-preview": "7.0.0-dev.20260223.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rslib build",
|