@canyonjs/cli 1.0.25 → 1.0.27
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/dist/index.js +27 -9
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { program } from "commander";
|
|
3
|
-
import { log } from "node:console";
|
|
4
3
|
import node_fs from "node:fs";
|
|
5
4
|
import node_path from "node:path";
|
|
6
5
|
import axios from "axios";
|
|
7
6
|
var package_namespaceObject = {
|
|
8
|
-
rE: "1.0.
|
|
7
|
+
rE: "1.0.27"
|
|
9
8
|
};
|
|
10
9
|
function mergeNumberMaps(a = {}, b = {}) {
|
|
11
10
|
const result = {
|
|
@@ -61,9 +60,9 @@ function mergeCoverageMaps(target = {}, source = {}) {
|
|
|
61
60
|
return out;
|
|
62
61
|
}
|
|
63
62
|
async function mapCommand(params, options) {
|
|
64
|
-
log('Current working directory:', process.cwd());
|
|
65
|
-
const { dsn, repo_id: repoID, sha, provider, build_target, debug, instrument_cwd, filter } = params;
|
|
66
|
-
if (!node_fs.existsSync(node_path.resolve(process.cwd(), '.canyon_output'))) return void log('
|
|
63
|
+
console.log('Current working directory:', process.cwd());
|
|
64
|
+
const { dsn, repo_id: repoID, sha, provider, build_target, debug, instrument_cwd, filter, scene } = params;
|
|
65
|
+
if (!node_fs.existsSync(node_path.resolve(process.cwd(), '.canyon_output'))) return void console.log('No .canyon_output directory found, skipping upload.');
|
|
67
66
|
const files = node_fs.readdirSync(node_path.resolve(process.cwd(), '.canyon_output'));
|
|
68
67
|
let data = {};
|
|
69
68
|
for(let i = 0; i < files.length; i++){
|
|
@@ -82,6 +81,19 @@ async function mapCommand(params, options) {
|
|
|
82
81
|
const env_branch = process.env.CI_COMMIT_BRANCH;
|
|
83
82
|
const env_buildID = process.env.CI_JOB_ID;
|
|
84
83
|
const env_buildProvider = 'gitlab_runner';
|
|
84
|
+
let sceneMap;
|
|
85
|
+
if (scene && Array.isArray(scene)) {
|
|
86
|
+
sceneMap = {};
|
|
87
|
+
for (const pair of scene){
|
|
88
|
+
if ('string' != typeof pair) return void console.error(`Invalid scene parameter: ${pair}. Expected format: key=value`);
|
|
89
|
+
const equalIndex = pair.indexOf('=');
|
|
90
|
+
if (-1 === equalIndex || 0 === equalIndex) return void console.error(`Invalid scene parameter format: ${pair}. Expected format: key=value`);
|
|
91
|
+
const key = pair.substring(0, equalIndex);
|
|
92
|
+
const value = pair.substring(equalIndex + 1);
|
|
93
|
+
if (!key || !value) return void console.error(`Invalid scene parameter format: ${pair}. Key and value cannot be empty`);
|
|
94
|
+
sceneMap[key] = value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
85
97
|
const p = {
|
|
86
98
|
dsn,
|
|
87
99
|
provider: provider || 'gitlab',
|
|
@@ -96,17 +108,20 @@ async function mapCommand(params, options) {
|
|
|
96
108
|
buildProvider: env_buildProvider,
|
|
97
109
|
buildID: env_buildID,
|
|
98
110
|
branch: env_branch
|
|
111
|
+
},
|
|
112
|
+
...sceneMap && {
|
|
113
|
+
scene: sceneMap
|
|
99
114
|
}
|
|
100
115
|
};
|
|
101
|
-
if ('true' === debug) log(p);
|
|
116
|
+
if ('true' === debug) console.log(p);
|
|
102
117
|
await axios.post(dsn, {
|
|
103
118
|
...p,
|
|
104
119
|
coverage: data
|
|
105
120
|
}).then((r)=>{
|
|
106
|
-
log(JSON.stringify(r.data, null, 2));
|
|
121
|
+
console.log(JSON.stringify(r.data, null, 2));
|
|
107
122
|
return r;
|
|
108
123
|
}).catch((err)=>{
|
|
109
|
-
if (err?.response?.data) log(err?.response?.data);
|
|
124
|
+
if (err?.response?.data) console.log(err?.response?.data);
|
|
110
125
|
else String(err);
|
|
111
126
|
return err;
|
|
112
127
|
});
|
|
@@ -119,7 +134,10 @@ program.name('canyon').version(package_namespaceObject.rE, '-v, --version', 'see
|
|
|
119
134
|
subcommandTerm: (cmd)=>accent(cmd.name(), cmd.usage()),
|
|
120
135
|
argumentTerm: (arg)=>accent(arg.name())
|
|
121
136
|
}).showHelpAfterError(true);
|
|
122
|
-
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').
|
|
137
|
+
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 = [])=>{
|
|
138
|
+
previous.push(value);
|
|
139
|
+
return previous;
|
|
140
|
+
}, []).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));
|
|
123
141
|
const cli = async (args)=>{
|
|
124
142
|
try {
|
|
125
143
|
await program.parseAsync(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canyonjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@rslib/core": "^0.15.1",
|
|
21
21
|
"@rstest/core": "^0.5.1",
|
|
22
22
|
"@types/node": "^24.10.1",
|
|
23
|
-
"@typescript/native-preview": "
|
|
23
|
+
"@typescript/native-preview": "7.0.0-dev.20260119.1"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"axios": "^1.12.2",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rslib build",
|
|
32
|
-
"
|
|
33
|
-
"dev": "rslib build --watch"
|
|
32
|
+
"do-test": "npm run build && node ./bin/canyon.js upload --debug true --scene k1=v2 --scene k2=v3",
|
|
33
|
+
"dev-cli": "rslib build --watch"
|
|
34
34
|
}
|
|
35
35
|
}
|