minimaz-cli 0.1.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 +7 -0
- package/README.md +107 -0
- package/bin/cli.ts +80 -0
- package/dist/LICENSE +7 -0
- package/dist/README.md +103 -0
- package/dist/bin/cli.js +2 -0
- package/dist/package.json +42 -0
- package/package.json +57 -0
- package/src/commands/build.ts +176 -0
- package/src/commands/help.ts +33 -0
- package/src/commands/init.ts +56 -0
- package/src/commands/template.ts +146 -0
- package/src/templates/default/minimaz.config.json +26 -0
- package/src/templates/default/public/assets/.gitkeep +0 -0
- package/src/templates/default/public/favicon.ico +0 -0
- package/src/templates/default/src/index.html +80 -0
- package/src/templates/default/src/pages/about.html +46 -0
- package/src/templates/default/src/script.js +1 -0
- package/src/templates/default/src/style.css +99 -0
- package/src/templates/gitignore +2 -0
- package/src/templates/simple/minimaz.config.json +26 -0
- package/src/templates/simple/public/assets/.gitkeep +0 -0
- package/src/templates/simple/public/favicon.ico +0 -0
- package/src/templates/simple/src/index.html +15 -0
- package/src/templates/simple/src/pages/page.html +11 -0
- package/src/templates/simple/src/script.js +1 -0
- package/src/templates/simple/src/style.css +0 -0
- package/src/utils/functions.ts +161 -0
- package/src/utils/loadConfig.ts +61 -0
- package/src/utils/logService.ts +19 -0
- package/src/utils/postInstall.ts +16 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { log } from './logService.js'
|
|
4
|
+
|
|
5
|
+
// ----- Default Config -----
|
|
6
|
+
// Provides default values for project build and minification
|
|
7
|
+
const defaultConfig: any = {
|
|
8
|
+
src: 'src',
|
|
9
|
+
dist: 'dist',
|
|
10
|
+
public: 'public',
|
|
11
|
+
minify: {
|
|
12
|
+
html: true,
|
|
13
|
+
css: true,
|
|
14
|
+
js: true
|
|
15
|
+
},
|
|
16
|
+
replace: {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// ----- Deep Merge Function -----
|
|
20
|
+
// Recursively merges user config into default config
|
|
21
|
+
function deepMerge(target: any, source: any): any {
|
|
22
|
+
const result: any = { ...target }
|
|
23
|
+
|
|
24
|
+
for (const key in source) {
|
|
25
|
+
if (
|
|
26
|
+
source[key] &&
|
|
27
|
+
typeof source[key] === 'object' &&
|
|
28
|
+
!Array.isArray(source[key])
|
|
29
|
+
) {
|
|
30
|
+
result[key] = deepMerge(target[key] || {}, source[key])
|
|
31
|
+
} else if (source[key] !== undefined) {
|
|
32
|
+
result[key] = source[key]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return result
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ----- Load User Config -----
|
|
40
|
+
// Loads minimaz.config.tson if present and merges it with default config
|
|
41
|
+
export async function loadConfig(): Promise<any> {
|
|
42
|
+
const configPath: string = path.resolve(process.cwd(), 'minimaz.config.json')
|
|
43
|
+
|
|
44
|
+
let userConfig: Partial<any> = {}
|
|
45
|
+
if (await fs.pathExists(configPath)) {
|
|
46
|
+
try {
|
|
47
|
+
userConfig = await fs.readJson(configPath)
|
|
48
|
+
log('info', 'Loaded config from minimaz.config.tson')
|
|
49
|
+
} catch (error: any) {
|
|
50
|
+
throw new Error(`Failed to parse minimaz.config.tson: ${error.message}`)
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
log('info', 'No minimaz.config.tson found. Using default config')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const config: any = deepMerge(defaultConfig, userConfig)
|
|
57
|
+
|
|
58
|
+
if (!config.src || !config.dist) throw new Error('Invalid configuration: src and dist are required')
|
|
59
|
+
|
|
60
|
+
return config
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// ----- Log Types -----
|
|
2
|
+
type LogType = 'error' | 'warn' | 'success' | 'info' | 'log'
|
|
3
|
+
|
|
4
|
+
// ----- Log Function -----
|
|
5
|
+
// Prints a message to console with icon based on type
|
|
6
|
+
export function log(type: LogType = 'log', message: string): void {
|
|
7
|
+
const icons: Record<LogType, string> = {
|
|
8
|
+
error: '❌',
|
|
9
|
+
warn: '⚠️',
|
|
10
|
+
success: '✅',
|
|
11
|
+
info: 'ℹ️',
|
|
12
|
+
log: '📁' // default icon
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Use console.error/console.warn only for error and warn
|
|
16
|
+
if (type === 'error') console.error(icons[type], message)
|
|
17
|
+
else if (type === 'warn') console.warn(icons[type], message)
|
|
18
|
+
else console.log(icons[type] || icons.log, message)
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createGlobalDir } from './functions.js'
|
|
2
|
+
import { log } from './logService.js'
|
|
3
|
+
|
|
4
|
+
// ----- Setup Default Templates -----
|
|
5
|
+
// Runs after install to ensure global templates exist
|
|
6
|
+
async function setupDefaultTemplates(): Promise<void> {
|
|
7
|
+
try {
|
|
8
|
+
await createGlobalDir()
|
|
9
|
+
log('success', 'Postinstall: Global templates setup completed.')
|
|
10
|
+
} catch (error: any) {
|
|
11
|
+
log('error', `Postinstall setup failed: ${error.message}`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Execute setup
|
|
16
|
+
setupDefaultTemplates()
|