@legna-lnc/legnacode 1.5.3 → 1.5.4
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/CHANGELOG.md +727 -723
- package/README.md +386 -385
- package/README.zh-CN.md +363 -362
- package/npm/bin/legna.cjs +117 -117
- package/npm/postinstall.cjs +82 -82
- package/package.json +154 -154
package/npm/bin/legna.cjs
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var os = require("os");
|
|
5
|
-
var path = require("path");
|
|
6
|
-
var fs = require("fs");
|
|
7
|
-
var childProcess = require("child_process");
|
|
8
|
-
|
|
9
|
-
var PLATFORMS = {
|
|
10
|
-
"darwin-arm64": "@legna-lnc/legnacode-darwin-arm64",
|
|
11
|
-
"darwin-x64": "@legna-lnc/legnacode-darwin-x64",
|
|
12
|
-
"linux-x64": "@legna-lnc/legnacode-linux-x64",
|
|
13
|
-
"linux-arm64": "@legna-lnc/legnacode-linux-arm64",
|
|
14
|
-
"win32-x64": "@legna-lnc/legnacode-win32-x64",
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
var key = process.platform + "-" + os.arch();
|
|
18
|
-
var pkg = PLATFORMS[key];
|
|
19
|
-
|
|
20
|
-
if (!pkg) {
|
|
21
|
-
console.error("legna: unsupported platform " + key);
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var binName = process.platform === "win32" ? "legna.exe" : "bin/legna";
|
|
26
|
-
|
|
27
|
-
function findBin() {
|
|
28
|
-
var candidates = [];
|
|
29
|
-
|
|
30
|
-
// Strategy 1: require.resolve
|
|
31
|
-
try {
|
|
32
|
-
var p = path.resolve(require.resolve(pkg + "/package.json"), "..", binName);
|
|
33
|
-
candidates.push(p);
|
|
34
|
-
if (fs.existsSync(p)) return p;
|
|
35
|
-
} catch (e) {}
|
|
36
|
-
|
|
37
|
-
// Strategy 2: sibling scope dir (global flat layout)
|
|
38
|
-
// __dirname = .../node_modules/@legna-lnc/legnacode/npm/bin
|
|
39
|
-
// go up to @legna-lnc scope dir, then into sibling package
|
|
40
|
-
var scopeDir = path.resolve(__dirname, "..", "..", "..");
|
|
41
|
-
var pkgName = pkg.split("/")[1];
|
|
42
|
-
var flat = path.resolve(scopeDir, pkgName, binName);
|
|
43
|
-
candidates.push(flat);
|
|
44
|
-
if (fs.existsSync(flat)) return flat;
|
|
45
|
-
|
|
46
|
-
// Strategy 3: nested node_modules (postinstall --no-save)
|
|
47
|
-
var nested = path.resolve(__dirname, "..", "..", "node_modules", pkg, binName);
|
|
48
|
-
candidates.push(nested);
|
|
49
|
-
if (fs.existsSync(nested)) return nested;
|
|
50
|
-
|
|
51
|
-
// Strategy 4: global prefix
|
|
52
|
-
try {
|
|
53
|
-
var prefix = childProcess.execSync("npm prefix -g", { encoding: "utf-8" }).trim();
|
|
54
|
-
var globalPaths = [
|
|
55
|
-
path.join(prefix, "node_modules", pkg, binName),
|
|
56
|
-
path.join(prefix, "lib", "node_modules", pkg, binName),
|
|
57
|
-
];
|
|
58
|
-
for (var gp of globalPaths) {
|
|
59
|
-
candidates.push(gp);
|
|
60
|
-
if (fs.existsSync(gp)) return gp;
|
|
61
|
-
}
|
|
62
|
-
} catch (e) {}
|
|
63
|
-
|
|
64
|
-
// Debug: print all searched paths
|
|
65
|
-
if (process.env.LEGNA_DEBUG) {
|
|
66
|
-
console.error("legna: searched paths:");
|
|
67
|
-
candidates.forEach(function(c) {
|
|
68
|
-
console.error(" " + (fs.existsSync(c) ? "[OK]" : "[ ]") + " " + c);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
var bin = findBin();
|
|
76
|
-
|
|
77
|
-
if (!bin) {
|
|
78
|
-
// Last resort: try to install from official registry
|
|
79
|
-
var version;
|
|
80
|
-
try {
|
|
81
|
-
version = JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "..", "package.json"), "utf-8")).version;
|
|
82
|
-
} catch (e) { version = "latest"; }
|
|
83
|
-
|
|
84
|
-
console.error("legna: installing platform binary " + pkg + "@" + version + "...");
|
|
85
|
-
var install = childProcess.spawnSync(
|
|
86
|
-
"npm", ["install", "-g", pkg + "@" + version, "--registry", "https://registry.npmjs.org"],
|
|
87
|
-
{ stdio: "inherit", shell: true }
|
|
88
|
-
);
|
|
89
|
-
if (install.status === 0) bin = findBin();
|
|
90
|
-
|
|
91
|
-
if (!bin) {
|
|
92
|
-
console.error("legna: platform binary not found after install attempt.");
|
|
93
|
-
console.error("Try: npm install -g " + pkg + " --registry https://registry.npmjs.org");
|
|
94
|
-
console.error("Debug: set LEGNA_DEBUG=1 and run again to see searched paths.");
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var result = childProcess.spawnSync(bin, process.argv.slice(2), {
|
|
100
|
-
stdio: "inherit",
|
|
101
|
-
env: process.env,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
if (result.error) {
|
|
105
|
-
if (result.error.code === "EACCES") {
|
|
106
|
-
fs.chmodSync(bin, 0o755);
|
|
107
|
-
result = childProcess.spawnSync(bin, process.argv.slice(2), {
|
|
108
|
-
stdio: "inherit",
|
|
109
|
-
env: process.env,
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
console.error("legna: spawn error: " + result.error.message);
|
|
113
|
-
process.exit(1);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
process.exit(result.status === null ? 1 : result.status);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var os = require("os");
|
|
5
|
+
var path = require("path");
|
|
6
|
+
var fs = require("fs");
|
|
7
|
+
var childProcess = require("child_process");
|
|
8
|
+
|
|
9
|
+
var PLATFORMS = {
|
|
10
|
+
"darwin-arm64": "@legna-lnc/legnacode-darwin-arm64",
|
|
11
|
+
"darwin-x64": "@legna-lnc/legnacode-darwin-x64",
|
|
12
|
+
"linux-x64": "@legna-lnc/legnacode-linux-x64",
|
|
13
|
+
"linux-arm64": "@legna-lnc/legnacode-linux-arm64",
|
|
14
|
+
"win32-x64": "@legna-lnc/legnacode-win32-x64",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var key = process.platform + "-" + os.arch();
|
|
18
|
+
var pkg = PLATFORMS[key];
|
|
19
|
+
|
|
20
|
+
if (!pkg) {
|
|
21
|
+
console.error("legna: unsupported platform " + key);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var binName = process.platform === "win32" ? "legna.exe" : "bin/legna";
|
|
26
|
+
|
|
27
|
+
function findBin() {
|
|
28
|
+
var candidates = [];
|
|
29
|
+
|
|
30
|
+
// Strategy 1: require.resolve
|
|
31
|
+
try {
|
|
32
|
+
var p = path.resolve(require.resolve(pkg + "/package.json"), "..", binName);
|
|
33
|
+
candidates.push(p);
|
|
34
|
+
if (fs.existsSync(p)) return p;
|
|
35
|
+
} catch (e) {}
|
|
36
|
+
|
|
37
|
+
// Strategy 2: sibling scope dir (global flat layout)
|
|
38
|
+
// __dirname = .../node_modules/@legna-lnc/legnacode/npm/bin
|
|
39
|
+
// go up to @legna-lnc scope dir, then into sibling package
|
|
40
|
+
var scopeDir = path.resolve(__dirname, "..", "..", "..");
|
|
41
|
+
var pkgName = pkg.split("/")[1];
|
|
42
|
+
var flat = path.resolve(scopeDir, pkgName, binName);
|
|
43
|
+
candidates.push(flat);
|
|
44
|
+
if (fs.existsSync(flat)) return flat;
|
|
45
|
+
|
|
46
|
+
// Strategy 3: nested node_modules (postinstall --no-save)
|
|
47
|
+
var nested = path.resolve(__dirname, "..", "..", "node_modules", pkg, binName);
|
|
48
|
+
candidates.push(nested);
|
|
49
|
+
if (fs.existsSync(nested)) return nested;
|
|
50
|
+
|
|
51
|
+
// Strategy 4: global prefix
|
|
52
|
+
try {
|
|
53
|
+
var prefix = childProcess.execSync("npm prefix -g", { encoding: "utf-8" }).trim();
|
|
54
|
+
var globalPaths = [
|
|
55
|
+
path.join(prefix, "node_modules", pkg, binName),
|
|
56
|
+
path.join(prefix, "lib", "node_modules", pkg, binName),
|
|
57
|
+
];
|
|
58
|
+
for (var gp of globalPaths) {
|
|
59
|
+
candidates.push(gp);
|
|
60
|
+
if (fs.existsSync(gp)) return gp;
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {}
|
|
63
|
+
|
|
64
|
+
// Debug: print all searched paths
|
|
65
|
+
if (process.env.LEGNA_DEBUG) {
|
|
66
|
+
console.error("legna: searched paths:");
|
|
67
|
+
candidates.forEach(function(c) {
|
|
68
|
+
console.error(" " + (fs.existsSync(c) ? "[OK]" : "[ ]") + " " + c);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var bin = findBin();
|
|
76
|
+
|
|
77
|
+
if (!bin) {
|
|
78
|
+
// Last resort: try to install from official registry
|
|
79
|
+
var version;
|
|
80
|
+
try {
|
|
81
|
+
version = JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "..", "package.json"), "utf-8")).version;
|
|
82
|
+
} catch (e) { version = "latest"; }
|
|
83
|
+
|
|
84
|
+
console.error("legna: installing platform binary " + pkg + "@" + version + "...");
|
|
85
|
+
var install = childProcess.spawnSync(
|
|
86
|
+
"npm", ["install", "-g", pkg + "@" + version, "--registry", "https://registry.npmjs.org"],
|
|
87
|
+
{ stdio: "inherit", shell: true }
|
|
88
|
+
);
|
|
89
|
+
if (install.status === 0) bin = findBin();
|
|
90
|
+
|
|
91
|
+
if (!bin) {
|
|
92
|
+
console.error("legna: platform binary not found after install attempt.");
|
|
93
|
+
console.error("Try: npm install -g " + pkg + " --registry https://registry.npmjs.org");
|
|
94
|
+
console.error("Debug: set LEGNA_DEBUG=1 and run again to see searched paths.");
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
var result = childProcess.spawnSync(bin, process.argv.slice(2), {
|
|
100
|
+
stdio: "inherit",
|
|
101
|
+
env: process.env,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (result.error) {
|
|
105
|
+
if (result.error.code === "EACCES") {
|
|
106
|
+
fs.chmodSync(bin, 0o755);
|
|
107
|
+
result = childProcess.spawnSync(bin, process.argv.slice(2), {
|
|
108
|
+
stdio: "inherit",
|
|
109
|
+
env: process.env,
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
console.error("legna: spawn error: " + result.error.message);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
process.exit(result.status === null ? 1 : result.status);
|
package/npm/postinstall.cjs
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* postinstall: ensure the correct platform binary package is installed.
|
|
6
|
-
* npm's optionalDependencies with os/cpu filters often fails on Windows
|
|
7
|
-
* and with non-standard registries. This script fixes that.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var os = require("os");
|
|
11
|
-
var path = require("path");
|
|
12
|
-
var fs = require("fs");
|
|
13
|
-
var childProcess = require("child_process");
|
|
14
|
-
|
|
15
|
-
var PLATFORMS = {
|
|
16
|
-
"darwin-arm64": "@legna-lnc/legnacode-darwin-arm64",
|
|
17
|
-
"darwin-x64": "@legna-lnc/legnacode-darwin-x64",
|
|
18
|
-
"linux-x64": "@legna-lnc/legnacode-linux-x64",
|
|
19
|
-
"linux-arm64": "@legna-lnc/legnacode-linux-arm64",
|
|
20
|
-
"win32-x64": "@legna-lnc/legnacode-win32-x64",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
var key = process.platform + "-" + os.arch();
|
|
24
|
-
var pkg = PLATFORMS[key];
|
|
25
|
-
if (!pkg) process.exit(0); // unsupported platform, skip silently
|
|
26
|
-
|
|
27
|
-
var binName = process.platform === "win32" ? "legna.exe" : "bin/legna";
|
|
28
|
-
|
|
29
|
-
// Check if platform package is already available
|
|
30
|
-
function isInstalled() {
|
|
31
|
-
try {
|
|
32
|
-
var p = path.resolve(require.resolve(pkg + "/package.json"), "..", binName);
|
|
33
|
-
if (fs.existsSync(p)) return true;
|
|
34
|
-
} catch (e) {}
|
|
35
|
-
|
|
36
|
-
// Check sibling in global/local node_modules
|
|
37
|
-
var scopeDir = path.resolve(__dirname, "..", "..");
|
|
38
|
-
var pkgName = pkg.split("/")[1];
|
|
39
|
-
if (fs.existsSync(path.resolve(scopeDir, pkgName, binName))) return true;
|
|
40
|
-
|
|
41
|
-
// Check nested
|
|
42
|
-
var nested = path.resolve(__dirname, "..", "node_modules", pkg, binName);
|
|
43
|
-
if (fs.existsSync(nested)) return true;
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (isInstalled()) process.exit(0);
|
|
49
|
-
|
|
50
|
-
// Not installed — fetch it from official npm registry
|
|
51
|
-
var version;
|
|
52
|
-
try {
|
|
53
|
-
version = JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "package.json"), "utf-8")).version;
|
|
54
|
-
} catch (e) {
|
|
55
|
-
version = "latest";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log("Installing platform binary " + pkg + "@" + version + "...");
|
|
59
|
-
|
|
60
|
-
// Use official registry to avoid mirror sync delays
|
|
61
|
-
var result = childProcess.spawnSync(
|
|
62
|
-
"npm",
|
|
63
|
-
["install", "--no-save", pkg + "@" + version, "--registry", "https://registry.npmjs.org"],
|
|
64
|
-
{
|
|
65
|
-
cwd: path.resolve(__dirname, ".."),
|
|
66
|
-
stdio: "inherit",
|
|
67
|
-
shell: true,
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
if (result.status !== 0) {
|
|
72
|
-
// Try global install as fallback
|
|
73
|
-
var result2 = childProcess.spawnSync(
|
|
74
|
-
"npm",
|
|
75
|
-
["install", "-g", pkg + "@" + version, "--registry", "https://registry.npmjs.org"],
|
|
76
|
-
{ stdio: "inherit", shell: true }
|
|
77
|
-
);
|
|
78
|
-
if (result2.status !== 0) {
|
|
79
|
-
console.error("Warning: could not install " + pkg + ". Run manually:");
|
|
80
|
-
console.error(" npm install -g " + pkg + "@" + version + " --registry https://registry.npmjs.org");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* postinstall: ensure the correct platform binary package is installed.
|
|
6
|
+
* npm's optionalDependencies with os/cpu filters often fails on Windows
|
|
7
|
+
* and with non-standard registries. This script fixes that.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var os = require("os");
|
|
11
|
+
var path = require("path");
|
|
12
|
+
var fs = require("fs");
|
|
13
|
+
var childProcess = require("child_process");
|
|
14
|
+
|
|
15
|
+
var PLATFORMS = {
|
|
16
|
+
"darwin-arm64": "@legna-lnc/legnacode-darwin-arm64",
|
|
17
|
+
"darwin-x64": "@legna-lnc/legnacode-darwin-x64",
|
|
18
|
+
"linux-x64": "@legna-lnc/legnacode-linux-x64",
|
|
19
|
+
"linux-arm64": "@legna-lnc/legnacode-linux-arm64",
|
|
20
|
+
"win32-x64": "@legna-lnc/legnacode-win32-x64",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var key = process.platform + "-" + os.arch();
|
|
24
|
+
var pkg = PLATFORMS[key];
|
|
25
|
+
if (!pkg) process.exit(0); // unsupported platform, skip silently
|
|
26
|
+
|
|
27
|
+
var binName = process.platform === "win32" ? "legna.exe" : "bin/legna";
|
|
28
|
+
|
|
29
|
+
// Check if platform package is already available
|
|
30
|
+
function isInstalled() {
|
|
31
|
+
try {
|
|
32
|
+
var p = path.resolve(require.resolve(pkg + "/package.json"), "..", binName);
|
|
33
|
+
if (fs.existsSync(p)) return true;
|
|
34
|
+
} catch (e) {}
|
|
35
|
+
|
|
36
|
+
// Check sibling in global/local node_modules
|
|
37
|
+
var scopeDir = path.resolve(__dirname, "..", "..");
|
|
38
|
+
var pkgName = pkg.split("/")[1];
|
|
39
|
+
if (fs.existsSync(path.resolve(scopeDir, pkgName, binName))) return true;
|
|
40
|
+
|
|
41
|
+
// Check nested
|
|
42
|
+
var nested = path.resolve(__dirname, "..", "node_modules", pkg, binName);
|
|
43
|
+
if (fs.existsSync(nested)) return true;
|
|
44
|
+
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isInstalled()) process.exit(0);
|
|
49
|
+
|
|
50
|
+
// Not installed — fetch it from official npm registry
|
|
51
|
+
var version;
|
|
52
|
+
try {
|
|
53
|
+
version = JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "package.json"), "utf-8")).version;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
version = "latest";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log("Installing platform binary " + pkg + "@" + version + "...");
|
|
59
|
+
|
|
60
|
+
// Use official registry to avoid mirror sync delays
|
|
61
|
+
var result = childProcess.spawnSync(
|
|
62
|
+
"npm",
|
|
63
|
+
["install", "--no-save", pkg + "@" + version, "--registry", "https://registry.npmjs.org"],
|
|
64
|
+
{
|
|
65
|
+
cwd: path.resolve(__dirname, ".."),
|
|
66
|
+
stdio: "inherit",
|
|
67
|
+
shell: true,
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (result.status !== 0) {
|
|
72
|
+
// Try global install as fallback
|
|
73
|
+
var result2 = childProcess.spawnSync(
|
|
74
|
+
"npm",
|
|
75
|
+
["install", "-g", pkg + "@" + version, "--registry", "https://registry.npmjs.org"],
|
|
76
|
+
{ stdio: "inherit", shell: true }
|
|
77
|
+
);
|
|
78
|
+
if (result2.status !== 0) {
|
|
79
|
+
console.error("Warning: could not install " + pkg + ". Run manually:");
|
|
80
|
+
console.error(" npm install -g " + pkg + "@" + version + " --registry https://registry.npmjs.org");
|
|
81
|
+
}
|
|
82
|
+
}
|