@fluffjs/cli 0.0.1 → 0.0.3
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/Cli.js +9 -11
- package/Generator.d.ts +1 -0
- package/Generator.js +15 -2
- package/IndexHtmlTransformer.js +32 -32
- package/package.json +3 -3
- package/types/FluffConfig.d.ts +29 -0
- package/types/FluffConfig.js +24 -0
package/Cli.js
CHANGED
|
@@ -294,7 +294,7 @@ Examples:
|
|
|
294
294
|
}
|
|
295
295
|
const entryPoint = target.entryPoint
|
|
296
296
|
? path.join(srcDir, target.entryPoint)
|
|
297
|
-
:
|
|
297
|
+
: this.generateEntryPoint(srcDir, target.components);
|
|
298
298
|
console.log(' Building with esbuild...');
|
|
299
299
|
const result = await esbuild.build({
|
|
300
300
|
entryPoints: [entryPoint],
|
|
@@ -409,25 +409,23 @@ Examples:
|
|
|
409
409
|
throw new Error(`fluff.json not found at ${configPath}. Run 'fluff init' first.`);
|
|
410
410
|
}
|
|
411
411
|
const config = this.loadConfigFrom(configPath);
|
|
412
|
-
let target;
|
|
412
|
+
let target = undefined;
|
|
413
413
|
if (targetOrProject) {
|
|
414
|
-
|
|
415
|
-
if (!
|
|
414
|
+
target = config.targets[targetOrProject];
|
|
415
|
+
if (!target) {
|
|
416
416
|
console.error(`Target '${targetOrProject}' not found in fluff.json`);
|
|
417
417
|
process.exit(1);
|
|
418
418
|
}
|
|
419
|
-
target = t;
|
|
420
419
|
}
|
|
421
420
|
else if (config.defaultTarget) {
|
|
422
|
-
|
|
423
|
-
if (!
|
|
421
|
+
target = config.targets[config.defaultTarget];
|
|
422
|
+
if (!target) {
|
|
424
423
|
console.error(`Default target '${config.defaultTarget}' not found in fluff.json`);
|
|
425
424
|
process.exit(1);
|
|
426
425
|
}
|
|
427
|
-
target = t;
|
|
428
426
|
}
|
|
429
427
|
else {
|
|
430
|
-
target = Object.values(config.targets)
|
|
428
|
+
[target] = Object.values(config.targets);
|
|
431
429
|
if (!target) {
|
|
432
430
|
console.error('No targets found in fluff.json');
|
|
433
431
|
process.exit(1);
|
|
@@ -449,7 +447,7 @@ Examples:
|
|
|
449
447
|
const host = serveOptions.host ?? 'localhost';
|
|
450
448
|
const entryPoint = target.entryPoint
|
|
451
449
|
? path.join(srcDir, target.entryPoint)
|
|
452
|
-
:
|
|
450
|
+
: this.generateEntryPoint(srcDir, target.components);
|
|
453
451
|
if (target.indexHtml) {
|
|
454
452
|
const indexHtmlPath = path.join(srcDir, target.indexHtml);
|
|
455
453
|
if (fs.existsSync(indexHtmlPath)) {
|
|
@@ -511,7 +509,7 @@ Examples:
|
|
|
511
509
|
console.log(` Server running at http://${hosts[0]}:${actualPort}`);
|
|
512
510
|
console.log(' Press Ctrl+C to stop\n');
|
|
513
511
|
}
|
|
514
|
-
|
|
512
|
+
generateEntryPoint(srcDir, componentPatterns) {
|
|
515
513
|
const componentFiles = this.findFiles(srcDir, componentPatterns);
|
|
516
514
|
const imports = componentFiles.map(f => {
|
|
517
515
|
const relativePath = './' + path.relative(srcDir, f)
|
package/Generator.d.ts
CHANGED
package/Generator.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
5
|
export class Generator {
|
|
4
6
|
generate(options) {
|
|
5
7
|
const { appName, outputDir } = options;
|
|
@@ -62,6 +64,7 @@ export class Generator {
|
|
|
62
64
|
.join(' ');
|
|
63
65
|
}
|
|
64
66
|
getPackageJson(name) {
|
|
67
|
+
const cliVersion = this.getCliVersion();
|
|
65
68
|
return JSON.stringify({
|
|
66
69
|
name,
|
|
67
70
|
version: '0.0.1',
|
|
@@ -72,14 +75,24 @@ export class Generator {
|
|
|
72
75
|
serve: 'npx @fluffjs/cli serve'
|
|
73
76
|
},
|
|
74
77
|
dependencies: {
|
|
75
|
-
'@fluffjs/fluff':
|
|
78
|
+
'@fluffjs/fluff': `^${cliVersion}`
|
|
76
79
|
},
|
|
77
80
|
devDependencies: {
|
|
78
|
-
'@fluffjs/cli':
|
|
81
|
+
'@fluffjs/cli': `^${cliVersion}`,
|
|
79
82
|
typescript: '^5.0.0'
|
|
80
83
|
}
|
|
81
84
|
}, null, 2) + '\n';
|
|
82
85
|
}
|
|
86
|
+
getCliVersion() {
|
|
87
|
+
const pkgPath = path.join(__dirname, 'package.json');
|
|
88
|
+
if (fs.existsSync(pkgPath)) {
|
|
89
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
90
|
+
if (typeof pkg === 'object' && pkg !== null && 'version' in pkg && typeof pkg.version === 'string') {
|
|
91
|
+
return pkg.version;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return '0.0.1';
|
|
95
|
+
}
|
|
83
96
|
getTsConfig() {
|
|
84
97
|
return JSON.stringify({
|
|
85
98
|
compilerOptions: {
|
package/IndexHtmlTransformer.js
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
import { minify } from 'html-minifier-terser';
|
|
2
2
|
import * as parse5 from 'parse5';
|
|
3
3
|
import { html as parse5Html } from 'parse5';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const jsSrc = options.gzip ? `${options.jsBundle}.gz` : options.jsBundle;
|
|
7
|
-
const cssSrc = options.cssBundle
|
|
8
|
-
? (options.gzip ? `${options.cssBundle}.gz` : options.cssBundle)
|
|
9
|
-
: null;
|
|
10
|
-
const head = findElement(doc, 'head');
|
|
11
|
-
const body = findElement(doc, 'body');
|
|
12
|
-
if (head && cssSrc) {
|
|
13
|
-
appendChild(head, createLinkElement(cssSrc));
|
|
14
|
-
}
|
|
15
|
-
if (body) {
|
|
16
|
-
appendChild(body, createScriptElement(jsSrc));
|
|
17
|
-
}
|
|
18
|
-
let result = parse5.serialize(doc);
|
|
19
|
-
if (options.liveReload) {
|
|
20
|
-
result = result.replace('</body>', getLiveReloadScript() + '</body>');
|
|
21
|
-
}
|
|
22
|
-
if (options.minify) {
|
|
23
|
-
result = await minify(result, {
|
|
24
|
-
collapseWhitespace: true,
|
|
25
|
-
removeComments: true,
|
|
26
|
-
removeRedundantAttributes: true,
|
|
27
|
-
removeEmptyAttributes: true,
|
|
28
|
-
minifyCSS: true,
|
|
29
|
-
minifyJS: true
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
4
|
+
function isElement(node) {
|
|
5
|
+
return 'tagName' in node;
|
|
33
6
|
}
|
|
34
7
|
function findElement(node, tagName) {
|
|
35
8
|
if (isElement(node) && node.tagName === tagName) {
|
|
@@ -44,9 +17,6 @@ function findElement(node, tagName) {
|
|
|
44
17
|
}
|
|
45
18
|
return null;
|
|
46
19
|
}
|
|
47
|
-
function isElement(node) {
|
|
48
|
-
return 'tagName' in node;
|
|
49
|
-
}
|
|
50
20
|
function appendChild(parent, child) {
|
|
51
21
|
child.parentNode = parent;
|
|
52
22
|
parent.childNodes.push(child);
|
|
@@ -95,3 +65,33 @@ function getLiveReloadScript() {
|
|
|
95
65
|
location.reload();
|
|
96
66
|
});</script>`;
|
|
97
67
|
}
|
|
68
|
+
export async function transformIndexHtml(html, options) {
|
|
69
|
+
const doc = parse5.parse(html);
|
|
70
|
+
const jsSrc = options.gzip ? `${options.jsBundle}.gz` : options.jsBundle;
|
|
71
|
+
const cssSrc = options.cssBundle
|
|
72
|
+
? (options.gzip ? `${options.cssBundle}.gz` : options.cssBundle)
|
|
73
|
+
: null;
|
|
74
|
+
const head = findElement(doc, 'head');
|
|
75
|
+
const body = findElement(doc, 'body');
|
|
76
|
+
if (head && cssSrc) {
|
|
77
|
+
appendChild(head, createLinkElement(cssSrc));
|
|
78
|
+
}
|
|
79
|
+
if (body) {
|
|
80
|
+
appendChild(body, createScriptElement(jsSrc));
|
|
81
|
+
}
|
|
82
|
+
let result = parse5.serialize(doc);
|
|
83
|
+
if (options.liveReload) {
|
|
84
|
+
result = result.replace('</body>', getLiveReloadScript() + '</body>');
|
|
85
|
+
}
|
|
86
|
+
if (options.minify) {
|
|
87
|
+
result = await minify(result, {
|
|
88
|
+
collapseWhitespace: true,
|
|
89
|
+
removeComments: true,
|
|
90
|
+
removeRedundantAttributes: true,
|
|
91
|
+
removeEmptyAttributes: true,
|
|
92
|
+
minifyCSS: true,
|
|
93
|
+
minifyJS: true
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluffjs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"**/*.js",
|
|
21
|
+
"**/*.d.ts",
|
|
22
22
|
"!*.tsbuildinfo"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface BundleOptions {
|
|
2
|
+
minify?: boolean;
|
|
3
|
+
splitting?: boolean;
|
|
4
|
+
target?: string;
|
|
5
|
+
gzip?: boolean;
|
|
6
|
+
external?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ServeOptions {
|
|
9
|
+
port?: number;
|
|
10
|
+
host?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface FluffTarget {
|
|
13
|
+
name: string;
|
|
14
|
+
srcDir: string;
|
|
15
|
+
outDir: string;
|
|
16
|
+
entryPoint?: string;
|
|
17
|
+
indexHtml?: string;
|
|
18
|
+
components: string[];
|
|
19
|
+
assets?: string[];
|
|
20
|
+
bundle?: BundleOptions;
|
|
21
|
+
serve?: ServeOptions;
|
|
22
|
+
}
|
|
23
|
+
export interface FluffConfig {
|
|
24
|
+
version: string;
|
|
25
|
+
targets: Record<string, FluffTarget>;
|
|
26
|
+
defaultTarget?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const DEFAULT_CONFIG: FluffConfig;
|
|
29
|
+
//# sourceMappingURL=FluffConfig.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const DEFAULT_CONFIG = {
|
|
2
|
+
version: '1.0',
|
|
3
|
+
targets: {
|
|
4
|
+
app: {
|
|
5
|
+
name: 'app',
|
|
6
|
+
srcDir: 'src',
|
|
7
|
+
outDir: 'dist',
|
|
8
|
+
entryPoint: 'main.ts',
|
|
9
|
+
indexHtml: 'index.html',
|
|
10
|
+
components: ['**/*.component.ts'],
|
|
11
|
+
assets: ['**/*.html', '**/*.css'],
|
|
12
|
+
bundle: {
|
|
13
|
+
minify: true,
|
|
14
|
+
gzip: true,
|
|
15
|
+
target: 'es2022'
|
|
16
|
+
},
|
|
17
|
+
serve: {
|
|
18
|
+
port: 3000,
|
|
19
|
+
host: 'localhost'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
defaultTarget: 'app'
|
|
24
|
+
};
|