idea-manager 0.9.2 → 0.9.3
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/package.json +1 -1
- package/src/cli.ts +11 -5
- package/src/lib/sync/git.ts +5 -3
- package/src/lib/sync/index.ts +17 -7
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -11,9 +11,15 @@ import { spawn } from 'child_process';
|
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import { fileURLToPath } from 'url';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// Resolve PKG_ROOT robustly across macOS/Windows and tsx/cjs context
|
|
15
|
+
let PKG_ROOT: string;
|
|
16
|
+
try {
|
|
17
|
+
const thisFile = fileURLToPath(import.meta.url);
|
|
18
|
+
PKG_ROOT = path.resolve(path.dirname(thisFile), '..');
|
|
19
|
+
} catch {
|
|
20
|
+
// Fallback for CJS context (tsx/cjs on some Windows setups)
|
|
21
|
+
PKG_ROOT = path.resolve(__dirname, '..');
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
async function openAsApp(url: string) {
|
|
19
25
|
const { exec: execCb } = await import('child_process');
|
|
@@ -29,8 +35,8 @@ async function openAsApp(url: string) {
|
|
|
29
35
|
]
|
|
30
36
|
: platform === 'win32'
|
|
31
37
|
? [
|
|
32
|
-
`start "" chrome --app=${url}`,
|
|
33
|
-
`start "" msedge --app=${url}`,
|
|
38
|
+
`start "" "chrome" "--app=${url}"`,
|
|
39
|
+
`start "" "msedge" "--app=${url}"`,
|
|
34
40
|
]
|
|
35
41
|
: [
|
|
36
42
|
`google-chrome --app=${url}`,
|
package/src/lib/sync/git.ts
CHANGED
|
@@ -4,10 +4,12 @@ import path from 'path';
|
|
|
4
4
|
|
|
5
5
|
function quoteArg(arg: string): string {
|
|
6
6
|
// Quote args with spaces for shell mode
|
|
7
|
-
if (arg.includes(' ')
|
|
8
|
-
|
|
7
|
+
if (!arg.includes(' ') && !arg.includes('"')) return arg;
|
|
8
|
+
if (process.platform === 'win32') {
|
|
9
|
+
// cmd.exe uses "" to escape quotes
|
|
10
|
+
return `"${arg.replace(/"/g, '""')}"`;
|
|
9
11
|
}
|
|
10
|
-
return arg
|
|
12
|
+
return `"${arg.replace(/"/g, '\\"')}"`;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
function exec(cmd: string, args: string[], cwd?: string): Promise<string> {
|
package/src/lib/sync/index.ts
CHANGED
|
@@ -78,21 +78,31 @@ export async function syncInit() {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
//
|
|
81
|
+
// Clone into a temp dir, then move contents to sync dir
|
|
82
82
|
console.log(`\n Cloning to ${syncDir}...`);
|
|
83
|
+
const tmpCloneDir = syncDir + '-tmp-' + Date.now();
|
|
84
|
+
let cloned = false;
|
|
85
|
+
|
|
83
86
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
await git.gitClone(repoUrl, tmpCloneDir);
|
|
88
|
+
// Move contents from tmp to sync dir
|
|
89
|
+
const entries = fs.readdirSync(tmpCloneDir, { withFileTypes: true });
|
|
90
|
+
// Clean sync dir first
|
|
91
|
+
for (const e of fs.readdirSync(syncDir)) {
|
|
87
92
|
fs.rmSync(path.join(syncDir, e), { recursive: true, force: true });
|
|
88
93
|
}
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
for (const e of entries) {
|
|
95
|
+
fs.renameSync(path.join(tmpCloneDir, e.name), path.join(syncDir, e.name));
|
|
96
|
+
}
|
|
97
|
+
fs.rmSync(tmpCloneDir, { recursive: true, force: true });
|
|
98
|
+
cloned = true;
|
|
91
99
|
} catch {
|
|
92
|
-
// Clone
|
|
100
|
+
// Clone failed — init locally + add remote
|
|
101
|
+
fs.rmSync(tmpCloneDir, { recursive: true, force: true });
|
|
93
102
|
try {
|
|
94
103
|
await git.gitInit(syncDir);
|
|
95
104
|
await git.gitAddRemote(syncDir, repoUrl);
|
|
105
|
+
cloned = true;
|
|
96
106
|
} catch (err2) {
|
|
97
107
|
console.error(` Failed: ${(err2 as Error).message}\n`);
|
|
98
108
|
process.exit(1);
|