@flazhost-nodeadmin/create-app 1.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 (3) hide show
  1. package/README.md +35 -0
  2. package/index.js +88 -0
  3. package/package.json +19 -0
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @flazhost-nodeadmin/create-app
2
+
3
+ Scaffolder untuk membuat aplikasi [NodeAdmin](https://github.com/NodeJsTech-Id/NodeAdmin) lengkap dalam satu perintah.
4
+
5
+ ## Penggunaan
6
+
7
+ ```bash
8
+ npm create @flazhost-nodeadmin/app myapp
9
+ ```
10
+
11
+ (atau `npm init @flazhost-nodeadmin/app myapp`, `yarn create @flazhost-nodeadmin/app myapp`, `pnpm create @flazhost-nodeadmin/app myapp`)
12
+
13
+ Tanpa argumen nama → akan ditanya interaktif.
14
+
15
+ ## Yang dihasilkan
16
+
17
+ Aplikasi admin panel utuh (TypeScript + Express + TypeORM): auth, RBAC (user/role/permission), profile, setting + template switcher, views EJS, migrations + seed admin. Runtime generik berasal dari paket [`@flazhost-nodeadmin/core`](https://www.npmjs.com/package/@flazhost-nodeadmin/core) + [`@flazhost-nodeadmin/cli`](https://www.npmjs.com/package/@flazhost-nodeadmin/cli) (ditarik dari npm), sehingga update runtime cukup `npm update`.
18
+
19
+ Default database: **SQLite** (zero-setup) — ganti via `.env`.
20
+
21
+ ## Setelah scaffold
22
+
23
+ ```bash
24
+ cd myapp
25
+ npm install
26
+ cp .env.example .env
27
+ npm run migration:run # tabel + seed admin & setting
28
+ npm run start:dev # http://localhost:3000
29
+ ```
30
+
31
+ Login default: `admin@admin.com` / `12345678`.
32
+
33
+ ## Lisensi
34
+
35
+ ISC
package/index.js ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @flazhost-nodeadmin/create-app
4
+ *
5
+ * Scaffolder: `npm create @flazhost-nodeadmin/app myapp`
6
+ * Menarik template aplikasi NodeAdmin standalone dari GitHub (folder template/
7
+ * pada tag tertentu) via giget, lalu menyiapkan project siap jalan.
8
+ */
9
+ const fs = require('fs')
10
+ const path = require('path')
11
+ const prompts = require('prompts')
12
+ const pc = require('picocolors')
13
+ const { downloadTemplate } = require('giget')
14
+
15
+ // Sumber template di GitHub. Di-pin ke tag agar versi CLI ↔ template deterministik.
16
+ // Format giget: github:<owner>/<repo>/<subdir>#<ref>
17
+ const TEMPLATE_TAG = 'template-v1.0.0'
18
+ const TEMPLATE_SRC = `github:NodeJsTech-Id/NodeAdmin/template#${TEMPLATE_TAG}`
19
+
20
+ async function main() {
21
+ const argDir = process.argv.slice(2).find((a) => !a.startsWith('-'))
22
+
23
+ let targetName = argDir
24
+ if (!targetName) {
25
+ const res = await prompts({
26
+ type: 'text',
27
+ name: 'name',
28
+ message: 'Nama project',
29
+ initial: 'nodeadmin-app',
30
+ })
31
+ targetName = res.name
32
+ }
33
+ if (!targetName) {
34
+ console.error(pc.red('✖ Nama project wajib diisi.'))
35
+ process.exit(1)
36
+ }
37
+
38
+ const targetDir = path.resolve(process.cwd(), targetName)
39
+
40
+ if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
41
+ console.error(pc.red(`✖ Folder "${targetName}" sudah ada dan tidak kosong.`))
42
+ process.exit(1)
43
+ }
44
+
45
+ console.log(pc.cyan(`\n⏬ Mengunduh template NodeAdmin ke ${pc.bold(targetName)}/ ...`))
46
+ try {
47
+ await downloadTemplate(TEMPLATE_SRC, { dir: targetDir, force: true })
48
+ } catch (err) {
49
+ console.error(pc.red('✖ Gagal mengunduh template:'), err.message)
50
+ console.error(pc.dim(` Sumber: ${TEMPLATE_SRC}`))
51
+ process.exit(1)
52
+ }
53
+
54
+ // Set nama package sesuai folder user.
55
+ const pkgPath = path.join(targetDir, 'package.json')
56
+ try {
57
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
58
+ pkg.name = sanitizeName(targetName)
59
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
60
+ } catch {
61
+ // non-fatal — template tetap berfungsi tanpa rename.
62
+ }
63
+
64
+ printNextSteps(targetName)
65
+ }
66
+
67
+ function sanitizeName(name) {
68
+ return String(name).trim().toLowerCase()
69
+ .replace(/[^a-z0-9-~._]/g, '-')
70
+ .replace(/^-+|-+$/g, '') || 'nodeadmin-app'
71
+ }
72
+
73
+ function printNextSteps(name) {
74
+ console.log(pc.green('\n✔ Selesai! Aplikasi NodeAdmin siap.\n'))
75
+ console.log('Langkah berikutnya:\n')
76
+ console.log(pc.cyan(` cd ${name}`))
77
+ console.log(pc.cyan(' npm install'))
78
+ console.log(pc.cyan(' cp .env.example .env') + pc.dim(' # default: SQLite (tanpa server DB)'))
79
+ console.log(pc.cyan(' npm run migration:run') + pc.dim(' # buat tabel + seed admin & setting'))
80
+ console.log(pc.cyan(' npm run start:dev') + pc.dim(' # http://localhost:3000'))
81
+ console.log('\nLogin default: ' + pc.bold('admin@admin.com') + ' / ' + pc.bold('12345678'))
82
+ console.log(pc.dim('(ganti password admin sebelum production)\n'))
83
+ }
84
+
85
+ main().catch((err) => {
86
+ console.error(pc.red('✖ Error:'), err)
87
+ process.exit(1)
88
+ })
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@flazhost-nodeadmin/create-app",
3
+ "version": "1.0.0",
4
+ "description": "Scaffolder aplikasi NodeAdmin — `npm create @flazhost-nodeadmin/app myapp`.",
5
+ "license": "ISC",
6
+ "type": "commonjs",
7
+ "bin": {
8
+ "create-app": "index.js"
9
+ },
10
+ "main": "index.js",
11
+ "files": [
12
+ "index.js"
13
+ ],
14
+ "dependencies": {
15
+ "giget": "^1.2.3",
16
+ "prompts": "^2.4.2",
17
+ "picocolors": "^1.1.0"
18
+ }
19
+ }