lumpiajs 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/index.js +73 -36
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -2,28 +2,20 @@
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
-
// --- KAMUS BAHASA SEMARANG
|
|
5
|
+
// --- KAMUS BAHASA SEMARANG ---
|
|
6
6
|
const dictionary = [
|
|
7
|
-
// Struktur
|
|
8
7
|
{ asal: /<lump>/g, jadi: '' },
|
|
9
8
|
{ asal: /<\/lump>/g, jadi: '' },
|
|
10
|
-
|
|
11
|
-
// Variabel
|
|
12
9
|
{ asal: /ono\s/g, jadi: 'let ' },
|
|
13
10
|
{ asal: /paten\s/g, jadi: 'const ' },
|
|
14
|
-
|
|
15
|
-
// Logic
|
|
16
11
|
{ asal: /gawe\s/g, jadi: 'function ' },
|
|
17
12
|
{ asal: /yen\s/g, jadi: 'if ' },
|
|
18
13
|
{ asal: /liyane/g, jadi: 'else' },
|
|
19
14
|
{ asal: /mandek;/g, jadi: 'return;' },
|
|
20
|
-
|
|
21
|
-
// Operator
|
|
22
15
|
{ asal: /ora\s/g, jadi: '!' },
|
|
23
16
|
{ asal: /panjang\(/g, jadi: 'len(' },
|
|
24
17
|
];
|
|
25
18
|
|
|
26
|
-
// Script Bantuan (Runtime)
|
|
27
19
|
const runtimeScript = `
|
|
28
20
|
<script>
|
|
29
21
|
function ambil(sel) { return document.querySelector(sel).value; }
|
|
@@ -36,54 +28,99 @@ const runtimeScript = `
|
|
|
36
28
|
</script>
|
|
37
29
|
`;
|
|
38
30
|
|
|
31
|
+
// --- TEMPLATE PROJECT BARU ---
|
|
32
|
+
const boilerplateCode = `<lump>
|
|
33
|
+
<klambi>
|
|
34
|
+
h1 { color: #d35400; font-family: sans-serif; }
|
|
35
|
+
button { padding: 10px 20px; background: #2ecc71; border: none; color: white; cursor: pointer; }
|
|
36
|
+
button:hover { background: #27ae60; }
|
|
37
|
+
</klambi>
|
|
38
|
+
|
|
39
|
+
<kulit>
|
|
40
|
+
<h1>Sugeng Rawuh di LumpiaJS</h1>
|
|
41
|
+
<p>Project anyar siap dimasak!</p>
|
|
42
|
+
<button onclick="sapa()">Pencet Aku</button>
|
|
43
|
+
</kulit>
|
|
44
|
+
|
|
45
|
+
<isi>
|
|
46
|
+
gawe sapa() {
|
|
47
|
+
tampil("Halo! Iki project pertamamu, Bro!");
|
|
48
|
+
}
|
|
49
|
+
</isi>
|
|
50
|
+
</lump>`;
|
|
51
|
+
|
|
39
52
|
async function main() {
|
|
40
53
|
const args = process.argv.slice(2);
|
|
41
|
-
const perintah = args[0];
|
|
54
|
+
const perintah = args[0]; // misal: 'create-project' atau 'goreng'
|
|
55
|
+
const parameter = args[1]; // misal: 'tokoku'
|
|
42
56
|
|
|
43
|
-
//
|
|
44
|
-
if (perintah === '
|
|
45
|
-
|
|
57
|
+
// --- FITUR 1: Bikin Project Baru ---
|
|
58
|
+
if (perintah === 'create-project' || perintah === 'buka-cabang') {
|
|
59
|
+
const namaProject = parameter;
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
if (!namaProject) {
|
|
62
|
+
console.log('❌ Eh, jeneng project-e opo?');
|
|
63
|
+
console.log('Contoh: lumpia create-project warung-baru');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
49
66
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
const projectPath = path.join(process.cwd(), namaProject);
|
|
68
|
+
const srcPath = path.join(projectPath, 'src');
|
|
69
|
+
|
|
70
|
+
if (fs.existsSync(projectPath)) {
|
|
71
|
+
console.log(`⚠️ Waduh, folder "${namaProject}" wis ono, Bro. Ganti jeneng liyo.`);
|
|
53
72
|
return;
|
|
54
73
|
}
|
|
55
74
|
|
|
56
|
-
|
|
75
|
+
console.log(`🔨 Lagi nyiapke lahan kanggo "${namaProject}"...`);
|
|
76
|
+
|
|
77
|
+
// 1. Bikin Folder Utama
|
|
78
|
+
fs.mkdirSync(projectPath);
|
|
79
|
+
|
|
80
|
+
// 2. Bikin Folder src
|
|
81
|
+
fs.mkdirSync(srcPath);
|
|
82
|
+
|
|
83
|
+
// 3. Tulis file contoh (Boilerplate)
|
|
84
|
+
fs.writeFileSync(path.join(srcPath, 'app.lmp'), boilerplateCode);
|
|
85
|
+
|
|
86
|
+
console.log('✅ Siap, Juragan! Project wis dadi.');
|
|
87
|
+
console.log('-------------------------------------------');
|
|
88
|
+
console.log(`cd ${namaProject}`);
|
|
89
|
+
console.log('lumpia goreng');
|
|
90
|
+
console.log('-------------------------------------------');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// --- FITUR 2: Compile (Goreng) ---
|
|
94
|
+
else if (perintah === 'goreng') {
|
|
95
|
+
console.log('🍳 Sik, lagi nggoreng kodingan...');
|
|
96
|
+
const srcDir = './src';
|
|
97
|
+
const distDir = './dist';
|
|
98
|
+
|
|
99
|
+
if (!fs.existsSync(srcDir)) return console.log('❌ Folder src ora ono! (Coba: lumpia create-project namaproject)');
|
|
57
100
|
if (!fs.existsSync(distDir)) fs.mkdirSync(distDir);
|
|
58
101
|
|
|
59
|
-
// Baca file .lmp
|
|
60
102
|
const files = fs.readdirSync(srcDir).filter(file => file.endsWith('.lmp'));
|
|
61
103
|
|
|
62
|
-
if (files.length === 0) {
|
|
63
|
-
console.log('⚠️ Gak ono file .lmp nang folder src.');
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
104
|
files.forEach(file => {
|
|
68
105
|
let content = fs.readFileSync(path.join(srcDir, file), 'utf-8');
|
|
69
106
|
|
|
70
|
-
// Pisah Kulit & Isi
|
|
71
107
|
const matchKulit = content.match(/<kulit>([\s\S]*?)<\/kulit>/);
|
|
72
108
|
const matchIsi = content.match(/<isi>([\s\S]*?)<\/isi>/);
|
|
109
|
+
const matchKlambi = content.match(/<klambi>([\s\S]*?)<\/klambi>/);
|
|
73
110
|
|
|
74
111
|
let htmlnya = matchKulit ? matchKulit[1] : '';
|
|
75
112
|
let logicnya = matchIsi ? matchIsi[1] : '';
|
|
113
|
+
let cssnya = matchKlambi ? matchKlambi[1] : '';
|
|
76
114
|
|
|
77
|
-
|
|
78
|
-
dictionary.forEach(kata => {
|
|
79
|
-
logicnya = logicnya.replace(kata.asal, kata.jadi);
|
|
80
|
-
});
|
|
115
|
+
dictionary.forEach(kata => logicnya = logicnya.replace(kata.asal, kata.jadi));
|
|
81
116
|
|
|
82
|
-
// Gabung jadi HTML
|
|
83
117
|
const hasil = `<!DOCTYPE html>
|
|
84
118
|
<html>
|
|
85
|
-
<head
|
|
86
|
-
<
|
|
119
|
+
<head>
|
|
120
|
+
<title>Lumpia App</title>
|
|
121
|
+
<style>body{font-family:sans-serif;padding:20px;} ${cssnya}</style>
|
|
122
|
+
</head>
|
|
123
|
+
<body>
|
|
87
124
|
${htmlnya}
|
|
88
125
|
<div id="output-lumpia" style="margin-top:20px; font-weight:bold;"></div>
|
|
89
126
|
${runtimeScript}
|
|
@@ -91,14 +128,14 @@ async function main() {
|
|
|
91
128
|
</body>
|
|
92
129
|
</html>`;
|
|
93
130
|
|
|
94
|
-
// Simpan
|
|
95
131
|
const namaFileBaru = file.replace('.lmp', '.html');
|
|
96
132
|
fs.writeFileSync(path.join(distDir, namaFileBaru), hasil);
|
|
97
133
|
console.log(`✅ Mateng: dist/${namaFileBaru}`);
|
|
98
134
|
});
|
|
99
|
-
|
|
100
135
|
} else {
|
|
101
|
-
console.log('
|
|
136
|
+
console.log('Perintah ora dikenal.');
|
|
137
|
+
console.log('1. lumpia create-project <nama>');
|
|
138
|
+
console.log('2. lumpia goreng');
|
|
102
139
|
}
|
|
103
140
|
}
|
|
104
141
|
|
package/package.json
CHANGED