@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 CHANGED
@@ -3,6 +3,8 @@ export declare class Cli {
3
3
  private readonly cwd;
4
4
  private readonly nxPackage;
5
5
  private readonly noGzip;
6
+ private readonly noMinify;
7
+ private readonly gzScriptTag;
6
8
  constructor(options?: CliOptions);
7
9
  run(args: string[]): Promise<void>;
8
10
  private showHelp;
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);
@@ -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: true,
131
+ removeComments: false,
127
132
  removeRedundantAttributes: true,
128
133
  removeEmptyAttributes: true
129
134
  });
package/Generator.js CHANGED
@@ -127,6 +127,7 @@ export class Generator {
127
127
  name,
128
128
  srcDir: 'src',
129
129
  outDir: 'dist',
130
+ componentsDir: 'app',
130
131
  entryPoint: 'main.ts',
131
132
  indexHtml: 'index.html',
132
133
  components: ['**/*.component.ts'],
@@ -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.gzip ? `${options.jsBundle}.gz` : options.jsBundle;
33
+ const jsSrc = options.gzScriptTag ? `${options.jsBundle}.gz` : options.jsBundle;
34
34
  const cssSrc = options.cssBundle
35
- ? (options.gzip ? `${options.cssBundle}.gz` : options.cssBundle)
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');
@@ -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
  }
@@ -3,6 +3,7 @@ export interface BundleOptions {
3
3
  splitting?: boolean;
4
4
  target?: string;
5
5
  gzip?: boolean;
6
+ gzScriptTag?: boolean;
6
7
  external?: string[];
7
8
  }
8
9
  //# sourceMappingURL=BundleOptions.d.ts.map
@@ -2,5 +2,7 @@ export interface CliOptions {
2
2
  cwd?: string;
3
3
  nxPackage?: string;
4
4
  noGzip?: boolean;
5
+ noMinify?: boolean;
6
+ gzScriptTag?: boolean;
5
7
  }
6
8
  //# sourceMappingURL=CliOptions.d.ts.map
@@ -4,6 +4,7 @@ export interface FluffTarget {
4
4
  name: string;
5
5
  srcDir: string;
6
6
  outDir: string;
7
+ componentsDir?: string;
7
8
  entryPoint?: string;
8
9
  indexHtml?: string;
9
10
  components: string[];
@@ -3,6 +3,7 @@ export interface HtmlTransformOptions {
3
3
  cssBundle?: string;
4
4
  inlineStyles?: string;
5
5
  gzip?: boolean;
6
+ gzScriptTag?: boolean;
6
7
  minify?: boolean;
7
8
  liveReload?: boolean;
8
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluffjs/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -5,6 +5,7 @@ export const DEFAULT_CONFIG = {
5
5
  name: 'app',
6
6
  srcDir: 'src',
7
7
  outDir: 'dist',
8
+ componentsDir: 'app',
8
9
  entryPoint: 'main.ts',
9
10
  indexHtml: 'index.html',
10
11
  components: ['**/*.component.ts'],