create-caspian-app 0.2.0-beta.50 → 0.2.0-beta.52

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.
@@ -21,6 +21,7 @@ const { __dirname } = getFileMeta();
21
21
  const bs: BrowserSyncInstance = browserSync.create();
22
22
 
23
23
  const WORKSPACE_ROOT = join(__dirname, "..");
24
+ const PUBLIC_ROOT = join(WORKSPACE_ROOT, PUBLIC_DIR);
24
25
  const PUBLIC_IGNORE_DIRS = ["uploads"];
25
26
  let previousRouteFiles: string[] = [];
26
27
  let lastChangedFile: string | null = null;
@@ -228,7 +229,7 @@ function updateRouteFilesCache() {
228
229
  }
229
230
 
230
231
  function isIgnoredPublicPath(absPath: string): boolean {
231
- const normalizedPath = relative(WORKSPACE_ROOT, absPath).replace(/\\/g, "/");
232
+ const normalizedPath = relative(PUBLIC_ROOT, absPath).replace(/\\/g, "/");
232
233
 
233
234
  return PUBLIC_IGNORE_DIRS.some(
234
235
  (dir) => normalizedPath === dir || normalizedPath.startsWith(`${dir}/`),
@@ -266,7 +267,7 @@ const publicPipeline = new DebouncedWorker(
266
267
 
267
268
  createSrcWatcher(join(PUBLIC_DIR, "**", "*"), {
268
269
  onEvent: (_ev, abs, _) => {
269
- const relFromPublic = relative(PUBLIC_DIR, abs);
270
+ const relFromPublic = relative(PUBLIC_ROOT, abs).replace(/\\/g, "/");
270
271
  if (isIgnoredPublicPath(abs)) return;
271
272
  publicPipeline.schedule(relFromPublic);
272
273
  },
@@ -6,7 +6,7 @@ import process from "node:process";
6
6
 
7
7
  const mode: "watch" | "build" =
8
8
  process.argv[2] === "watch" ? "watch" : "build";
9
- const watcherPidFile = join(process.cwd(), ".pp", "postcss-watch.pid");
9
+ const watcherPidFile = join(process.cwd(), ".casp", "postcss-watch.pid");
10
10
  const mkdirAsync = promisify(mkdir);
11
11
  const readFileAsync = promisify(readFile);
12
12
  const rmAsync = promisify(rm);
@@ -1,8 +1,7 @@
1
1
  import { fileURLToPath } from "url";
2
- import { dirname } from "path";
2
+ import { dirname, extname, relative } from "path";
3
3
  import chokidar, { FSWatcher } from "chokidar";
4
4
  import { spawn, ChildProcess, execFile } from "child_process";
5
- import { relative } from "path";
6
5
 
7
6
  export const PUBLIC_DIR = "public";
8
7
  export const SRC_DIR = "src";
@@ -30,6 +29,24 @@ export const DEFAULT_IGNORES: (string | RegExp)[] = [
30
29
 
31
30
  export const DEFAULT_AWF = { stabilityThreshold: 300, pollInterval: 100 };
32
31
 
32
+ function hasGlobPattern(value: string): boolean {
33
+ return /[*{[]/.test(value);
34
+ }
35
+
36
+ function getWatchBase(root: string): string {
37
+ if (hasGlobPattern(root)) {
38
+ const globIndex = root.search(/[*{[]/);
39
+ const prefix = root.slice(0, globIndex).replace(/[\\/]+$/, "");
40
+ return prefix || ".";
41
+ }
42
+
43
+ return extname(root) ? dirname(root) : root;
44
+ }
45
+
46
+ function formatWatchTarget(root: string): string {
47
+ return root.replace(/\\/g, "/");
48
+ }
49
+
33
50
  export function createSrcWatcher(
34
51
  root: string,
35
52
  opts: {
@@ -50,6 +67,7 @@ export function createSrcWatcher(
50
67
  logPrefix = "watch",
51
68
  usePolling = true,
52
69
  } = opts;
70
+ const watchBase = getWatchBase(root);
53
71
 
54
72
  const watcher = chokidar.watch(root, {
55
73
  ignoreInitial: true,
@@ -62,14 +80,14 @@ export function createSrcWatcher(
62
80
 
63
81
  watcher
64
82
  .on("ready", () => {
65
- console.log(`[${logPrefix}] Watching ${root.replace(/\\/g, "/")}/**/*`);
83
+ console.log(`[${logPrefix}] Watching ${formatWatchTarget(root)}`);
66
84
  })
67
85
  .on("all", (event: WatchEvent, filePath: string) => {
68
86
  if (exts && exts.length > 0) {
69
87
  const ok = exts.some((ext) => filePath.endsWith(ext));
70
88
  if (!ok) return;
71
89
  }
72
- const rel = relative(root, filePath).replace(/\\/g, "/");
90
+ const rel = relative(watchBase, filePath).replace(/\\/g, "/");
73
91
  if (event === "add" || event === "change" || event === "unlink") {
74
92
  onEvent(event, filePath, rel);
75
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-caspian-app",
3
- "version": "0.2.0-beta.50",
3
+ "version": "0.2.0-beta.52",
4
4
  "description": "Scaffold a new Caspian project (FastAPI-powered reactive Python framework).",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",