@fluffjs/cli 0.0.8 → 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/BabelHelpers.d.ts +26 -0
- package/BabelHelpers.js +65 -0
- package/Cli.d.ts +5 -10
- package/Cli.js +123 -52
- package/CodeGenerator.d.ts +53 -39
- package/CodeGenerator.js +330 -725
- package/ComponentCompiler.d.ts +14 -16
- package/ComponentCompiler.js +187 -256
- package/DomPreProcessor.d.ts +36 -0
- package/DomPreProcessor.js +645 -0
- package/ErrorHelpers.d.ts +5 -0
- package/ErrorHelpers.js +8 -0
- package/ExpressionTransformer.d.ts +38 -28
- package/ExpressionTransformer.js +558 -230
- package/Generator.d.ts +1 -5
- package/Generator.js +128 -67
- package/GetterDependencyExtractor.d.ts +4 -0
- package/GetterDependencyExtractor.js +73 -0
- package/IndexHtmlTransformer.d.ts +6 -7
- package/IndexHtmlTransformer.js +82 -88
- package/Parse5Helpers.d.ts +16 -0
- package/Parse5Helpers.js +81 -0
- package/TemplateParser.d.ts +39 -21
- package/TemplateParser.js +462 -268
- package/Typeguards.d.ts +24 -0
- package/Typeguards.js +30 -0
- package/babel-plugin-class-transform.d.ts +3 -18
- package/babel-plugin-class-transform.js +3 -11
- package/babel-plugin-component.d.ts +4 -13
- package/babel-plugin-component.js +7 -0
- package/babel-plugin-imports.d.ts +3 -11
- package/babel-plugin-imports.js +5 -31
- package/babel-plugin-reactive.d.ts +2 -19
- package/babel-plugin-reactive.js +21 -76
- package/bin.js +2 -2
- package/fluff-esbuild-plugin.d.ts +2 -5
- package/fluff-esbuild-plugin.js +4 -1
- package/index.d.ts +6 -2
- package/index.js +1 -1
- package/interfaces/BabelPluginClassTransformState.d.ts +5 -0
- package/interfaces/BabelPluginComponentState.d.ts +4 -0
- package/interfaces/BabelPluginComponentState.js +1 -0
- package/interfaces/BabelPluginImportsState.d.ts +5 -0
- package/interfaces/BabelPluginImportsState.js +1 -0
- package/interfaces/BabelPluginReactiveState.d.ts +13 -0
- package/interfaces/BabelPluginReactiveState.js +1 -0
- package/interfaces/BabelPluginReactiveWatchCallInfo.d.ts +7 -0
- package/interfaces/BabelPluginReactiveWatchCallInfo.js +1 -0
- package/interfaces/BabelPluginReactiveWatchInfo.d.ts +5 -0
- package/interfaces/BabelPluginReactiveWatchInfo.js +1 -0
- package/interfaces/BabelToken.d.ts +8 -0
- package/interfaces/BabelToken.js +1 -0
- package/interfaces/BindingInfo.d.ts +12 -0
- package/interfaces/BindingInfo.js +1 -0
- package/interfaces/BreakMarkerConfig.d.ts +4 -0
- package/interfaces/BreakMarkerConfig.js +1 -0
- package/interfaces/BreakNode.d.ts +4 -0
- package/interfaces/BreakNode.js +1 -0
- package/interfaces/BundleOptions.d.ts +8 -0
- package/interfaces/BundleOptions.js +1 -0
- package/interfaces/ClassTransformOptions.d.ts +10 -0
- package/interfaces/ClassTransformOptions.js +1 -0
- package/interfaces/CliOptions.d.ts +6 -0
- package/interfaces/CliOptions.js +1 -0
- package/interfaces/CommentNode.d.ts +5 -0
- package/interfaces/CommentNode.js +1 -0
- package/interfaces/CompileResult.d.ts +6 -0
- package/interfaces/CompileResult.js +1 -0
- package/interfaces/CompilerOptions.d.ts +6 -0
- package/interfaces/CompilerOptions.js +1 -0
- package/interfaces/ComponentInfo.d.ts +8 -0
- package/interfaces/ComponentInfo.js +1 -0
- package/interfaces/ComponentMetadata.d.ts +9 -0
- package/interfaces/ComponentMetadata.js +1 -0
- package/interfaces/ControlFlow.d.ts +19 -0
- package/interfaces/ControlFlow.js +1 -0
- package/interfaces/ControlFlowNode.d.ts +6 -0
- package/interfaces/ControlFlowNode.js +1 -0
- package/interfaces/ControlFlowParseResult.d.ts +10 -0
- package/interfaces/ControlFlowParseResult.js +1 -0
- package/interfaces/ElementNode.d.ts +11 -0
- package/interfaces/ElementNode.js +1 -0
- package/interfaces/FluffConfigInterface.d.ts +7 -0
- package/interfaces/FluffConfigInterface.js +1 -0
- package/interfaces/FluffPluginOptions.d.ts +9 -0
- package/interfaces/FluffPluginOptions.js +1 -0
- package/interfaces/FluffTarget.d.ts +15 -0
- package/interfaces/FluffTarget.js +1 -0
- package/interfaces/ForMarkerConfig.d.ts +9 -0
- package/interfaces/ForMarkerConfig.js +1 -0
- package/interfaces/ForNode.d.ts +13 -0
- package/interfaces/ForNode.js +1 -0
- package/interfaces/GeneratorOptions.d.ts +5 -0
- package/interfaces/GeneratorOptions.js +1 -0
- package/interfaces/HtmlTransformOptions.d.ts +9 -0
- package/interfaces/HtmlTransformOptions.js +1 -0
- package/interfaces/IfBranch.d.ts +8 -0
- package/interfaces/IfBranch.js +1 -0
- package/interfaces/IfMarkerConfig.d.ts +8 -0
- package/interfaces/IfMarkerConfig.js +1 -0
- package/interfaces/IfNode.d.ts +7 -0
- package/interfaces/IfNode.js +1 -0
- package/interfaces/ImportTransformOptions.d.ts +7 -0
- package/interfaces/ImportTransformOptions.js +1 -0
- package/interfaces/InterpolationNode.d.ts +12 -0
- package/interfaces/InterpolationNode.js +1 -0
- package/interfaces/ParsedTemplate.d.ts +6 -0
- package/interfaces/ParsedTemplate.js +1 -0
- package/interfaces/ParsedTemplateOld.d.ts +9 -0
- package/interfaces/ParsedTemplateOld.js +1 -0
- package/interfaces/PropertyChain.d.ts +2 -0
- package/interfaces/PropertyChain.js +1 -0
- package/interfaces/Scope.d.ts +5 -0
- package/interfaces/Scope.js +1 -0
- package/interfaces/ServeOptions.d.ts +5 -0
- package/interfaces/ServeOptions.js +1 -0
- package/interfaces/SwitchCase.d.ts +8 -0
- package/interfaces/SwitchCase.js +1 -0
- package/interfaces/SwitchMarkerConfig.d.ts +11 -0
- package/interfaces/SwitchMarkerConfig.js +1 -0
- package/interfaces/SwitchNode.d.ts +10 -0
- package/interfaces/SwitchNode.js +1 -0
- package/interfaces/TemplateBinding.d.ts +10 -0
- package/interfaces/TemplateBinding.js +1 -0
- package/interfaces/TemplateNode.d.ts +7 -0
- package/interfaces/TemplateNode.js +1 -0
- package/interfaces/TextMarkerConfig.d.ts +10 -0
- package/interfaces/TextMarkerConfig.js +1 -0
- package/interfaces/TextNode.d.ts +5 -0
- package/interfaces/TextNode.js +1 -0
- package/interfaces/TokenizeResult.d.ts +6 -0
- package/interfaces/TokenizeResult.js +1 -0
- package/interfaces/TransformOptions.d.ts +11 -0
- package/interfaces/TransformOptions.js +1 -0
- package/interfaces/index.d.ts +34 -0
- package/interfaces/index.js +1 -0
- package/package.json +9 -1
- package/types/FluffConfig.d.ts +5 -27
- package/ControlFlowParser.d.ts +0 -55
- package/ControlFlowParser.js +0 -279
- package/types.d.ts +0 -46
- /package/{types.js → interfaces/BabelPluginClassTransformState.js} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _generate from '@babel/generator';
|
|
2
|
+
import _traverse from '@babel/traverse';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
export declare const generate: typeof _generate.generate;
|
|
5
|
+
export declare const traverse: {
|
|
6
|
+
<S>(parent: _traverse.Node, opts: _traverse.TraverseOptions<S>, scope: _traverse.Scope | undefined, state: S, parentPath?: _traverse.NodePath): void;
|
|
7
|
+
(parent: _traverse.Node, opts?: _traverse.TraverseOptions, scope?: _traverse.Scope, state?: any, parentPath?: _traverse.NodePath): void;
|
|
8
|
+
visitors: typeof _traverse.visitors;
|
|
9
|
+
verify: typeof _traverse.visitors.verify;
|
|
10
|
+
explode: typeof _traverse.visitors.explode;
|
|
11
|
+
cheap: (node: _traverse.Node, enter: (node: _traverse.Node) => void) => void;
|
|
12
|
+
node: (node: _traverse.Node, opts: _traverse.TraverseOptions, scope?: _traverse.Scope, state?: any, path?: _traverse.NodePath, skipKeys?: Record<string, boolean>) => void;
|
|
13
|
+
clearNode: (node: _traverse.Node, opts?: _traverse.RemovePropertiesOptions) => void;
|
|
14
|
+
removeProperties: (tree: _traverse.Node, opts?: _traverse.RemovePropertiesOptions) => _traverse.Node;
|
|
15
|
+
hasType: (tree: _traverse.Node, type: _traverse.Node["type"], denylistTypes?: string[]) => boolean;
|
|
16
|
+
cache: typeof _traverse.cache;
|
|
17
|
+
};
|
|
18
|
+
export declare function findDecoratorIndex(decorators: t.Decorator[], name: string): number;
|
|
19
|
+
export declare function getDecoratorName(decorator: t.Decorator): string | null;
|
|
20
|
+
export interface DecoratedNode {
|
|
21
|
+
decorators?: t.Decorator[] | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function filterDecoratorsFromNode(node: DecoratedNode, removeDecorators: string[]): void;
|
|
24
|
+
export declare function parseMethodBody(body: string): t.Statement[];
|
|
25
|
+
export declare function buildHostBindingUpdateStatement(hostProperty: string): t.Statement;
|
|
26
|
+
//# sourceMappingURL=BabelHelpers.d.ts.map
|
package/BabelHelpers.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _generate from '@babel/generator';
|
|
2
|
+
import { parse } from '@babel/parser';
|
|
3
|
+
import _traverse from '@babel/traverse';
|
|
4
|
+
import * as t from '@babel/types';
|
|
5
|
+
export const generate = _generate.default ?? _generate;
|
|
6
|
+
export const traverse = _traverse.default ?? _traverse;
|
|
7
|
+
export function findDecoratorIndex(decorators, name) {
|
|
8
|
+
return decorators.findIndex(dec => {
|
|
9
|
+
if (t.isCallExpression(dec.expression) && t.isIdentifier(dec.expression.callee)) {
|
|
10
|
+
return dec.expression.callee.name === name;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function getDecoratorName(decorator) {
|
|
16
|
+
const expr = decorator.expression;
|
|
17
|
+
if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
|
|
18
|
+
return expr.callee.name;
|
|
19
|
+
}
|
|
20
|
+
if (t.isIdentifier(expr)) {
|
|
21
|
+
return expr.name;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export function filterDecoratorsFromNode(node, removeDecorators) {
|
|
26
|
+
const { decorators } = node;
|
|
27
|
+
if (!decorators)
|
|
28
|
+
return;
|
|
29
|
+
node.decorators = decorators.filter(dec => {
|
|
30
|
+
const name = getDecoratorName(dec);
|
|
31
|
+
return !name || !removeDecorators.includes(name);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function parseMethodBody(body) {
|
|
35
|
+
const wrappedCode = `class __Temp__ { __temp__() { ${body} } }`;
|
|
36
|
+
const ast = parse(wrappedCode, { sourceType: 'module' });
|
|
37
|
+
const [classDecl] = ast.program.body;
|
|
38
|
+
if (t.isClassDeclaration(classDecl)) {
|
|
39
|
+
const [method] = classDecl.body.body;
|
|
40
|
+
if (t.isClassMethod(method)) {
|
|
41
|
+
return method.body.body;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
export function buildHostBindingUpdateStatement(hostProperty) {
|
|
47
|
+
if (hostProperty.startsWith('class.')) {
|
|
48
|
+
const className = hostProperty.slice(6);
|
|
49
|
+
return t.ifStatement(t.identifier('__v'), t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('classList')), t.identifier('add')), [t.stringLiteral(className)])), t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('classList')), t.identifier('remove')), [t.stringLiteral(className)])));
|
|
50
|
+
}
|
|
51
|
+
else if (hostProperty.startsWith('attr.')) {
|
|
52
|
+
const attrName = hostProperty.slice(5);
|
|
53
|
+
return t.ifStatement(t.binaryExpression('!=', t.identifier('__v'), t.nullLiteral()), t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('setAttribute')), [
|
|
54
|
+
t.stringLiteral(attrName),
|
|
55
|
+
t.callExpression(t.identifier('String'), [t.identifier('__v')])
|
|
56
|
+
])), t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('removeAttribute')), [t.stringLiteral(attrName)])));
|
|
57
|
+
}
|
|
58
|
+
else if (hostProperty.startsWith('style.')) {
|
|
59
|
+
const styleProp = hostProperty.slice(6);
|
|
60
|
+
return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('style')), t.identifier(styleProp)), t.logicalExpression('||', t.identifier('__v'), t.stringLiteral(''))));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(hostProperty)), t.identifier('__v')));
|
|
64
|
+
}
|
|
65
|
+
}
|
package/Cli.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
cwd?: string;
|
|
3
|
-
nxPackage?: string;
|
|
4
|
-
noGzip?: boolean;
|
|
5
|
-
}
|
|
1
|
+
import type { CliOptions } from './interfaces/CliOptions.js';
|
|
6
2
|
export declare class Cli {
|
|
7
3
|
private readonly cwd;
|
|
8
4
|
private readonly nxPackage;
|
|
@@ -28,10 +24,9 @@ export declare class Cli {
|
|
|
28
24
|
private findFiles;
|
|
29
25
|
private matchesPatterns;
|
|
30
26
|
private matchGlob;
|
|
27
|
+
static parseArgs(argv: string[]): {
|
|
28
|
+
options: CliOptions;
|
|
29
|
+
args: string[];
|
|
30
|
+
};
|
|
31
31
|
}
|
|
32
|
-
export declare function parseArgs(argv: string[]): {
|
|
33
|
-
options: CliOptions;
|
|
34
|
-
args: string[];
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
37
32
|
//# sourceMappingURL=Cli.d.ts.map
|
package/Cli.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
1
3
|
import * as esbuild from 'esbuild';
|
|
2
4
|
import * as fs from 'fs';
|
|
3
5
|
import * as path from 'path';
|
|
6
|
+
import picomatch from 'picomatch';
|
|
4
7
|
import { gzipSync } from 'zlib';
|
|
8
|
+
import { generate } from './BabelHelpers.js';
|
|
5
9
|
import { ComponentCompiler } from './ComponentCompiler.js';
|
|
6
10
|
import { fluffPlugin } from './fluff-esbuild-plugin.js';
|
|
7
|
-
import { transformIndexHtml } from './IndexHtmlTransformer.js';
|
|
8
|
-
import { DEFAULT_CONFIG } from './types/FluffConfig.js';
|
|
9
11
|
import { Generator } from './Generator.js';
|
|
12
|
+
import { IndexHtmlTransformer } from './IndexHtmlTransformer.js';
|
|
13
|
+
import { DEFAULT_CONFIG } from './types/FluffConfig.js';
|
|
10
14
|
export class Cli {
|
|
11
15
|
cwd;
|
|
12
16
|
nxPackage;
|
|
@@ -295,6 +299,27 @@ Examples:
|
|
|
295
299
|
const entryPoint = target.entryPoint
|
|
296
300
|
? path.join(srcDir, target.entryPoint)
|
|
297
301
|
: this.generateEntryPoint(srcDir, target.components);
|
|
302
|
+
let inlineStyles = '';
|
|
303
|
+
if (target.styles && target.styles.length > 0) {
|
|
304
|
+
const styleContents = [];
|
|
305
|
+
for (const styleGlob of target.styles) {
|
|
306
|
+
const styleFiles = this.findFiles(srcDir, [styleGlob]);
|
|
307
|
+
for (const styleFile of styleFiles) {
|
|
308
|
+
styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (styleContents.length > 0) {
|
|
312
|
+
inlineStyles = styleContents.join('\n');
|
|
313
|
+
if (bundleOptions.minify) {
|
|
314
|
+
const cssResult = await esbuild.transform(inlineStyles, {
|
|
315
|
+
loader: 'css',
|
|
316
|
+
minify: true
|
|
317
|
+
});
|
|
318
|
+
inlineStyles = cssResult.code;
|
|
319
|
+
}
|
|
320
|
+
console.log(' ✓ Bundled global styles');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
298
323
|
console.log(' Building with esbuild...');
|
|
299
324
|
const result = await esbuild.build({
|
|
300
325
|
entryPoints: [entryPoint],
|
|
@@ -307,7 +332,15 @@ Examples:
|
|
|
307
332
|
splitting: bundleOptions.splitting ?? false,
|
|
308
333
|
treeShaking: true,
|
|
309
334
|
metafile: true,
|
|
310
|
-
plugins: [
|
|
335
|
+
plugins: [
|
|
336
|
+
fluffPlugin({
|
|
337
|
+
srcDir: appDir,
|
|
338
|
+
outDir,
|
|
339
|
+
minify: bundleOptions.minify ?? true,
|
|
340
|
+
skipDefine: false,
|
|
341
|
+
production: true
|
|
342
|
+
})
|
|
343
|
+
],
|
|
311
344
|
external: bundleOptions.external ?? [],
|
|
312
345
|
logLevel: 'warning',
|
|
313
346
|
tsconfigRaw: '{}'
|
|
@@ -319,8 +352,8 @@ Examples:
|
|
|
319
352
|
const jsBundleName = path.basename(jsBundle);
|
|
320
353
|
const jsPath = path.join(outDir, jsBundleName);
|
|
321
354
|
if (bundleOptions.gzip) {
|
|
322
|
-
const
|
|
323
|
-
const gzipped = gzipSync(
|
|
355
|
+
const gzipContent = fs.readFileSync(jsPath);
|
|
356
|
+
const gzipped = gzipSync(gzipContent, { level: 9 });
|
|
324
357
|
fs.writeFileSync(`${jsPath}.gz`, gzipped);
|
|
325
358
|
fs.unlinkSync(jsPath);
|
|
326
359
|
console.log(` ✓ Created ${jsBundleName}.gz (${gzipped.length} bytes)`);
|
|
@@ -347,9 +380,10 @@ Examples:
|
|
|
347
380
|
const indexHtmlPath = path.join(srcDir, target.indexHtml);
|
|
348
381
|
if (fs.existsSync(indexHtmlPath)) {
|
|
349
382
|
const indexHtml = fs.readFileSync(indexHtmlPath, 'utf-8');
|
|
350
|
-
const transformed = await
|
|
383
|
+
const transformed = await IndexHtmlTransformer.transform(indexHtml, {
|
|
351
384
|
jsBundle: jsBundle ? path.basename(jsBundle) : 'main.js',
|
|
352
385
|
cssBundle: cssBundle ? path.basename(cssBundle) : undefined,
|
|
386
|
+
inlineStyles: inlineStyles || undefined,
|
|
353
387
|
gzip: bundleOptions.gzip,
|
|
354
388
|
minify: bundleOptions.minify
|
|
355
389
|
});
|
|
@@ -436,26 +470,58 @@ Examples:
|
|
|
436
470
|
async serveTarget(target, projectRoot, workspaceRoot, projectRelativePath) {
|
|
437
471
|
const srcDir = path.resolve(projectRoot, target.srcDir);
|
|
438
472
|
const appDir = path.join(srcDir, 'app');
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
473
|
+
const fluffDir = path.join(this.cwd, '.fluff');
|
|
474
|
+
const serveId = randomUUID();
|
|
475
|
+
const outDir = path.join(fluffDir, serveId);
|
|
442
476
|
if (!fs.existsSync(outDir)) {
|
|
443
477
|
fs.mkdirSync(outDir, { recursive: true });
|
|
444
478
|
}
|
|
479
|
+
const cleanup = () => {
|
|
480
|
+
try {
|
|
481
|
+
if (fs.existsSync(outDir)) {
|
|
482
|
+
fs.rmSync(outDir, { recursive: true, force: true });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
process.on('exit', cleanup);
|
|
489
|
+
process.on('SIGINT', () => {
|
|
490
|
+
cleanup();
|
|
491
|
+
process.exit(0);
|
|
492
|
+
});
|
|
493
|
+
process.on('SIGTERM', () => {
|
|
494
|
+
cleanup();
|
|
495
|
+
process.exit(0);
|
|
496
|
+
});
|
|
445
497
|
const serveOptions = target.serve ?? {};
|
|
446
498
|
const port = serveOptions.port ?? 3000;
|
|
447
499
|
const host = serveOptions.host ?? 'localhost';
|
|
448
500
|
const entryPoint = target.entryPoint
|
|
449
501
|
? path.join(srcDir, target.entryPoint)
|
|
450
502
|
: this.generateEntryPoint(srcDir, target.components);
|
|
503
|
+
let inlineStyles = '';
|
|
504
|
+
if (target.styles && target.styles.length > 0) {
|
|
505
|
+
const styleContents = [];
|
|
506
|
+
for (const styleGlob of target.styles) {
|
|
507
|
+
const styleFiles = this.findFiles(srcDir, [styleGlob]);
|
|
508
|
+
for (const styleFile of styleFiles) {
|
|
509
|
+
styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
if (styleContents.length > 0) {
|
|
513
|
+
inlineStyles = styleContents.join('\n');
|
|
514
|
+
}
|
|
515
|
+
}
|
|
451
516
|
if (target.indexHtml) {
|
|
452
517
|
const indexHtmlPath = path.join(srcDir, target.indexHtml);
|
|
453
518
|
if (fs.existsSync(indexHtmlPath)) {
|
|
454
519
|
const indexHtml = fs.readFileSync(indexHtmlPath, 'utf-8');
|
|
455
|
-
const transformed = await
|
|
520
|
+
const transformed = await IndexHtmlTransformer.transform(indexHtml, {
|
|
456
521
|
jsBundle: path.basename(entryPoint)
|
|
457
522
|
.replace('.ts', '.js'),
|
|
458
523
|
cssBundle: undefined,
|
|
524
|
+
inlineStyles: inlineStyles || undefined,
|
|
459
525
|
gzip: false,
|
|
460
526
|
minify: false,
|
|
461
527
|
liveReload: true
|
|
@@ -496,7 +562,16 @@ Examples:
|
|
|
496
562
|
minify: false,
|
|
497
563
|
treeShaking: true,
|
|
498
564
|
sourcemap: true,
|
|
499
|
-
plugins: [
|
|
565
|
+
plugins: [
|
|
566
|
+
fluffPlugin({
|
|
567
|
+
srcDir: appDir,
|
|
568
|
+
outDir,
|
|
569
|
+
minify: false,
|
|
570
|
+
sourcemap: true,
|
|
571
|
+
skipDefine: false,
|
|
572
|
+
production: false
|
|
573
|
+
})
|
|
574
|
+
],
|
|
500
575
|
logLevel: 'info'
|
|
501
576
|
});
|
|
502
577
|
await ctx.watch();
|
|
@@ -511,12 +586,13 @@ Examples:
|
|
|
511
586
|
}
|
|
512
587
|
generateEntryPoint(srcDir, componentPatterns) {
|
|
513
588
|
const componentFiles = this.findFiles(srcDir, componentPatterns);
|
|
514
|
-
const
|
|
589
|
+
const importDecls = componentFiles.map(f => {
|
|
515
590
|
const relativePath = './' + path.relative(srcDir, f)
|
|
516
591
|
.replace(/\\/g, '/');
|
|
517
|
-
return
|
|
592
|
+
return t.importDeclaration([], t.stringLiteral(relativePath));
|
|
518
593
|
});
|
|
519
|
-
const
|
|
594
|
+
const program = t.program(importDecls);
|
|
595
|
+
const entryContent = generate(program, { compact: false }).code;
|
|
520
596
|
const entryPath = path.join(srcDir, '__generated_entry.ts');
|
|
521
597
|
fs.writeFileSync(entryPath, entryContent);
|
|
522
598
|
return entryPath;
|
|
@@ -550,45 +626,40 @@ Examples:
|
|
|
550
626
|
return false;
|
|
551
627
|
}
|
|
552
628
|
matchGlob(filePath, pattern) {
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
.replace(/\*/g, '[^/]*')
|
|
557
|
-
.replace(/\{\{GLOBSTAR}}\//g, '(.*\\/)?')
|
|
558
|
-
.replace(/\{\{GLOBSTAR}}/g, '.*');
|
|
559
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
560
|
-
return regex.test(filePath);
|
|
629
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
630
|
+
const isMatch = picomatch(pattern, { dot: false });
|
|
631
|
+
return isMatch(normalizedPath);
|
|
561
632
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
633
|
+
static parseArgs(argv) {
|
|
634
|
+
const options = {};
|
|
635
|
+
const args = [];
|
|
636
|
+
let i = 0;
|
|
637
|
+
while (i < argv.length) {
|
|
638
|
+
const arg = argv[i];
|
|
639
|
+
if (arg === '--nx' && argv[i + 1]) {
|
|
640
|
+
options.nxPackage = argv[i + 1];
|
|
641
|
+
i += 2;
|
|
642
|
+
}
|
|
643
|
+
else if (arg === '--cwd' && argv[i + 1]) {
|
|
644
|
+
options.cwd = argv[i + 1];
|
|
645
|
+
i += 2;
|
|
646
|
+
}
|
|
647
|
+
else if (arg === '--no-gzip') {
|
|
648
|
+
options.noGzip = true;
|
|
649
|
+
i++;
|
|
650
|
+
}
|
|
651
|
+
else if (arg?.startsWith('--')) {
|
|
652
|
+
console.error(`Unknown option: ${arg}`);
|
|
653
|
+
process.exit(1);
|
|
654
|
+
}
|
|
655
|
+
else if (arg) {
|
|
656
|
+
args.push(arg);
|
|
657
|
+
i++;
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
i++;
|
|
661
|
+
}
|
|
591
662
|
}
|
|
663
|
+
return { options, args };
|
|
592
664
|
}
|
|
593
|
-
return { options, args };
|
|
594
665
|
}
|
package/CodeGenerator.d.ts
CHANGED
|
@@ -1,42 +1,56 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BreakMarkerConfig } from './interfaces/BreakMarkerConfig.js';
|
|
2
|
+
import type { ForMarkerConfig } from './interfaces/ForMarkerConfig.js';
|
|
3
|
+
import type { IfMarkerConfig } from './interfaces/IfMarkerConfig.js';
|
|
4
|
+
import type { SwitchMarkerConfig } from './interfaces/SwitchMarkerConfig.js';
|
|
5
|
+
import type { TextMarkerConfig } from './interfaces/TextMarkerConfig.js';
|
|
6
|
+
import type { ParsedTemplate } from './TemplateParser.js';
|
|
7
|
+
export type { BreakMarkerConfig } from './interfaces/BreakMarkerConfig.js';
|
|
8
|
+
export type { ForMarkerConfig } from './interfaces/ForMarkerConfig.js';
|
|
9
|
+
export type { IfMarkerConfig } from './interfaces/IfMarkerConfig.js';
|
|
10
|
+
export type { SwitchMarkerConfig } from './interfaces/SwitchMarkerConfig.js';
|
|
11
|
+
export type { TextMarkerConfig } from './interfaces/TextMarkerConfig.js';
|
|
12
|
+
export type MarkerConfig = IfMarkerConfig | ForMarkerConfig | SwitchMarkerConfig | TextMarkerConfig | BreakMarkerConfig;
|
|
2
13
|
export declare class CodeGenerator {
|
|
3
|
-
private
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
private
|
|
28
|
-
private
|
|
29
|
-
private
|
|
30
|
-
private
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private
|
|
34
|
-
private
|
|
35
|
-
private
|
|
36
|
-
private
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private
|
|
14
|
+
private readonly componentSelectors;
|
|
15
|
+
private readonly componentSelector;
|
|
16
|
+
private static readonly globalExprIdsByExpr;
|
|
17
|
+
private static globalExprs;
|
|
18
|
+
private static readonly globalHandlerIdsByExpr;
|
|
19
|
+
private static globalHandlers;
|
|
20
|
+
private markerId;
|
|
21
|
+
private readonly markerConfigs;
|
|
22
|
+
private readonly usedExprIds;
|
|
23
|
+
private readonly usedHandlerIds;
|
|
24
|
+
private readonly bindingsMap;
|
|
25
|
+
private rootFragment;
|
|
26
|
+
private readonly collectedTemplates;
|
|
27
|
+
constructor(componentSelectors?: Set<string>, componentSelector?: string);
|
|
28
|
+
static resetGlobalState(): void;
|
|
29
|
+
generateRenderMethod(template: ParsedTemplate, styles?: string): string;
|
|
30
|
+
generateHtml(template: ParsedTemplate): string;
|
|
31
|
+
generateRenderMethodFromHtml(html: string, styles?: string, markerConfigJson?: string): string;
|
|
32
|
+
getMarkerConfigJson(): string;
|
|
33
|
+
generateBindingsSetup(): string;
|
|
34
|
+
getBindingsMap(): Record<string, Record<string, unknown>[]>;
|
|
35
|
+
generateExpressionAssignments(): string;
|
|
36
|
+
static generateGlobalExprTable(): string;
|
|
37
|
+
private static buildExpressionArrowFunction;
|
|
38
|
+
private static buildHandlerArrowFunction;
|
|
39
|
+
private static normalizeCompiledExpr;
|
|
40
|
+
private nextMarkerId;
|
|
41
|
+
private renderNodesToParent;
|
|
42
|
+
private renderNodeToParent;
|
|
43
|
+
private renderElementToParent;
|
|
44
|
+
private renderTextToParent;
|
|
45
|
+
private isComponentTag;
|
|
46
|
+
private serializeBinding;
|
|
47
|
+
private internExpression;
|
|
48
|
+
private internHandler;
|
|
49
|
+
private renderInterpolationToParent;
|
|
50
|
+
private renderCommentToParent;
|
|
51
|
+
private renderIfToParent;
|
|
52
|
+
private renderForToParent;
|
|
53
|
+
private renderSwitchToParent;
|
|
54
|
+
private renderBreakToParent;
|
|
41
55
|
}
|
|
42
56
|
//# sourceMappingURL=CodeGenerator.d.ts.map
|