@fluffjs/cli 0.1.0 → 0.1.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/Cli.d.ts +2 -0
- package/Cli.js +18 -2
- package/ComponentCompiler.js +6 -1
- package/Generator.js +1 -0
- package/IndexHtmlTransformer.js +2 -2
- package/Parse5Helpers.d.ts +1 -0
- package/Parse5Helpers.js +14 -0
- package/interfaces/BundleOptions.d.ts +1 -0
- package/interfaces/CliOptions.d.ts +2 -0
- package/interfaces/FluffTarget.d.ts +1 -0
- package/interfaces/HtmlTransformOptions.d.ts +1 -0
- package/package.json +1 -1
- package/types/FluffConfig.js +1 -0
package/Cli.d.ts
CHANGED
package/Cli.js
CHANGED
|
@@ -15,10 +15,14 @@ export class Cli {
|
|
|
15
15
|
cwd;
|
|
16
16
|
nxPackage;
|
|
17
17
|
noGzip;
|
|
18
|
+
noMinify;
|
|
19
|
+
gzScriptTag;
|
|
18
20
|
constructor(options = {}) {
|
|
19
21
|
this.cwd = options.cwd ?? process.env.INIT_CWD ?? process.cwd();
|
|
20
22
|
this.nxPackage = options.nxPackage;
|
|
21
23
|
this.noGzip = options.noGzip ?? false;
|
|
24
|
+
this.noMinify = options.noMinify ?? false;
|
|
25
|
+
this.gzScriptTag = options.gzScriptTag ?? false;
|
|
22
26
|
}
|
|
23
27
|
async run(args) {
|
|
24
28
|
const [command, ...commandArgs] = args;
|
|
@@ -282,7 +286,7 @@ Examples:
|
|
|
282
286
|
async buildTarget(target, projectRoot, workspaceRoot, projectRelativePath) {
|
|
283
287
|
console.log(`🔨 Building target '${target.name}'...`);
|
|
284
288
|
const srcDir = path.resolve(projectRoot, target.srcDir);
|
|
285
|
-
const appDir = path.join(srcDir, 'app');
|
|
289
|
+
const appDir = path.join(srcDir, target.componentsDir ?? 'app');
|
|
286
290
|
const outDir = (workspaceRoot && projectRelativePath)
|
|
287
291
|
? path.join(workspaceRoot, 'dist', projectRelativePath)
|
|
288
292
|
: path.resolve(projectRoot, target.outDir);
|
|
@@ -296,6 +300,9 @@ Examples:
|
|
|
296
300
|
if (this.noGzip) {
|
|
297
301
|
bundleOptions.gzip = false;
|
|
298
302
|
}
|
|
303
|
+
if (this.noMinify) {
|
|
304
|
+
bundleOptions.minify = false;
|
|
305
|
+
}
|
|
299
306
|
const entryPoint = target.entryPoint
|
|
300
307
|
? path.join(srcDir, target.entryPoint)
|
|
301
308
|
: this.generateEntryPoint(srcDir, target.components);
|
|
@@ -385,6 +392,7 @@ Examples:
|
|
|
385
392
|
cssBundle: cssBundle ? path.basename(cssBundle) : undefined,
|
|
386
393
|
inlineStyles: inlineStyles || undefined,
|
|
387
394
|
gzip: bundleOptions.gzip,
|
|
395
|
+
gzScriptTag: bundleOptions.gzScriptTag ?? this.gzScriptTag,
|
|
388
396
|
minify: bundleOptions.minify
|
|
389
397
|
});
|
|
390
398
|
fs.writeFileSync(path.join(outDir, 'index.html'), transformed);
|
|
@@ -469,7 +477,7 @@ Examples:
|
|
|
469
477
|
}
|
|
470
478
|
async serveTarget(target, projectRoot, workspaceRoot, projectRelativePath) {
|
|
471
479
|
const srcDir = path.resolve(projectRoot, target.srcDir);
|
|
472
|
-
const appDir = path.join(srcDir, 'app');
|
|
480
|
+
const appDir = path.join(srcDir, target.componentsDir ?? 'app');
|
|
473
481
|
const fluffDir = path.join(this.cwd, '.fluff');
|
|
474
482
|
const serveId = randomUUID();
|
|
475
483
|
const outDir = path.join(fluffDir, serveId);
|
|
@@ -648,6 +656,14 @@ Examples:
|
|
|
648
656
|
options.noGzip = true;
|
|
649
657
|
i++;
|
|
650
658
|
}
|
|
659
|
+
else if (arg === '--no-minify') {
|
|
660
|
+
options.noMinify = true;
|
|
661
|
+
i++;
|
|
662
|
+
}
|
|
663
|
+
else if (arg === '--gz-script-tag') {
|
|
664
|
+
options.gzScriptTag = true;
|
|
665
|
+
i++;
|
|
666
|
+
}
|
|
651
667
|
else if (arg?.startsWith('--')) {
|
|
652
668
|
console.error(`Unknown option: ${arg}`);
|
|
653
669
|
process.exit(1);
|
package/ComponentCompiler.js
CHANGED
|
@@ -3,6 +3,7 @@ import { parse } from '@babel/parser';
|
|
|
3
3
|
import * as t from '@babel/types';
|
|
4
4
|
import * as esbuild from 'esbuild';
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
+
import * as parse5 from 'parse5';
|
|
6
7
|
import { minify as minifyHtml } from 'html-minifier-terser';
|
|
7
8
|
import * as path from 'path';
|
|
8
9
|
import { SourceMapConsumer, SourceMapGenerator } from 'source-map';
|
|
@@ -14,6 +15,7 @@ import { generate } from './BabelHelpers.js';
|
|
|
14
15
|
import { CodeGenerator } from './CodeGenerator.js';
|
|
15
16
|
import { ErrorHelpers } from './ErrorHelpers.js';
|
|
16
17
|
import { GetterDependencyExtractor } from './GetterDependencyExtractor.js';
|
|
18
|
+
import { Parse5Helpers } from './Parse5Helpers.js';
|
|
17
19
|
import { TemplateParser } from './TemplateParser.js';
|
|
18
20
|
export class ComponentCompiler {
|
|
19
21
|
componentSelectors = new Set();
|
|
@@ -121,9 +123,12 @@ export class ComponentCompiler {
|
|
|
121
123
|
const gen = new CodeGenerator(this.componentSelectors, selector);
|
|
122
124
|
let generatedHtml = gen.generateHtml(parsed);
|
|
123
125
|
if (minify) {
|
|
126
|
+
const fragment = parse5.parseFragment(generatedHtml);
|
|
127
|
+
Parse5Helpers.removeNonMarkerComments(fragment);
|
|
128
|
+
generatedHtml = parse5.serialize(fragment);
|
|
124
129
|
generatedHtml = await minifyHtml(generatedHtml, {
|
|
125
130
|
collapseWhitespace: true,
|
|
126
|
-
removeComments:
|
|
131
|
+
removeComments: false,
|
|
127
132
|
removeRedundantAttributes: true,
|
|
128
133
|
removeEmptyAttributes: true
|
|
129
134
|
});
|
package/Generator.js
CHANGED
package/IndexHtmlTransformer.js
CHANGED
|
@@ -30,9 +30,9 @@ export class IndexHtmlTransformer {
|
|
|
30
30
|
})();`;
|
|
31
31
|
static async transform(html, options) {
|
|
32
32
|
const doc = parse5.parse(html);
|
|
33
|
-
const jsSrc = options.
|
|
33
|
+
const jsSrc = options.gzScriptTag ? `${options.jsBundle}.gz` : options.jsBundle;
|
|
34
34
|
const cssSrc = options.cssBundle
|
|
35
|
-
? (options.
|
|
35
|
+
? (options.gzScriptTag ? `${options.cssBundle}.gz` : options.cssBundle)
|
|
36
36
|
: null;
|
|
37
37
|
const head = Parse5Helpers.findElement(doc, 'head');
|
|
38
38
|
const body = Parse5Helpers.findElement(doc, 'body');
|
package/Parse5Helpers.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export declare class Parse5Helpers {
|
|
|
12
12
|
static createDocument(): Parse5Document;
|
|
13
13
|
static walkNodes(node: Parse5Node, visitor: Parse5NodeVisitor): void;
|
|
14
14
|
static findElement(node: Parse5Node, tagName: string): Parse5Element | null;
|
|
15
|
+
static removeNonMarkerComments(node: Parse5Node): void;
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=Parse5Helpers.d.ts.map
|
package/Parse5Helpers.js
CHANGED
|
@@ -78,4 +78,18 @@ export class Parse5Helpers {
|
|
|
78
78
|
}
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
|
+
static removeNonMarkerComments(node) {
|
|
82
|
+
if (!('childNodes' in node))
|
|
83
|
+
return;
|
|
84
|
+
const markerPattern = /^\/?(fluff:(if|for|switch|text|break):\d+)$/;
|
|
85
|
+
node.childNodes = node.childNodes.filter(child => {
|
|
86
|
+
if (Typeguards.isCommentNode(child)) {
|
|
87
|
+
return markerPattern.test(child.data);
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
});
|
|
91
|
+
for (const child of node.childNodes) {
|
|
92
|
+
Parse5Helpers.removeNonMarkerComments(child);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
81
95
|
}
|
package/package.json
CHANGED