Skip to content

Commit 5b5d44c

Browse files
authored
dev-link script works also on Windows (teambit#4223)
1 parent fe12516 commit 5b5d44c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
],
5252
"scripts": {
5353
"dev-link": "node ./scripts/establish-dev-link.js $1",
54+
"dev-link:windows": "node ./scripts/establish-dev-link-windows.js $1",
5455
"ts-coverage": "type-coverage",
5556
"check-types": "tsc",
5657
"ts-watch": "tsc -w",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { rmSync, mkdirSync, writeFileSync } = require('fs');
2+
const { exec } = require('child_process');
3+
const path = require('path');
4+
5+
const userLinkName = process.argv[3];
6+
const linkName = userLinkName || 'bit-dev';
7+
8+
const source = path.join(__dirname, '..', 'bin', 'bit.js');
9+
const dest = `${process.env.localappdata}\\${linkName}`;
10+
11+
rmSync(dest, { recursive: true, force: true });
12+
mkdirSync(dest);
13+
14+
writeFileSync(`${dest}\\${linkName}.bat`, `@echo off\nnode ${source} %*`);
15+
16+
if (process.env.PATH.includes(dest)) {
17+
console.log(`Success!!!\nNow you can use the "${linkName}" command to run your dev app.`);
18+
return;
19+
}
20+
21+
exec(`powershell -NoProfile -ExecutionPolicy Bypass -Command "[Environment]::SetEnvironmentVariable('path', [Environment]::GetEnvironmentVariable('path', [EnvironmentVariableTarget]::User) + ';${dest}', 'User');"`, (error, stdout, stderr) => {
22+
if (error) {
23+
console.error(`exec error: ${error}`);
24+
return;
25+
}
26+
27+
if (stdout) console.log(stdout);
28+
if (stderr) console.error(stderr);
29+
30+
console.log(`Success!!!\nPlease close and reopen the terminal.\nIf you are using VSCode, you need to close it and reopen.\nThen you will be able to use the "${linkName}" command to run your dev app :)`);
31+
});

scripts/establish-dev-link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ exec(`ln -sf ${source} ${dest}`, (error, stdout, stderr) => {
3434

3535
if (sout) console.log(sout);
3636
if (serr) console.error(serr);
37-
console.log(`now you can use the "${linkName}" command to run you dev app`);
37+
console.log(`Now you can use the "${linkName}" command to run your dev app.`);
3838
});
3939
});

0 commit comments

Comments
 (0)