forgecss 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.js ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+ import { program } from "commander";
7
+ import ForgeCSS from './index.js';
8
+ import chokidar from "chokidar";
9
+
10
+ program.option("--config", "Path to forgecss config file", process.cwd() + "/forgecss.config.js");
11
+ program.option("--watch", "Enable watch mode", false);
12
+ program.option("--verbose", "Enable watch mode", false);
13
+ program.parse();
14
+
15
+ const options = program.opts();
16
+ let config = null;
17
+
18
+ if (!fs.existsSync(options.config)) {
19
+ throw new Error(`forgecss: Config file not found at ${options.config}. Check the --config option.`);
20
+ }
21
+
22
+ async function loadConfig(configPath) {
23
+ const abs = path.resolve(configPath);
24
+ const fileUrl = pathToFileURL(abs).href;
25
+
26
+ const mod = await import(fileUrl);
27
+ return mod.default ?? mod; // support both default and named export
28
+ }
29
+ async function runForgeCSS() {
30
+ if (!config) {
31
+ config = await loadConfig(options.config);
32
+ if (options.watch) {
33
+ const watcher = chokidar.watch([
34
+ config.styles.sourceDir,
35
+ config.ui.sourceDir
36
+ ], {
37
+ persistent: true,
38
+ ignoreInitial: true,
39
+ ignored: (p, stats) => {
40
+ if (path.resolve(p) === path.resolve(config.output)){
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+ });
46
+ watcher.on("change", async (filePath) => {
47
+ if (options.verbose) {
48
+ console.log(`forgecss: Detected change in ${filePath}`);
49
+ }
50
+ runForgeCSS();
51
+ });
52
+ if (options.verbose) {
53
+ console.log("forgecss: Watch mode enabled. Listening for file changes...");
54
+ }
55
+ }
56
+ }
57
+ ForgeCSS(config).parse();
58
+ }
59
+
60
+ runForgeCSS();
61
+
package/fx.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function fx(classes: string): string;
package/fx.js ADDED
@@ -0,0 +1,3 @@
1
+ import forgeCSSExpressionTransformer from "./client/fx.js";
2
+
3
+ export default forgeCSSExpressionTransformer;
package/index.js CHANGED
@@ -2,9 +2,6 @@ import getAllFiles from "./lib/getAllFiles.js";
2
2
  import { extractStyles } from "./lib/styles.js";
3
3
  import { extractDeclarations } from "./lib/processFile.js";
4
4
  import { generateOutputCSS } from "./lib/generator.js";
5
- import forgeCSSExpressionTransformer from './client/fx.js';
6
-
7
- export const fx = forgeCSSExpressionTransformer;
8
5
 
9
6
  const DEFAULT_OPTIONS = {
10
7
  styles: {
package/lib/generator.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { writeFile } from "fs/promises";
2
- const OUTPUT = "forgecss-media-queries.css";
3
2
  import { getDeclarations } from "./processFile.js";
4
- import { createMediaStyle, extractStyles } from "./styles.js";
3
+ import { createMediaStyle } from "./styles.js";
5
4
 
6
5
  export async function generateOutputCSS(config) {
7
6
  const cache = {};
@@ -20,7 +19,7 @@ export async function generateOutputCSS(config) {
20
19
  .join("\n");
21
20
  await writeFile(
22
21
  config.output,
23
- `${result}`,
22
+ `/* ForgeCSS autogenerated file */\n${result}`,
24
23
  "utf-8"
25
24
  );
26
25
  }
@@ -3,7 +3,7 @@ import { readFile } from "fs/promises";
3
3
  import { fromHtml } from "hast-util-from-html";
4
4
  import { visit } from "unist-util-visit";
5
5
 
6
- const FUNC_NAME = 'mq';
6
+ const FUNC_NAME = 'fx';
7
7
  const DECLARATIONS = {};
8
8
 
9
9
  const { parse } = swc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgecss",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "ForgeCSS turns strings into fully generated responsive CSS using a custom DSL.",
6
6
  "author": "Krasimir Tsonev",
@@ -24,6 +24,8 @@
24
24
  "dependencies": {
25
25
  "@swc/cli": "^0.7.7",
26
26
  "@swc/core": "1.12.1",
27
+ "chokidar": "^4.0.3",
28
+ "commander": "^14.0.2",
27
29
  "hast-util-from-html": "^2.0.3",
28
30
  "postcss": "^8.5.6",
29
31
  "postcss-safe-parser": "^7.0.1",
@@ -31,5 +33,8 @@
31
33
  },
32
34
  "devDependencies": {
33
35
  "esbuild": "^0.27.1"
36
+ },
37
+ "bin": {
38
+ "forgecss": "./cli.js"
34
39
  }
35
40
  }