Skip to content

Commit becf41a

Browse files
committed
fixed npm scripts
1 parent 585ded6 commit becf41a

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

vscode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,9 @@
765765
"compile": "tsc -p ./ && node ./esbuild.js",
766766
"watch": "tsc -watch -p ./ | node ./esbuild.js --watch",
767767
"test": "npm run compile && node ./out/test/runTest.js",
768-
"nbcode": "node ./out/nbcode.js",
769-
"nbjavac": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install .*nbjavac.*",
770-
"apisupport": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install '(org.netbeans.libs.xerces|org.netbeans.modules.editor.structure|org.netbeans.modules.xml|org.netbeans.modules.xml.axi|org.netbeans.modules.xml.retriever|org.netbeans.modules.xml.schema.model|org.netbeans.modules.xml.tax|org.netbeans.modules.xml.text|org.netbeans.modules.ant.browsetask|.*apisupport.*|org.netbeans.modules.debugger.jpda.ant)' && node ./out/nbcode.js -J-Dnetbeans.close=true --modules --enable .*apisupport.ant",
768+
"nbcode": "node ./out/test/launchNbcode.js",
769+
"nbjavac": "node ./out/test/launchNbcode.js -J-Dnetbeans.close=true --modules --install .*nbjavac.*",
770+
"apisupport": "node ./out/test/launchNbcode.js -J-Dnetbeans.close=true --modules --install '(org.netbeans.libs.xerces|org.netbeans.modules.editor.structure|org.netbeans.modules.xml|org.netbeans.modules.xml.axi|org.netbeans.modules.xml.retriever|org.netbeans.modules.xml.schema.model|org.netbeans.modules.xml.tax|org.netbeans.modules.xml.text|.*apisupport.*|org.netbeans.modules.debugger.jpda.ant)' && node ./out/test/launchNbcode.js -J-Dnetbeans.close=true --modules --enable .*apisupport.ant",
771771
"artifactory:check": "node ./esbuild.js --artifactory-check"
772772
},
773773
"devDependencies": {

vscode/src/test/launchNbcode.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs';
3+
import * as os from 'os';
4+
import { env } from 'process';
5+
import { ChildProcessByStdio, spawn } from 'child_process';
6+
import { Readable } from 'stream';
7+
8+
const findNbcode = (extensionPath: string): string => {
9+
let nbcode = os.platform() === 'win32' ?
10+
os.arch() === 'x64' ? 'nbcode64.exe' : 'nbcode.exe'
11+
: 'nbcode.sh';
12+
let nbcodePath = path.join(extensionPath, "nbcode", "bin", nbcode);
13+
14+
let nbcodePerm = fs.statSync(nbcodePath);
15+
if (!nbcodePerm.isFile()) {
16+
throw `Cannot execute ${nbcodePath}`;
17+
}
18+
if (os.platform() !== 'win32') {
19+
fs.chmodSync(path.join(extensionPath, "nbcode", "bin", nbcode), "744");
20+
fs.chmodSync(path.join(extensionPath, "nbcode", "platform", "lib", "nbexec.sh"), "744");
21+
fs.chmodSync(path.join(extensionPath, "nbcode", "java", "maven", "bin", "mvn.sh"), "744");
22+
}
23+
return nbcodePath;
24+
}
25+
26+
if (typeof process === 'object' && process.argv0 === 'node') {
27+
let extension = path.join(process.argv[1], '..', '..', '..');
28+
let nbcode = path.join(extension, 'nbcode');
29+
if (!fs.existsSync(nbcode)) {
30+
throw `Cannot find ${nbcode}. Try npm run compile first!`;
31+
}
32+
let clusters = fs.readdirSync(nbcode).filter(c => c !== 'bin' && c !== 'etc').map(c => path.join(nbcode, c));
33+
let args = process.argv.slice(2);
34+
let json = JSON.parse("" + fs.readFileSync(path.join(extension, 'package.json')));
35+
let storage;
36+
37+
if (!env.nbcode_userdir || env.nbcode_userdir == 'global') {
38+
storage = path.join(os.platform() === 'darwin' ?
39+
path.join(os.homedir(), 'Library', 'Application Support') :
40+
path.join(os.homedir(), '.config'),
41+
'Code', 'User', 'globalStorage', json.publisher + '.' + json.name);
42+
} else {
43+
storage = env.nbcode_userdir;
44+
}
45+
const userdir = path.join(storage, "userdir");
46+
47+
if (!fs.existsSync(userdir)) {
48+
fs.mkdirSync(userdir, { recursive: true });
49+
const stats = fs.statSync(userdir);
50+
if (!stats.isDirectory()) {
51+
throw `${userdir} is not a directory`;
52+
}
53+
}
54+
55+
console.log('Launching NBLS with user directory: ' + userdir);
56+
const ideArgs = [];
57+
ideArgs.push(`-J-Dnetbeans.extra.dirs="${clusters.join(path.delimiter)}"`, ...args);
58+
const nbcodeBinPath = findNbcode(extension);
59+
const nbProcess: ChildProcessByStdio<any, Readable, Readable> = spawn(nbcodeBinPath, ideArgs, {
60+
cwd: userdir,
61+
stdio: ["ignore", "pipe", "pipe"],
62+
});
63+
64+
nbProcess.stdout.on('data', function (data) {
65+
console.log(data.toString());
66+
});
67+
nbProcess.stderr.on('data', function (data) {
68+
console.log(data.toString());
69+
});
70+
nbProcess.on('close', (code) => {
71+
console.log(`nbcode finished with status ${code}`);
72+
});
73+
}

0 commit comments

Comments
 (0)