@salty-css/core 0.0.1-alpha.304 → 0.0.1-alpha.306

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.
@@ -560,6 +560,88 @@ ${current}`;
560
560
  }
561
561
  return void 0;
562
562
  });
563
+ __publicField(this, "generateFile", async (file) => {
564
+ try {
565
+ const destDir = await this.getDestDir();
566
+ const validFile = compiler_helpers.isSaltyFile(file);
567
+ if (validFile) {
568
+ const cssFiles = [];
569
+ const config = await this.getConfig();
570
+ const { contents } = await this.compileSaltyFile(file, destDir);
571
+ for (const [name, value] of Object.entries(contents)) {
572
+ const resolved = await compiler_helpers.resolveExportValue(value, 1);
573
+ if (resolved.isKeyframes && resolved.css) {
574
+ const fileName = `a_${resolved.animationName}.css`;
575
+ const filePath2 = `css/${fileName}`;
576
+ const cssPath2 = path.join(destDir, filePath2);
577
+ fs.writeFileSync(cssPath2, await resolved.css);
578
+ continue;
579
+ }
580
+ if (resolved.isClassName) {
581
+ const generator2 = resolved.generator._withBuildContext({
582
+ callerName: name,
583
+ isProduction: this.isProduction,
584
+ config
585
+ });
586
+ const styles2 = await generator2.css;
587
+ if (!styles2) continue;
588
+ if (!cssFiles[generator2.priority]) cssFiles[generator2.priority] = [];
589
+ cssFiles[generator2.priority].push(generator2.cssFileName);
590
+ const filePath2 = `css/${generator2.cssFileName}`;
591
+ const cssPath2 = path.join(destDir, filePath2);
592
+ fs.writeFileSync(cssPath2, styles2);
593
+ continue;
594
+ }
595
+ if (!resolved.generator) continue;
596
+ const generator = resolved.generator._withBuildContext({
597
+ callerName: name,
598
+ isProduction: this.isProduction,
599
+ config
600
+ });
601
+ const styles = await generator.css;
602
+ if (!styles) continue;
603
+ const filePath = `css/${generator.cssFileName}`;
604
+ const cssPath = path.join(destDir, filePath);
605
+ fs.writeFileSync(cssPath, styles);
606
+ if (!cssFiles[generator.priority]) cssFiles[generator.priority] = [];
607
+ cssFiles[generator.priority].push(generator.cssFileName);
608
+ }
609
+ if (config.importStrategy !== "component") {
610
+ cssFiles.forEach((val, layer) => {
611
+ const layerFileName = `l_${layer}.css`;
612
+ const layerFilePath = path.join(destDir, "css", layerFileName);
613
+ let currentLayerFileContent = fs.readFileSync(layerFilePath, "utf8");
614
+ val.forEach((file2) => {
615
+ var _a;
616
+ const filepath = path.join(destDir, "css", file2);
617
+ const filepathHash = ((_a = /.*-([^-]+)-\d+.css/.exec(file2)) == null ? void 0 : _a.at(1)) || dashCase.toHash(filepath, 6);
618
+ const found = currentLayerFileContent.includes(filepathHash);
619
+ if (!found) {
620
+ const css = fs.readFileSync(filepath, "utf8");
621
+ const newContent = `/*start:${filepathHash}-${file2}*/
622
+ ${css}
623
+ /*end:${filepathHash}*/
624
+ `;
625
+ currentLayerFileContent = `${currentLayerFileContent.replace(/\}$/, "")}
626
+ ${newContent}
627
+ }`;
628
+ }
629
+ });
630
+ fs.writeFileSync(layerFilePath, currentLayerFileContent);
631
+ });
632
+ } else {
633
+ const cssContent = cssFiles.flat().map((file2) => `@import url('./${file2}');`).join("\n");
634
+ const hashName = dashCase.toHash(file, 6);
635
+ const parsedPath = path.parse(file);
636
+ const dasherized = dashCase.dashCase(parsedPath.name);
637
+ const cssFile = path.join(destDir, `css/f_${dasherized}-${hashName}.css`);
638
+ fs.writeFileSync(cssFile, cssContent || `/* Empty file */`);
639
+ }
640
+ }
641
+ } catch (e) {
642
+ console.error(e);
643
+ }
644
+ });
563
645
  __publicField(this, "replaceStyledTag", (currentFile) => {
564
646
  return currentFile.replace(/styled\(([^"'`{,]+),/g, (match, tag) => {
565
647
  const isString = /^['"`]/.test(tag);
@@ -29,7 +29,24 @@ export declare class SaltyCompiler {
29
29
  */
30
30
  generateCss: (clean?: boolean) => Promise<void>;
31
31
  private generateConfigStyles;
32
- private compileSaltyFile;
32
+ compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
33
+ contents: {
34
+ [key: string]: {
35
+ generator: any;
36
+ isClassName?: boolean;
37
+ isMedia?: boolean;
38
+ isGlobalDefine?: boolean;
39
+ isDefineVariables?: boolean;
40
+ isDefineTemplates?: boolean;
41
+ isKeyframes?: boolean;
42
+ animationName?: string;
43
+ css?: Promise<string>;
44
+ styles?: any;
45
+ };
46
+ };
47
+ outputFilePath: string;
48
+ }>;
33
49
  minimizeFile: (file: string) => Promise<string | undefined>;
50
+ generateFile: (file: string) => Promise<void>;
34
51
  private replaceStyledTag;
35
52
  }
@@ -541,6 +541,88 @@ ${current}`;
541
541
  }
542
542
  return void 0;
543
543
  });
544
+ __publicField(this, "generateFile", async (file) => {
545
+ try {
546
+ const destDir = await this.getDestDir();
547
+ const validFile = isSaltyFile(file);
548
+ if (validFile) {
549
+ const cssFiles = [];
550
+ const config = await this.getConfig();
551
+ const { contents } = await this.compileSaltyFile(file, destDir);
552
+ for (const [name, value] of Object.entries(contents)) {
553
+ const resolved = await resolveExportValue(value, 1);
554
+ if (resolved.isKeyframes && resolved.css) {
555
+ const fileName = `a_${resolved.animationName}.css`;
556
+ const filePath2 = `css/${fileName}`;
557
+ const cssPath2 = join(destDir, filePath2);
558
+ writeFileSync(cssPath2, await resolved.css);
559
+ continue;
560
+ }
561
+ if (resolved.isClassName) {
562
+ const generator2 = resolved.generator._withBuildContext({
563
+ callerName: name,
564
+ isProduction: this.isProduction,
565
+ config
566
+ });
567
+ const styles2 = await generator2.css;
568
+ if (!styles2) continue;
569
+ if (!cssFiles[generator2.priority]) cssFiles[generator2.priority] = [];
570
+ cssFiles[generator2.priority].push(generator2.cssFileName);
571
+ const filePath2 = `css/${generator2.cssFileName}`;
572
+ const cssPath2 = join(destDir, filePath2);
573
+ writeFileSync(cssPath2, styles2);
574
+ continue;
575
+ }
576
+ if (!resolved.generator) continue;
577
+ const generator = resolved.generator._withBuildContext({
578
+ callerName: name,
579
+ isProduction: this.isProduction,
580
+ config
581
+ });
582
+ const styles = await generator.css;
583
+ if (!styles) continue;
584
+ const filePath = `css/${generator.cssFileName}`;
585
+ const cssPath = join(destDir, filePath);
586
+ writeFileSync(cssPath, styles);
587
+ if (!cssFiles[generator.priority]) cssFiles[generator.priority] = [];
588
+ cssFiles[generator.priority].push(generator.cssFileName);
589
+ }
590
+ if (config.importStrategy !== "component") {
591
+ cssFiles.forEach((val, layer) => {
592
+ const layerFileName = `l_${layer}.css`;
593
+ const layerFilePath = join(destDir, "css", layerFileName);
594
+ let currentLayerFileContent = readFileSync(layerFilePath, "utf8");
595
+ val.forEach((file2) => {
596
+ var _a;
597
+ const filepath = join(destDir, "css", file2);
598
+ const filepathHash = ((_a = /.*-([^-]+)-\d+.css/.exec(file2)) == null ? void 0 : _a.at(1)) || toHash(filepath, 6);
599
+ const found = currentLayerFileContent.includes(filepathHash);
600
+ if (!found) {
601
+ const css = readFileSync(filepath, "utf8");
602
+ const newContent = `/*start:${filepathHash}-${file2}*/
603
+ ${css}
604
+ /*end:${filepathHash}*/
605
+ `;
606
+ currentLayerFileContent = `${currentLayerFileContent.replace(/\}$/, "")}
607
+ ${newContent}
608
+ }`;
609
+ }
610
+ });
611
+ writeFileSync(layerFilePath, currentLayerFileContent);
612
+ });
613
+ } else {
614
+ const cssContent = cssFiles.flat().map((file2) => `@import url('./${file2}');`).join("\n");
615
+ const hashName = toHash(file, 6);
616
+ const parsedPath = parse(file);
617
+ const dasherized = dashCase(parsedPath.name);
618
+ const cssFile = join(destDir, `css/f_${dasherized}-${hashName}.css`);
619
+ writeFileSync(cssFile, cssContent || `/* Empty file */`);
620
+ }
621
+ }
622
+ } catch (e) {
623
+ console.error(e);
624
+ }
625
+ });
544
626
  __publicField(this, "replaceStyledTag", (currentFile) => {
545
627
  return currentFile.replace(/styled\(([^"'`{,]+),/g, (match, tag) => {
546
628
  const isString = /^['"`]/.test(tag);
@@ -3,4 +3,5 @@ import { StyledParams } from '../types';
3
3
  export declare class ClassNameGenerator<const STYLE_PARAMS extends StyledParams = StyledParams> extends StylesGenerator<STYLE_PARAMS> {
4
4
  _params: STYLE_PARAMS;
5
5
  constructor(_params: STYLE_PARAMS);
6
+ get priority(): number;
6
7
  }
@@ -65,6 +65,10 @@ class ClassNameGenerator extends StylesGenerator {
65
65
  super(_params);
66
66
  this._params = _params;
67
67
  }
68
+ get priority() {
69
+ if (this.params.priority) return this.params.priority;
70
+ return 0;
71
+ }
68
72
  }
69
73
  class StyledGenerator extends StylesGenerator {
70
74
  constructor(tagName, _params) {
@@ -63,6 +63,10 @@ class ClassNameGenerator extends StylesGenerator {
63
63
  super(_params);
64
64
  this._params = _params;
65
65
  }
66
+ get priority() {
67
+ if (this.params.priority) return this.params.priority;
68
+ return 0;
69
+ }
66
70
  }
67
71
  class StyledGenerator extends StylesGenerator {
68
72
  constructor(tagName, _params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.304",
3
+ "version": "0.0.1-alpha.306",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",