mhs-lang 2.1.1 → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maheswara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="./assets/logo.png" alt="Logo mhs-lang" width="180" />
3
3
  </p>
4
4
 
5
- # mhs-lang v2.1 (`.mhs`)
5
+ # mhs-lang v2.2 (`.mhs`)
6
6
 
7
7
  Bahasa pemrograman **Python dalam Bahasa Indonesia** yang bisa diunduh lewat `npm` dan dijalankan di IDE apa pun. Hadir dengan **Dual-Engine**:
8
8
  1. **Engine Node.js + Python Bridge** (`mhs file.mhs`): langsung jalan tanpa Python, tapi otomatis bisa memanggil modul `.py` / `pip` lewat `impor_py` atau `impor "./alat.py"`.
@@ -45,9 +45,19 @@ Transport: stdio
45
45
 
46
46
  Perintah `mhs --lsp` dijalankan oleh klien editor (bukan sebagai program interaktif di terminal).
47
47
 
48
- Instalasi npm **tidak dapat memasang plugin, grammar, atau ikon secara otomatis ke semua IDE**. Setiap editor tetap memerlukan klien LSP, dan ikon file diatur oleh tema/plugin editor masing-masing.
48
+ ### Dukungan IDE dan Ekstensi Otomatis
49
49
 
50
- - **VS Code dan Antigravity:** pasang ekstensi MHS Tools untuk grammar, ikon, tombol Run, dan koneksi LSP. Di Antigravity gunakan pemasangan VSIX/ekstensi jika tersedia pada versi yang dipakai.
50
+ Mulai versi 2.2.0, saat Anda menjalankan:
51
+ ```bash
52
+ npm install -g mhs-lang
53
+ ```
54
+ Skrip post-install secara otomatis:
55
+ - Mendeteksi editor yang terpasang (**VS Code**, **Cursor**, **Antigravity IDE**, **VSCodium**)
56
+ - Memasang ekstensi VSIX (`mhs-file-icons`) lengkap dengan Syntax Highlighting, Snippets, Run Shortcut, dan Ikon `.mhs`
57
+ - Mengonfigurasi `workbench.iconTheme` dan asosiasi file `*.mhs`
58
+ - Mendaftarkan ikon file `.mhs` pada Windows Explorer
59
+
60
+ Jika editor sedang terbuka saat instalasi, cukup tekan `Ctrl+Shift+P` lalu ketik **"Reload Window"** agar tema dan ikon langsung aktif.
51
61
  - **JetBrains:** pasang plugin klien LSP seperti LSP4IJ, lalu daftarkan command `mhs` dengan argumen `--lsp`.
52
62
  - **Sublime Text:** pasang paket LSP, lalu daftarkan command server `mhs --lsp`.
53
63
  - **Vim/Neovim:** daftarkan filetype `.mhs` dan jalankan klien LSP dengan command `mhs` dan argumen `--lsp`.
@@ -110,3 +120,11 @@ Semua modul berikut dapat langsung diimpor baik di mode Node.js (`mhs`) maupun m
110
120
  | `and` / `or` / `not` / `in` | `dan` / `atau` / `bukan` / `dalam` |
111
121
  | `break` / `continue` / `pass` | `berhenti` / `lanjut` / `lewat` |
112
122
  | `[x*2 for x in range(5)]` | `[x*2 untuk x dalam rentang(5)]` |
123
+
124
+ ---
125
+
126
+ ## 4. Lisensi
127
+
128
+ Proyek ini dilisensikan di bawah lisensi open source [MIT License](LICENSE).
129
+ Hak Cipta (c) 2026 Maheswara. Bebas digunakan, dimodifikasi, dan didistribusikan untuk keperluan pribadi maupun komersial.
130
+
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mhs-lang",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Bahasa pemrograman Python dalam Bahasa Indonesia (.mhs) dengan dual-engine Node.js + Python 3 native, dukungan impor .mhs, npm, dan modul Python (.py/pip).",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -11,11 +11,14 @@
11
11
  "bin/",
12
12
  "src/",
13
13
  "assets/",
14
+ "scripts/postinstall.js",
14
15
  "examples/",
15
- "README.md"
16
+ "README.md",
17
+ "LICENSE"
16
18
  ],
17
19
  "scripts": {
18
- "test": "node test/run_tests.js"
20
+ "test": "node test/run_tests.js",
21
+ "postinstall": "node scripts/postinstall.js"
19
22
  },
20
23
  "keywords": [
21
24
  "bahasa-pemrograman",
@@ -36,4 +39,4 @@
36
39
  "vscode-languageserver": "^9.0.1",
37
40
  "vscode-languageserver-textdocument": "^1.0.12"
38
41
  }
39
- }
42
+ }
@@ -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
+ }