@fluffjs/cli 0.0.8 → 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.
- package/BabelHelpers.d.ts +26 -0
- package/BabelHelpers.js +65 -0
- package/Cli.d.ts +7 -10
- package/Cli.js +139 -52
- package/CodeGenerator.d.ts +53 -39
- package/CodeGenerator.js +330 -725
- package/ComponentCompiler.d.ts +14 -16
- package/ComponentCompiler.js +193 -257
- 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 +17 -0
- package/Parse5Helpers.js +95 -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 +9 -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 +8 -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 +10 -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,12 +1,10 @@
|
|
|
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;
|
|
9
5
|
private readonly noGzip;
|
|
6
|
+
private readonly noMinify;
|
|
7
|
+
private readonly gzScriptTag;
|
|
10
8
|
constructor(options?: CliOptions);
|
|
11
9
|
run(args: string[]): Promise<void>;
|
|
12
10
|
private showHelp;
|
|
@@ -28,10 +26,9 @@ export declare class Cli {
|
|
|
28
26
|
private findFiles;
|
|
29
27
|
private matchesPatterns;
|
|
30
28
|
private matchGlob;
|
|
29
|
+
static parseArgs(argv: string[]): {
|
|
30
|
+
options: CliOptions;
|
|
31
|
+
args: string[];
|
|
32
|
+
};
|
|
31
33
|
}
|
|
32
|
-
export declare function parseArgs(argv: string[]): {
|
|
33
|
-
options: CliOptions;
|
|
34
|
-
args: string[];
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
37
34
|
//# sourceMappingURL=Cli.d.ts.map
|
package/Cli.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
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;
|
|
13
17
|
noGzip;
|
|
18
|
+
noMinify;
|
|
19
|
+
gzScriptTag;
|
|
14
20
|
constructor(options = {}) {
|
|
15
21
|
this.cwd = options.cwd ?? process.env.INIT_CWD ?? process.cwd();
|
|
16
22
|
this.nxPackage = options.nxPackage;
|
|
17
23
|
this.noGzip = options.noGzip ?? false;
|
|
24
|
+
this.noMinify = options.noMinify ?? false;
|
|
25
|
+
this.gzScriptTag = options.gzScriptTag ?? false;
|
|
18
26
|
}
|
|
19
27
|
async run(args) {
|
|
20
28
|
const [command, ...commandArgs] = args;
|
|
@@ -292,9 +300,33 @@ Examples:
|
|
|
292
300
|
if (this.noGzip) {
|
|
293
301
|
bundleOptions.gzip = false;
|
|
294
302
|
}
|
|
303
|
+
if (this.noMinify) {
|
|
304
|
+
bundleOptions.minify = false;
|
|
305
|
+
}
|
|
295
306
|
const entryPoint = target.entryPoint
|
|
296
307
|
? path.join(srcDir, target.entryPoint)
|
|
297
308
|
: this.generateEntryPoint(srcDir, target.components);
|
|
309
|
+
let inlineStyles = '';
|
|
310
|
+
if (target.styles && target.styles.length > 0) {
|
|
311
|
+
const styleContents = [];
|
|
312
|
+
for (const styleGlob of target.styles) {
|
|
313
|
+
const styleFiles = this.findFiles(srcDir, [styleGlob]);
|
|
314
|
+
for (const styleFile of styleFiles) {
|
|
315
|
+
styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (styleContents.length > 0) {
|
|
319
|
+
inlineStyles = styleContents.join('\n');
|
|
320
|
+
if (bundleOptions.minify) {
|
|
321
|
+
const cssResult = await esbuild.transform(inlineStyles, {
|
|
322
|
+
loader: 'css',
|
|
323
|
+
minify: true
|
|
324
|
+
});
|
|
325
|
+
inlineStyles = cssResult.code;
|
|
326
|
+
}
|
|
327
|
+
console.log(' ✓ Bundled global styles');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
298
330
|
console.log(' Building with esbuild...');
|
|
299
331
|
const result = await esbuild.build({
|
|
300
332
|
entryPoints: [entryPoint],
|
|
@@ -307,7 +339,15 @@ Examples:
|
|
|
307
339
|
splitting: bundleOptions.splitting ?? false,
|
|
308
340
|
treeShaking: true,
|
|
309
341
|
metafile: true,
|
|
310
|
-
plugins: [
|
|
342
|
+
plugins: [
|
|
343
|
+
fluffPlugin({
|
|
344
|
+
srcDir: appDir,
|
|
345
|
+
outDir,
|
|
346
|
+
minify: bundleOptions.minify ?? true,
|
|
347
|
+
skipDefine: false,
|
|
348
|
+
production: true
|
|
349
|
+
})
|
|
350
|
+
],
|
|
311
351
|
external: bundleOptions.external ?? [],
|
|
312
352
|
logLevel: 'warning',
|
|
313
353
|
tsconfigRaw: '{}'
|
|
@@ -319,8 +359,8 @@ Examples:
|
|
|
319
359
|
const jsBundleName = path.basename(jsBundle);
|
|
320
360
|
const jsPath = path.join(outDir, jsBundleName);
|
|
321
361
|
if (bundleOptions.gzip) {
|
|
322
|
-
const
|
|
323
|
-
const gzipped = gzipSync(
|
|
362
|
+
const gzipContent = fs.readFileSync(jsPath);
|
|
363
|
+
const gzipped = gzipSync(gzipContent, { level: 9 });
|
|
324
364
|
fs.writeFileSync(`${jsPath}.gz`, gzipped);
|
|
325
365
|
fs.unlinkSync(jsPath);
|
|
326
366
|
console.log(` ✓ Created ${jsBundleName}.gz (${gzipped.length} bytes)`);
|
|
@@ -347,10 +387,12 @@ Examples:
|
|
|
347
387
|
const indexHtmlPath = path.join(srcDir, target.indexHtml);
|
|
348
388
|
if (fs.existsSync(indexHtmlPath)) {
|
|
349
389
|
const indexHtml = fs.readFileSync(indexHtmlPath, 'utf-8');
|
|
350
|
-
const transformed = await
|
|
390
|
+
const transformed = await IndexHtmlTransformer.transform(indexHtml, {
|
|
351
391
|
jsBundle: jsBundle ? path.basename(jsBundle) : 'main.js',
|
|
352
392
|
cssBundle: cssBundle ? path.basename(cssBundle) : undefined,
|
|
393
|
+
inlineStyles: inlineStyles || undefined,
|
|
353
394
|
gzip: bundleOptions.gzip,
|
|
395
|
+
gzScriptTag: bundleOptions.gzScriptTag ?? this.gzScriptTag,
|
|
354
396
|
minify: bundleOptions.minify
|
|
355
397
|
});
|
|
356
398
|
fs.writeFileSync(path.join(outDir, 'index.html'), transformed);
|
|
@@ -436,26 +478,58 @@ Examples:
|
|
|
436
478
|
async serveTarget(target, projectRoot, workspaceRoot, projectRelativePath) {
|
|
437
479
|
const srcDir = path.resolve(projectRoot, target.srcDir);
|
|
438
480
|
const appDir = path.join(srcDir, 'app');
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
481
|
+
const fluffDir = path.join(this.cwd, '.fluff');
|
|
482
|
+
const serveId = randomUUID();
|
|
483
|
+
const outDir = path.join(fluffDir, serveId);
|
|
442
484
|
if (!fs.existsSync(outDir)) {
|
|
443
485
|
fs.mkdirSync(outDir, { recursive: true });
|
|
444
486
|
}
|
|
487
|
+
const cleanup = () => {
|
|
488
|
+
try {
|
|
489
|
+
if (fs.existsSync(outDir)) {
|
|
490
|
+
fs.rmSync(outDir, { recursive: true, force: true });
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
process.on('exit', cleanup);
|
|
497
|
+
process.on('SIGINT', () => {
|
|
498
|
+
cleanup();
|
|
499
|
+
process.exit(0);
|
|
500
|
+
});
|
|
501
|
+
process.on('SIGTERM', () => {
|
|
502
|
+
cleanup();
|
|
503
|
+
process.exit(0);
|
|
504
|
+
});
|
|
445
505
|
const serveOptions = target.serve ?? {};
|
|
446
506
|
const port = serveOptions.port ?? 3000;
|
|
447
507
|
const host = serveOptions.host ?? 'localhost';
|
|
448
508
|
const entryPoint = target.entryPoint
|
|
449
509
|
? path.join(srcDir, target.entryPoint)
|
|
450
510
|
: this.generateEntryPoint(srcDir, target.components);
|
|
511
|
+
let inlineStyles = '';
|
|
512
|
+
if (target.styles && target.styles.length > 0) {
|
|
513
|
+
const styleContents = [];
|
|
514
|
+
for (const styleGlob of target.styles) {
|
|
515
|
+
const styleFiles = this.findFiles(srcDir, [styleGlob]);
|
|
516
|
+
for (const styleFile of styleFiles) {
|
|
517
|
+
styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (styleContents.length > 0) {
|
|
521
|
+
inlineStyles = styleContents.join('\n');
|
|
522
|
+
}
|
|
523
|
+
}
|
|
451
524
|
if (target.indexHtml) {
|
|
452
525
|
const indexHtmlPath = path.join(srcDir, target.indexHtml);
|
|
453
526
|
if (fs.existsSync(indexHtmlPath)) {
|
|
454
527
|
const indexHtml = fs.readFileSync(indexHtmlPath, 'utf-8');
|
|
455
|
-
const transformed = await
|
|
528
|
+
const transformed = await IndexHtmlTransformer.transform(indexHtml, {
|
|
456
529
|
jsBundle: path.basename(entryPoint)
|
|
457
530
|
.replace('.ts', '.js'),
|
|
458
531
|
cssBundle: undefined,
|
|
532
|
+
inlineStyles: inlineStyles || undefined,
|
|
459
533
|
gzip: false,
|
|
460
534
|
minify: false,
|
|
461
535
|
liveReload: true
|
|
@@ -496,7 +570,16 @@ Examples:
|
|
|
496
570
|
minify: false,
|
|
497
571
|
treeShaking: true,
|
|
498
572
|
sourcemap: true,
|
|
499
|
-
plugins: [
|
|
573
|
+
plugins: [
|
|
574
|
+
fluffPlugin({
|
|
575
|
+
srcDir: appDir,
|
|
576
|
+
outDir,
|
|
577
|
+
minify: false,
|
|
578
|
+
sourcemap: true,
|
|
579
|
+
skipDefine: false,
|
|
580
|
+
production: false
|
|
581
|
+
})
|
|
582
|
+
],
|
|
500
583
|
logLevel: 'info'
|
|
501
584
|
});
|
|
502
585
|
await ctx.watch();
|
|
@@ -511,12 +594,13 @@ Examples:
|
|
|
511
594
|
}
|
|
512
595
|
generateEntryPoint(srcDir, componentPatterns) {
|
|
513
596
|
const componentFiles = this.findFiles(srcDir, componentPatterns);
|
|
514
|
-
const
|
|
597
|
+
const importDecls = componentFiles.map(f => {
|
|
515
598
|
const relativePath = './' + path.relative(srcDir, f)
|
|
516
599
|
.replace(/\\/g, '/');
|
|
517
|
-
return
|
|
600
|
+
return t.importDeclaration([], t.stringLiteral(relativePath));
|
|
518
601
|
});
|
|
519
|
-
const
|
|
602
|
+
const program = t.program(importDecls);
|
|
603
|
+
const entryContent = generate(program, { compact: false }).code;
|
|
520
604
|
const entryPath = path.join(srcDir, '__generated_entry.ts');
|
|
521
605
|
fs.writeFileSync(entryPath, entryContent);
|
|
522
606
|
return entryPath;
|
|
@@ -550,45 +634,48 @@ Examples:
|
|
|
550
634
|
return false;
|
|
551
635
|
}
|
|
552
636
|
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);
|
|
637
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
638
|
+
const isMatch = picomatch(pattern, { dot: false });
|
|
639
|
+
return isMatch(normalizedPath);
|
|
561
640
|
}
|
|
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
|
-
|
|
641
|
+
static parseArgs(argv) {
|
|
642
|
+
const options = {};
|
|
643
|
+
const args = [];
|
|
644
|
+
let i = 0;
|
|
645
|
+
while (i < argv.length) {
|
|
646
|
+
const arg = argv[i];
|
|
647
|
+
if (arg === '--nx' && argv[i + 1]) {
|
|
648
|
+
options.nxPackage = argv[i + 1];
|
|
649
|
+
i += 2;
|
|
650
|
+
}
|
|
651
|
+
else if (arg === '--cwd' && argv[i + 1]) {
|
|
652
|
+
options.cwd = argv[i + 1];
|
|
653
|
+
i += 2;
|
|
654
|
+
}
|
|
655
|
+
else if (arg === '--no-gzip') {
|
|
656
|
+
options.noGzip = true;
|
|
657
|
+
i++;
|
|
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
|
+
}
|
|
667
|
+
else if (arg?.startsWith('--')) {
|
|
668
|
+
console.error(`Unknown option: ${arg}`);
|
|
669
|
+
process.exit(1);
|
|
670
|
+
}
|
|
671
|
+
else if (arg) {
|
|
672
|
+
args.push(arg);
|
|
673
|
+
i++;
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
i++;
|
|
677
|
+
}
|
|
591
678
|
}
|
|
679
|
+
return { options, args };
|
|
592
680
|
}
|
|
593
|
-
return { options, args };
|
|
594
681
|
}
|
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
|