node-shortcuts 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -46,9 +46,13 @@ Covers all major Node.js core modules, including:
46
46
  ## Installation
47
47
  ```bash
48
48
  npm i node-shorcuts -D
49
+ npm i node-shortcuts -D
50
+ ```
51
+ You may need to restart VSC/VSC-I via:
52
+ ```text
53
+ Ctrl + Shift + P → Reload Window
49
54
  ```
50
55
 
51
- .vscode/node.code-snippets
52
56
  Snippets load automatically when the workspace opens.
53
57
 
54
58
  ### Node Version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-shortcuts",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Node Shortcut snippets",
5
5
  "main": "sync-snippets.js",
6
6
  "scripts": {
package/sync-snippets.js CHANGED
@@ -3,64 +3,79 @@
3
3
 
4
4
  import fs from 'fs';
5
5
  import path from 'path';
6
+ import os from 'os';
6
7
 
7
- const SOURCE_FILE = path.resolve('./snippets/node.json');
8
- const VSC_FILE = path.resolve('./node.code-snippets');
8
+ /**
9
+ * Paths
10
+ */
11
+ const USER_HOME = os.homedir();
12
+
13
+ const TARGETS = [
14
+ path.join(USER_HOME, 'AppData', 'Roaming', 'Code', 'User', 'snippets', 'javascript.json'),
15
+ path.join(USER_HOME, 'AppData', 'Roaming', 'Code - Insiders', 'User', 'snippets', 'javascript.json')
16
+ ];
17
+
18
+ const SOURCE_FILE = path.resolve('./snippets.source.json');
9
19
 
10
20
  /**
11
- * Safely read JSON file
21
+ * Read JSON safely
12
22
  */
13
- function readJSON(filePath) {
14
- if (!fs.existsSync(filePath)) return {};
15
- const raw = fs.readFileSync(filePath, 'utf8');
23
+ function readJSON(file) {
24
+ if (!fs.existsSync(file)) return {};
25
+ const raw = fs.readFileSync(file, 'utf8');
16
26
  return raw.trim() ? JSON.parse(raw) : {};
17
27
  }
18
28
 
29
+ /**
30
+ * Ensure directory exists
31
+ */
32
+ function ensureDir(file) {
33
+ fs.mkdirSync(path.dirname(file), { recursive: true });
34
+ }
35
+
19
36
  /**
20
37
  * Write formatted JSON
21
38
  */
22
- function writeJSON(filePath, data) {
23
- fs.writeFileSync(
24
- filePath,
25
- JSON.stringify(data, null, 2) + '\n',
26
- 'utf8'
27
- );
39
+ function writeJSON(file, data) {
40
+ ensureDir(file);
41
+ fs.writeFileSync(file, JSON.stringify(data, null, 2) + '\n', 'utf8');
28
42
  }
29
43
 
30
44
  /**
31
- * Sync snippets
45
+ * Sync snippets into javascript.json
32
46
  */
33
- function syncSnippets() {
47
+ function syncToVSCode(targetFile) {
34
48
  const sourceSnippets = readJSON(SOURCE_FILE);
35
- const vscSnippets = readJSON(VSC_FILE);
49
+ const userSnippets = readJSON(targetFile);
36
50
 
37
51
  let added = 0;
38
52
  let updated = 0;
39
53
 
40
- for (const [name, snippet] of Object.entries(sourceSnippets)) {
41
- if (!vscSnippets[name]) {
54
+ for (const [key, snippet] of Object.entries(sourceSnippets)) {
55
+ if (!userSnippets[key]) {
42
56
  added++;
43
- } else if (JSON.stringify(vscSnippets[name]) !== JSON.stringify(snippet)) {
57
+ } else if (JSON.stringify(userSnippets[key]) !== JSON.stringify(snippet)) {
44
58
  updated++;
45
59
  }
46
-
47
- vscSnippets[name] = snippet;
60
+ userSnippets[key] = snippet;
48
61
  }
49
62
 
50
- writeJSON(VSC_FILE, vscSnippets);
63
+ writeJSON(targetFile, userSnippets);
51
64
 
52
- console.log(`✔ Snippets synced`);
53
- console.log(`➕ Added: ${added}`);
54
- console.log(`🔄 Updated: ${updated}`);
65
+ console.log(`✔ Synced: ${targetFile}`);
66
+ console.log(` ➕ Added: ${added}`);
67
+ console.log(` 🔄 Updated: ${updated}`);
55
68
  }
56
69
 
57
70
  /**
58
71
  * Run
59
72
  */
60
73
  try {
61
- syncSnippets();
74
+ for (const target of TARGETS) {
75
+ syncToVSCode(target);
76
+ }
62
77
  } catch (err) {
63
- console.error('❌ Failed to sync snippets');
78
+ console.error('❌ Snippet sync failed');
64
79
  console.error(err);
65
80
  process.exit(1);
66
81
  }