mhs-lang 2.1.0 → 2.2.0
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/LICENSE +21 -0
- package/README.md +21 -3
- package/assets/mhs-file-icons.vsix +0 -0
- package/assets/mhs.ico +0 -0
- package/assets/mhs.svg +3 -0
- package/examples/__pycache__/alat_py.cpython-312.pyc +0 -0
- package/package.json +7 -4
- package/scripts/postinstall.js +276 -0
- package/src/language_server.js +283 -283
- package/src/py_modules/__pycache__/berkas.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/data_json.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/jaringan.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/koleksi.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/kripto.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/matematika.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/modul_acak.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/pola.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/sistem.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/uji.cpython-312.pyc +0 -0
- package/src/py_modules/__pycache__/waktu.cpython-312.pyc +0 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* mhs-lang postinstall — otomatis pasang ekstensi VSIX ke semua editor
|
|
5
|
+
* VS Code-family yang terdeteksi, atur tema ikon & asosiasi file .mhs,
|
|
6
|
+
* dan daftarkan ikon .mhs di Windows Explorer.
|
|
7
|
+
*
|
|
8
|
+
* Berjalan otomatis saat `npm install -g mhs-lang`.
|
|
9
|
+
* Tidak pernah gagalkan instalasi — semua error ditangkap dan dilaporkan.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { execFileSync, execSync, spawnSync } = require('child_process');
|
|
15
|
+
|
|
16
|
+
const VSIX = path.resolve(__dirname, '..', 'assets', 'mhs-file-icons.vsix');
|
|
17
|
+
const ICO = path.resolve(__dirname, '..', 'assets', 'mhs.ico');
|
|
18
|
+
|
|
19
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
20
|
+
// 1. Cari semua editor VS Code-family
|
|
21
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
22
|
+
|
|
23
|
+
function findEditors() {
|
|
24
|
+
const found = [];
|
|
25
|
+
|
|
26
|
+
if (process.platform === 'win32') {
|
|
27
|
+
const candidates = [
|
|
28
|
+
// VS Code
|
|
29
|
+
{
|
|
30
|
+
name: 'VS Code',
|
|
31
|
+
cli: path.join(process.env.LOCALAPPDATA || '', 'Programs', 'Microsoft VS Code', 'bin', 'code.cmd'),
|
|
32
|
+
settingsDir: path.join(process.env.APPDATA || '', 'Code', 'User'),
|
|
33
|
+
},
|
|
34
|
+
// Cursor
|
|
35
|
+
{
|
|
36
|
+
name: 'Cursor',
|
|
37
|
+
cli: path.join('D:', 'cursor', 'resources', 'app', 'bin', 'cursor.cmd'),
|
|
38
|
+
settingsDir: path.join(process.env.APPDATA || '', 'Cursor', 'User'),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'Cursor',
|
|
42
|
+
cli: path.join(process.env.LOCALAPPDATA || '', 'Programs', 'cursor', 'bin', 'cursor.cmd'),
|
|
43
|
+
settingsDir: path.join(process.env.APPDATA || '', 'Cursor', 'User'),
|
|
44
|
+
},
|
|
45
|
+
// Antigravity IDE
|
|
46
|
+
{
|
|
47
|
+
name: 'Antigravity IDE',
|
|
48
|
+
cli: path.join(process.env.LOCALAPPDATA || '', 'Programs', 'Antigravity IDE', 'bin', 'antigravity-ide.cmd'),
|
|
49
|
+
settingsDir: path.join(process.env.APPDATA || '', 'Antigravity IDE', 'User'),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'Antigravity IDE',
|
|
53
|
+
cli: path.join('D:', 'Antigravity IDE', 'bin', 'antigravity-ide.cmd'),
|
|
54
|
+
settingsDir: path.join(process.env.APPDATA || '', 'Antigravity IDE', 'User'),
|
|
55
|
+
},
|
|
56
|
+
// VSCodium
|
|
57
|
+
{
|
|
58
|
+
name: 'VSCodium',
|
|
59
|
+
cli: path.join(process.env.LOCALAPPDATA || '', 'Programs', 'VSCodium', 'bin', 'codium.cmd'),
|
|
60
|
+
settingsDir: path.join(process.env.APPDATA || '', 'VSCodium', 'User'),
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
// Also try finding via PATH
|
|
65
|
+
const pathClis = [
|
|
66
|
+
{ name: 'VS Code (PATH)', cmd: 'code', settingsDir: path.join(process.env.APPDATA || '', 'Code', 'User') },
|
|
67
|
+
{ name: 'Cursor (PATH)', cmd: 'cursor', settingsDir: path.join(process.env.APPDATA || '', 'Cursor', 'User') },
|
|
68
|
+
{ name: 'Antigravity IDE (PATH)', cmd: 'antigravity-ide', settingsDir: path.join(process.env.APPDATA || '', 'Antigravity IDE', 'User') },
|
|
69
|
+
{ name: 'VSCodium (PATH)', cmd: 'codium', settingsDir: path.join(process.env.APPDATA || '', 'VSCodium', 'User') },
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
for (const c of candidates) {
|
|
73
|
+
if (fs.existsSync(c.cli) && !found.some((f) => f.name === c.name)) {
|
|
74
|
+
found.push(c);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Check PATH-based CLIs only if not already found via absolute path
|
|
79
|
+
for (const pc of pathClis) {
|
|
80
|
+
if (found.some((f) => f.name.startsWith(pc.name.split(' (')[0]))) continue;
|
|
81
|
+
try {
|
|
82
|
+
execFileSync('where', [pc.cmd], { stdio: 'ignore' });
|
|
83
|
+
found.push({ name: pc.name, cli: pc.cmd, settingsDir: pc.settingsDir });
|
|
84
|
+
} catch {}
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
// macOS / Linux
|
|
88
|
+
const clis = [
|
|
89
|
+
{ name: 'VS Code', cmd: 'code' },
|
|
90
|
+
{ name: 'Cursor', cmd: 'cursor' },
|
|
91
|
+
{ name: 'VSCodium', cmd: 'codium' },
|
|
92
|
+
{ name: 'Antigravity IDE', cmd: 'antigravity-ide' },
|
|
93
|
+
];
|
|
94
|
+
for (const c of clis) {
|
|
95
|
+
try {
|
|
96
|
+
execFileSync('which', [c.cmd], { stdio: 'ignore' });
|
|
97
|
+
found.push({ name: c.name, cli: c.cmd, settingsDir: '' });
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
106
|
+
// 2. Install VSIX ke editor
|
|
107
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
108
|
+
|
|
109
|
+
function installVsix(editor) {
|
|
110
|
+
if (!fs.existsSync(VSIX)) {
|
|
111
|
+
console.log(` ⚠ VSIX tidak ditemukan: ${VSIX}`);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
let res;
|
|
116
|
+
if (process.platform === 'win32') {
|
|
117
|
+
res = spawnSync('cmd.exe', ['/d', '/c', editor.cli, '--install-extension', VSIX, '--force'], {
|
|
118
|
+
stdio: 'pipe',
|
|
119
|
+
timeout: 45000,
|
|
120
|
+
encoding: 'utf8',
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
res = spawnSync(editor.cli, ['--install-extension', VSIX, '--force'], {
|
|
124
|
+
stdio: 'pipe',
|
|
125
|
+
timeout: 45000,
|
|
126
|
+
encoding: 'utf8',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (res.status === 0) {
|
|
130
|
+
return true;
|
|
131
|
+
} else {
|
|
132
|
+
const msg = (res.stderr || res.stdout || '').trim().split('\n')[0];
|
|
133
|
+
console.log(` ⚠ Gagal (${res.status}): ${msg}`);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.log(` ⚠ Gagal install ekstensi ke ${editor.name}: ${err.message}`);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
143
|
+
// 3. Update settings.json editor
|
|
144
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
145
|
+
|
|
146
|
+
function updateEditorSettings(settingsDir) {
|
|
147
|
+
if (!settingsDir) return;
|
|
148
|
+
const settingsPath = path.join(settingsDir, 'settings.json');
|
|
149
|
+
let settings = {};
|
|
150
|
+
|
|
151
|
+
if (fs.existsSync(settingsPath)) {
|
|
152
|
+
try {
|
|
153
|
+
// Parse JSON with comments (strip // and /* */ comments)
|
|
154
|
+
const raw = fs.readFileSync(settingsPath, 'utf8');
|
|
155
|
+
const stripped = raw
|
|
156
|
+
.replace(/\/\/.*$/gm, '')
|
|
157
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
158
|
+
.replace(/,\s*([}\]])/g, '$1');
|
|
159
|
+
settings = JSON.parse(stripped);
|
|
160
|
+
} catch {
|
|
161
|
+
// If parsing fails, don't overwrite
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let changed = false;
|
|
167
|
+
|
|
168
|
+
// Set icon theme
|
|
169
|
+
if (settings['workbench.iconTheme'] !== 'mhs-file-icons') {
|
|
170
|
+
settings['workbench.iconTheme'] = 'mhs-file-icons';
|
|
171
|
+
changed = true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Set file associations
|
|
175
|
+
if (!settings['files.associations']) {
|
|
176
|
+
settings['files.associations'] = {};
|
|
177
|
+
}
|
|
178
|
+
if (settings['files.associations']['*.mhs'] !== 'mhs') {
|
|
179
|
+
settings['files.associations']['*.mhs'] = 'mhs';
|
|
180
|
+
changed = true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (changed) {
|
|
184
|
+
try {
|
|
185
|
+
fs.mkdirSync(settingsDir, { recursive: true });
|
|
186
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4), 'utf8');
|
|
187
|
+
} catch {}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
192
|
+
// 4. Windows: Daftarkan ikon .mhs di Explorer & file association
|
|
193
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
194
|
+
|
|
195
|
+
function registerWindowsFileAssociation() {
|
|
196
|
+
if (process.platform !== 'win32') return;
|
|
197
|
+
if (!fs.existsSync(ICO)) return;
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
// Copy icon to persistent location
|
|
201
|
+
const icoDir = path.join(process.env.LOCALAPPDATA || '', 'mhs-lang');
|
|
202
|
+
fs.mkdirSync(icoDir, { recursive: true });
|
|
203
|
+
const icoTarget = path.join(icoDir, 'mhs.ico');
|
|
204
|
+
fs.copyFileSync(ICO, icoTarget);
|
|
205
|
+
|
|
206
|
+
// Register file extension
|
|
207
|
+
const regCmds = [
|
|
208
|
+
`reg add "HKCU\\Software\\Classes\\.mhs" /ve /d "mhsfile" /f`,
|
|
209
|
+
`reg add "HKCU\\Software\\Classes\\mhsfile" /ve /d "MHS Script File (.mhs)" /f`,
|
|
210
|
+
`reg add "HKCU\\Software\\Classes\\mhsfile\\DefaultIcon" /ve /d "${icoTarget},0" /f`,
|
|
211
|
+
`reg add "HKCU\\Software\\Classes\\mhsfile\\shell\\open\\command" /ve /d "cmd.exe /c mhs \\"%1\\" & pause" /f`,
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
for (const cmd of regCmds) {
|
|
215
|
+
try {
|
|
216
|
+
execSync(cmd, { stdio: 'ignore' });
|
|
217
|
+
} catch {}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Notify shell of icon cache change
|
|
221
|
+
try {
|
|
222
|
+
execSync(
|
|
223
|
+
'powershell -NoProfile -Command "Add-Type -TypeDefinition \'using System;using System.Runtime.InteropServices;public class S{[DllImport(\\\"shell32.dll\\\")]public static extern void SHChangeNotify(uint e,uint f,IntPtr i,IntPtr j);}\';[S]::SHChangeNotify(0x08000000,0,[IntPtr]::Zero,[IntPtr]::Zero)"',
|
|
224
|
+
{ stdio: 'ignore' }
|
|
225
|
+
);
|
|
226
|
+
} catch {}
|
|
227
|
+
|
|
228
|
+
console.log(' ✓ Ikon .mhs terdaftar di Windows Explorer');
|
|
229
|
+
} catch (err) {
|
|
230
|
+
console.log(` ⚠ Gagal mendaftarkan ikon Windows: ${err.message}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
235
|
+
// 5. Main
|
|
236
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
237
|
+
|
|
238
|
+
function main() {
|
|
239
|
+
// Skip in CI environments
|
|
240
|
+
if (process.env.CI || process.env.CONTINUOUS_INTEGRATION) return;
|
|
241
|
+
|
|
242
|
+
console.log('');
|
|
243
|
+
console.log('🔧 mhs-lang: Memasang ekstensi MHS ke editor yang terdeteksi...');
|
|
244
|
+
console.log('');
|
|
245
|
+
|
|
246
|
+
const editors = findEditors();
|
|
247
|
+
|
|
248
|
+
if (editors.length === 0) {
|
|
249
|
+
console.log(' ℹ Tidak menemukan editor VS Code / Cursor / Antigravity IDE.');
|
|
250
|
+
console.log(' ℹ Anda bisa memasang ekstensi secara manual:');
|
|
251
|
+
console.log(` <editor> --install-extension "${VSIX}"`);
|
|
252
|
+
} else {
|
|
253
|
+
for (const editor of editors) {
|
|
254
|
+
process.stdout.write(` → ${editor.name}... `);
|
|
255
|
+
const ok = installVsix(editor);
|
|
256
|
+
if (ok) {
|
|
257
|
+
console.log('✓ Ekstensi terpasang!');
|
|
258
|
+
updateEditorSettings(editor.settingsDir);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
registerWindowsFileAssociation();
|
|
264
|
+
|
|
265
|
+
console.log('');
|
|
266
|
+
console.log('✅ mhs-lang siap! Jalankan: mhs --version');
|
|
267
|
+
console.log(' Jika editor sedang terbuka, tekan Ctrl+Shift+P → "Reload Window"');
|
|
268
|
+
console.log('');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Run but NEVER fail the npm install
|
|
272
|
+
try {
|
|
273
|
+
main();
|
|
274
|
+
} catch (err) {
|
|
275
|
+
// Silently ignore — postinstall must not block npm install
|
|
276
|
+
}
|