mhs-lang 2.3.0 → 3.0.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.
Files changed (60) hide show
  1. package/README.md +47 -134
  2. package/bin/mhs.js +89 -81
  3. package/examples/demo_lengkap.mhs +12 -9
  4. package/examples/halo.mhs +7 -7
  5. package/examples/python_native.mhs +5 -4
  6. package/examples/rumus_elektronika.mhs +6 -6
  7. package/examples/tes_semua_modul.mhs +7 -7
  8. package/examples/utama_impor.mhs +8 -7
  9. package/package.json +6 -7
  10. package/src/index.js +84 -28
  11. package/src/language_server.js +58 -28
  12. package/src/lexer.js +444 -0
  13. package/src/modules/data_json.js +16 -4
  14. package/src/modules/index.js +0 -18
  15. package/src/parser.js +1523 -0
  16. package/src/py_modules/data_json.py +13 -2
  17. package/src/py_transpiler.js +1279 -202
  18. package/src/rust_runtime.js +443 -0
  19. package/src/safety_analyzer.js +2139 -0
  20. package/src/stdlib.js +123 -77
  21. package/src/transpiler.js +813 -337
  22. package/LICENSE +0 -21
  23. package/assets/mhs-file-icons.vsix +0 -0
  24. package/assets/mhs.ico +0 -0
  25. package/assets/mhs.svg +0 -3
  26. package/examples/__pycache__/alat_py.cpython-312.pyc +0 -0
  27. package/examples/tes_modul_baru.mhs +0 -44
  28. package/scripts/postinstall.js +0 -276
  29. package/src/modules/antrian.js +0 -37
  30. package/src/modules/arsip.js +0 -31
  31. package/src/modules/basis_data.js +0 -47
  32. package/src/modules/iterasi.js +0 -136
  33. package/src/modules/jalur.js +0 -77
  34. package/src/modules/proses.js +0 -43
  35. package/src/modules/statistika.js +0 -79
  36. package/src/modules/tabel.js +0 -83
  37. package/src/py_modules/__pycache__/antrian.cpython-312.pyc +0 -0
  38. package/src/py_modules/__pycache__/basis_data.cpython-312.pyc +0 -0
  39. package/src/py_modules/__pycache__/berkas.cpython-312.pyc +0 -0
  40. package/src/py_modules/__pycache__/data_json.cpython-312.pyc +0 -0
  41. package/src/py_modules/__pycache__/iterasi.cpython-312.pyc +0 -0
  42. package/src/py_modules/__pycache__/jalur.cpython-312.pyc +0 -0
  43. package/src/py_modules/__pycache__/jaringan.cpython-312.pyc +0 -0
  44. package/src/py_modules/__pycache__/koleksi.cpython-312.pyc +0 -0
  45. package/src/py_modules/__pycache__/kripto.cpython-312.pyc +0 -0
  46. package/src/py_modules/__pycache__/matematika.cpython-312.pyc +0 -0
  47. package/src/py_modules/__pycache__/modul_acak.cpython-312.pyc +0 -0
  48. package/src/py_modules/__pycache__/pola.cpython-312.pyc +0 -0
  49. package/src/py_modules/__pycache__/sistem.cpython-312.pyc +0 -0
  50. package/src/py_modules/__pycache__/statistika.cpython-312.pyc +0 -0
  51. package/src/py_modules/__pycache__/uji.cpython-312.pyc +0 -0
  52. package/src/py_modules/__pycache__/waktu.cpython-312.pyc +0 -0
  53. package/src/py_modules/antrian.py +0 -20
  54. package/src/py_modules/arsip.py +0 -37
  55. package/src/py_modules/basis_data.py +0 -29
  56. package/src/py_modules/iterasi.py +0 -37
  57. package/src/py_modules/jalur.py +0 -47
  58. package/src/py_modules/proses.py +0 -35
  59. package/src/py_modules/statistika.py +0 -29
  60. package/src/py_modules/tabel.py +0 -29
