minimaz-cli 0.1.0 → 0.1.1

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.
@@ -1,26 +0,0 @@
1
- {
2
- "src": "src",
3
- "dist": "dist",
4
- "public": "public",
5
- "minify": {
6
- "html": true,
7
- "css": true,
8
- "js": true,
9
- "ts": true
10
- },
11
- "replace": {
12
- "../public/": "public/"
13
- },
14
- "styles": [
15
- "style.css",
16
- "style-2.css"
17
- ],
18
- "scripts": [
19
- "script.js",
20
- "script-2.js"
21
- ],
22
- "folders": {
23
- "src": "",
24
- "public": "public"
25
- }
26
- }
File without changes
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Welcome to Minimaz</title>
8
- <link rel="stylesheet" href="style.css" />
9
- </head>
10
-
11
- <body>
12
- <script src="script.js"></script>
13
- </body>
14
-
15
- </html>
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Document</title>
7
- </head>
8
- <body>
9
-
10
- </body>
11
- </html>
@@ -1 +0,0 @@
1
- console.log('Minimaz is ready!')
File without changes
@@ -1,161 +0,0 @@
1
- import readline from 'readline'
2
- import fs from 'fs-extra'
3
- import path from 'path'
4
- import os from 'os'
5
- import { log } from './logService.js'
6
- import { execSync } from 'child_process'
7
-
8
- // ----- Types -----
9
- interface Args {
10
- _: string[]
11
- [key: string]: string | boolean | string[]
12
- }
13
-
14
- // ----- Parse CLI Arguments -----
15
- // Converts raw process arguments into structured key-value pairs
16
- export function parseArgs(rawArgs: string[]): Args {
17
- const args: Args = { _: [] }
18
- for (let i = 0; i < rawArgs.length; i++) {
19
- const arg: string = rawArgs[i]
20
- if (arg.startsWith('-')) {
21
- const key: string = arg.startsWith('--') ? arg.slice(2) : arg.slice(1)
22
- const next: string = rawArgs[i + 1]
23
- const hasValue: boolean = !!next && !next.startsWith('-')
24
- args[key] = hasValue ? next : true
25
- if (hasValue) i++
26
- } else {
27
- args._.push(arg)
28
- }
29
- }
30
- return args
31
- }
32
-
33
- // ----- Ask Question from CLI -----
34
- // Prompts the user with a question and returns the input
35
- export function askQuestion(query: string): Promise<string> {
36
- return new Promise(resolve => {
37
- const rl: readline.Interface = readline.createInterface({
38
- input: process.stdin,
39
- output: process.stdout
40
- })
41
- rl.question(query, answer => {
42
- rl.close()
43
- resolve(answer.trim())
44
- })
45
- })
46
- }
47
-
48
- // ----- List Templates -----
49
- // Displays all available global templates in the given directory
50
- export async function listTemplates(dir: string): Promise<void> {
51
- if (!await fs.pathExists(dir)) {
52
- log('info', 'No templates directory found.')
53
- return
54
- }
55
-
56
- const templates: string[] = await fs.readdir(dir)
57
- if (templates.length === 0) log('info', 'No global templates available.')
58
- else {
59
- log('info', 'Available global templates:')
60
- templates.forEach(t => log('info', `- ${t}`))
61
- }
62
- }
63
-
64
- // ----- Apply Replacements -----
65
- // Replaces all occurrences of keys in content with their corresponding values
66
- export function applyReplacements(content: string, replacements: Record<string, string> = {}): string {
67
- for (const [from, to] of Object.entries(replacements)) {
68
- content = content.split(from).join(to)
69
- }
70
- return content
71
- }
72
-
73
- // ----- Read File with Replacements -----
74
- // Reads a file and applies string replacements if provided
75
- export async function getFile(srcPath: string, replace?: Record<string, string>): Promise<string> {
76
- try {
77
- let file: string = await fs.readFile(srcPath, 'utf-8')
78
- if (replace) file = applyReplacements(file, replace)
79
- return file
80
- } catch (error: any) {
81
- log('error', `Failed to read file ${srcPath}: ${error.message}`)
82
- return ''
83
- }
84
- }
85
-
86
- // ----- Global Node Modules Path -----
87
- // Returns the path to global node_modules depending on the platform
88
-
89
- export function getGlobalNodeModulesPath(): string {
90
- try {
91
- const prefix = execSync('npm config get prefix', { encoding: 'utf-8' }).trim();
92
- if (!prefix) throw new Error('Empty prefix');
93
- return process.platform === 'win32'
94
- ? path.join(prefix, 'node_modules', 'minimaz-cli')
95
- : path.join(prefix, 'lib', 'node_modules', 'minimaz-cli');
96
- } catch {
97
- // fallback
98
- return process.platform === 'win32'
99
- ? path.join(process.env.APPDATA || '', 'npm', 'node_modules', 'minimaz-cli')
100
- : '/usr/local/lib/node_modules/minimaz-cli';
101
- }
102
- }
103
-
104
-
105
- // ----- Create Global Templates Folder -----
106
- // Creates ~/.minimaz/templates and copies default templates if folder is empty
107
- export async function createGlobalDir(): Promise<void> {
108
- const minimazDir = path.join(os.homedir(), '.minimaz')
109
- const globalTemplatesDir = path.join(minimazDir, 'templates')
110
- const defaultTemplatesDir = path.join(getGlobalNodeModulesPath(), 'src', 'templates')
111
- const settingsPath = path.join(minimazDir, 'settings.json')
112
-
113
- console.log(defaultTemplatesDir)
114
-
115
- // ----- Ensure node_modules path exists (fallback for portable setups) -----
116
-
117
- try {
118
- // ----- Ensure minimaz dir exists -----
119
- await fs.ensureDir(minimazDir)
120
-
121
- // ----- Create settings.json if missing -----
122
- if (!await fs.pathExists(settingsPath)) {
123
- const defaultSettings = {
124
- createdAt: new Date().toISOString(),
125
- templatesPath: globalTemplatesDir,
126
- npmGlobalPath: getGlobalNodeModulesPath()
127
- }
128
- await fs.outputJson(settingsPath, defaultSettings, { spaces: 2 })
129
- log('success', `Created settings.json at ${settingsPath}`)
130
- }
131
-
132
- // ----- Check if templates folder exists -----
133
- const exists = await fs.pathExists(globalTemplatesDir)
134
- const isEmpty = exists ? (await fs.readdir(globalTemplatesDir)).length === 0 : true
135
-
136
- if (!exists) {
137
- await fs.ensureDir(globalTemplatesDir)
138
- log('success', 'Created global templates directory.')
139
- }
140
-
141
- // ----- Skip copy if not empty -----
142
- if (!isEmpty) {
143
- log('info', 'Global templates directory not empty. Skipping copy.')
144
- return
145
- }
146
-
147
- const templates: string[] = await fs.readdir(defaultTemplatesDir)
148
-
149
- console.log(templates)
150
- // ----- Copy default templates -----
151
- for (const name of await fs.readdir(defaultTemplatesDir)) {
152
- await fs.copy(path.join(defaultTemplatesDir, name), path.join(globalTemplatesDir, name))
153
- log('success', `Copied template '${name}'.`)
154
- }
155
-
156
- log('success', 'Default templates setup completed.')
157
- } catch (error: any) {
158
- log('error', `Failed to create global templates directory: ${error.message}`)
159
- throw error
160
- }
161
- }
@@ -1,61 +0,0 @@
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
- }
@@ -1,19 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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()