@@ -1,276 +0,0 @@
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
- }
@@ -1,37 +0,0 @@
1
- function Antrian(maks = 0) {
2
- if (!(this instanceof Antrian)) {
3
- return new Antrian(maks);
4
- }
5
- this._maks = maks;
6
- this._items = [];
7
- }
8
-
9
- Antrian.prototype.masukkan = function (item) {
10
- if (this._maks > 0 && this._items.length >= this._maks) {
11
- throw new Error('Antrian penuh');
12
- }
13
- this._items.push(item);
14
- };
15
-
16
- Antrian.prototype.ambil = function () {
17
- if (this.kosong()) {
18
- throw new Error('Antrian kosong');
19
- }
20
- return this._items.shift();
21
- };
22
-
23
- Antrian.prototype.ukuran = function () {
24
- return this._items.length;
25
- };
26
-
27
- Antrian.prototype.kosong = function () {
28
- return this._items.length === 0;
29
- };
30
-
31
- Antrian.prototype.penuh = function () {
32
- return this._maks > 0 && this._items.length >= this._maks;
33
- };
34
-
35
- module.exports = {
36
- Antrian,
37
- };
@@ -1,31 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- function salin_berkas(sumber, tujuan) {
5
- fs.copyFileSync(sumber, tujuan);
6
- return true;
7
- }
8
-
9
- function salin_folder(sumber, tujuan) {
10
- fs.cpSync(sumber, tujuan, { recursive: true });
11
- return true;
12
- }
13
-
14
- function hapus_folder(folder) {
15
- if (fs.existsSync(folder)) {
16
- fs.rmSync(folder, { recursive: true, force: true });
17
- }
18
- return true;
19
- }
20
-
21
- function pindah(sumber, tujuan) {
22
- fs.renameSync(sumber, tujuan);
23
- return true;
24
- }
25
-
26
- module.exports = {
27
- salin_berkas,
28
- salin_folder,
29
- hapus_folder,
30
- pindah,
31
- };
@@ -1,47 +0,0 @@
1
- const fs = require('fs');
2
-
3
- function hubungkan(nama_berkas = ':memory:') {
4
- let store = {};
5
- if (nama_berkas !== ':memory:' && fs.existsSync(nama_berkas)) {
6
- try {
7
- store = JSON.parse(fs.readFileSync(nama_berkas, 'utf8'));
8
- } catch {}
9
- }
10
- return {
11
- _file: nama_berkas,
12
- _store: store,
13
- _rows: [],
14
- };
15
- }
16
-
17
- function eksekusi(koneksi, sql, params = []) {
18
- // basic mock for node fallback
19
- return 1;
20
- }
21
-
22
- function ambil_semua(koneksi, sql, params = []) {
23
- return koneksi._rows || [];
24
- }
25
-
26
- function ambil_satu(koneksi, sql, params = []) {
27
- return (koneksi._rows && koneksi._rows[0]) || null;
28
- }
29
-
30
- function simpan(koneksi) {
31
- if (koneksi._file !== ':memory:') {
32
- fs.writeFileSync(koneksi._file, JSON.stringify(koneksi._store, null, 2), 'utf8');
33
- }
34
- }
35
-
36
- function tutup(koneksi) {
37
- simpan(koneksi);
38
- }
39
-
40
- module.exports = {
41
- hubungkan,
42
- eksekusi,
43
- ambil_semua,
44
- ambil_satu,
45
- simpan,
46
- tutup,
47
- };
@@ -1,136 +0,0 @@
1
- function kombinasi(koleksi, r) {
2
- const arr = Array.from(koleksi);
3
- if (r < 0 || r > arr.length) return [];
4
- if (r === 0) return [[]];
5
- const hasil = [];
6
- function bantu(mulai, jalur) {
7
- if (jalur.length === r) {
8
- hasil.push([...jalur]);
9
- return;
10
- }
11
- for (let i = mulai; i < arr.length; i++) {
12
- jalur.push(arr[i]);
13
- bantu(i + 1, jalur);
14
- jalur.pop();
15
- }
16
- }
17
- bantu(0, []);
18
- return hasil;
19
- }
20
-
21
- function permutasi(koleksi, r) {
22
- const arr = Array.from(koleksi);
23
- const panjang = r === undefined || r === null ? arr.length : r;
24
- if (panjang < 0 || panjang > arr.length) return [];
25
- if (panjang === 0) return [[]];
26
- const hasil = [];
27
- const digunakan = new Array(arr.length).fill(false);
28
- function bantu(jalur) {
29
- if (jalur.length === panjang) {
30
- hasil.push([...jalur]);
31
- return;
32
- }
33
- for (let i = 0; i < arr.length; i++) {
34
- if (digunakan[i]) continue;
35
- digunakan[i] = true;
36
- jalur.push(arr[i]);
37
- bantu(jalur);
38
- jalur.pop();
39
- digunakan[i] = false;
40
- }
41
- }
42
- bantu([]);
43
- return hasil;
44
- }
45
-
46
- function produk(...koleksi) {
47
- if (koleksi.length === 0) return [[]];
48
- let hasil = [[]];
49
- for (const pool of koleksi) {
50
- const baru = [];
51
- for (const x of hasil) {
52
- for (const y of pool) {
53
- baru.push([...x, y]);
54
- }
55
- }
56
- hasil = baru;
57
- }
58
- return hasil;
59
- }
60
-
61
- function rantai(...koleksi) {
62
- const hasil = [];
63
- for (const k of koleksi) {
64
- hasil.push(...Array.from(k));
65
- }
66
- return hasil;
67
- }
68
-
69
- function akumulasi(koleksi, fungsi) {
70
- const arr = Array.from(koleksi);
71
- if (arr.length === 0) return [];
72
- const fn = fungsi || ((a, b) => a + b);
73
- const hasil = [arr[0]];
74
- for (let i = 1; i < arr.length; i++) {
75
- hasil.push(fn(hasil[i - 1], arr[i]));
76
- }
77
- return hasil;
78
- }
79
-
80
- function ulang(item, kali) {
81
- const hasil = [];
82
- for (let i = 0; i < kali; i++) hasil.push(item);
83
- return hasil;
84
- }
85
-
86
- function ambil_selama(predikat, koleksi) {
87
- const hasil = [];
88
- for (const item of koleksi) {
89
- if (predikat(item)) hasil.push(item);
90
- else break;
91
- }
92
- return hasil;
93
- }
94
-
95
- function lewati_selama(predikat, koleksi) {
96
- const arr = Array.from(koleksi);
97
- let idx = 0;
98
- while (idx < arr.length && predikat(arr[idx])) {
99
- idx++;
100
- }
101
- return arr.slice(idx);
102
- }
103
-
104
- function saring_palsu(predikat, koleksi) {
105
- return Array.from(koleksi).filter((x) => !predikat(x));
106
- }
107
-
108
- function siklus(koleksi, kali = 1) {
109
- const arr = Array.from(koleksi);
110
- const hasil = [];
111
- for (let i = 0; i < kali; i++) hasil.push(...arr);
112
- return hasil;
113
- }
114
-
115
- function ritsleting_terpanjang(...koleksi) {
116
- const maxLen = Math.max(...koleksi.map((k) => k.length));
117
- const hasil = [];
118
- for (let i = 0; i < maxLen; i++) {
119
- hasil.push(koleksi.map((k) => (i < k.length ? k[i] : null)));
120
- }
121
- return hasil;
122
- }
123
-
124
- module.exports = {
125
- kombinasi,
126
- permutasi,
127
- produk,
128
- rantai,
129
- akumulasi,
130
- ulang,
131
- ambil_selama,
132
- lewati_selama,
133
- saring_palsu,
134
- siklus,
135
- ritsleting_terpanjang,
136
- };
@@ -1,77 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const os = require('os');
4
-
5
- function gabung(...bagian) {
6
- return path.join(...bagian);
7
- }
8
-
9
- function nama(jalur) {
10
- return path.basename(jalur);
11
- }
12
-
13
- function induk(jalur) {
14
- return path.dirname(jalur);
15
- }
16
-
17
- function ekstensi(jalur) {
18
- return path.extname(jalur);
19
- }
20
-
21
- function nama_murni(jalur) {
22
- return path.basename(jalur, path.extname(jalur));
23
- }
24
-
25
- function mutlak(jalur) {
26
- return path.resolve(jalur);
27
- }
28
-
29
- function ada(jalur) {
30
- return fs.existsSync(jalur);
31
- }
32
-
33
- function adalah_berkas(jalur) {
34
- return fs.existsSync(jalur) && fs.statSync(jalur).isFile();
35
- }
36
-
37
- function adalah_folder(jalur) {
38
- return fs.existsSync(jalur) && fs.statSync(jalur).isDirectory();
39
- }
40
-
41
- function ukuran(jalur) {
42
- return fs.existsSync(jalur) ? fs.statSync(jalur).size : 0;
43
- }
44
-
45
- function folder_pengguna() {
46
- return os.homedir();
47
- }
48
-
49
- function direktori_kerja() {
50
- return process.cwd();
51
- }
52
-
53
- function baca_teks(jalur, encoding = 'utf-8') {
54
- return fs.readFileSync(jalur, encoding).replace(/^\uFEFF/, '');
55
- }
56
-
57
- function tulis_teks(jalur, konten, encoding = 'utf-8') {
58
- fs.writeFileSync(jalur, konten, encoding);
59
- return true;
60
- }
61
-
62
- module.exports = {
63
- gabung,
64
- nama,
65
- induk,
66
- ekstensi,
67
- nama_murni,
68
- mutlak,
69
- ada,
70
- adalah_berkas,
71
- adalah_folder,
72
- ukuran,
73
- folder_pengguna,
74
- direktori_kerja,
75
- baca_teks,
76
- tulis_teks,
77
- };
@@ -1,43 +0,0 @@
1
- const { execSync, spawnSync } = require('child_process');
2
-
3
- function jalankan(perintah, masukan = null, tangkap_keluaran = true, batas_waktu = null) {
4
- try {
5
- const res = spawnSync(perintah, {
6
- shell: true,
7
- input: masukan,
8
- encoding: 'utf8',
9
- timeout: batas_waktu ? batas_waktu * 1000 : undefined,
10
- });
11
- return {
12
- kode_keluar: res.status !== null ? res.status : -1,
13
- sukses: res.status === 0,
14
- keluaran: res.stdout || '',
15
- galat: res.stderr || '',
16
- };
17
- } catch (err) {
18
- return {
19
- kode_keluar: -1,
20
- sukses: false,
21
- keluaran: '',
22
- galat: err.message,
23
- };
24
- }
25
- }
26
-
27
- function keluaran(perintah) {
28
- try {
29
- return execSync(perintah, { encoding: 'utf8', shell: true }).trim();
30
- } catch (err) {
31
- return '';
32
- }
33
- }
34
-
35
- function sukses(perintah) {
36
- return jalankan(perintah).sukses;
37
- }
38
-
39
- module.exports = {
40
- jalankan,
41
- keluaran,
42
- sukses,
43
- };