@axerity/cli 0.1.3 → 0.1.4

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/bin/axerity.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  readdirSync,
11
11
  rmSync,
12
12
  symlinkSync,
13
+ watch,
13
14
  writeFileSync
14
15
  } from 'node:fs';
15
16
  import { basename, dirname, join, relative, resolve } from 'node:path';
@@ -67,6 +68,11 @@ function mountSpecs(config) {
67
68
  return { ...config, openapi };
68
69
  }
69
70
 
71
+ function writeConfig() {
72
+ const config = JSON.parse(readFileSync(join(userRoot, 'axerity.json'), 'utf8'));
73
+ writeFileSync(ENGINE_CONFIG, JSON.stringify(mountSpecs(config), null, '\t'));
74
+ }
75
+
70
76
  function mount(contentDir) {
71
77
  rmSync(ENGINE_DOCS, { recursive: true, force: true });
72
78
  mkdirSync(ENGINE_DOCS, { recursive: true });
@@ -74,8 +80,7 @@ function mount(contentDir) {
74
80
  symlinkSync(join(contentDir, entry), join(ENGINE_DOCS, entry), symlinkType);
75
81
  }
76
82
 
77
- const config = JSON.parse(readFileSync(join(userRoot, 'axerity.json'), 'utf8'));
78
- writeFileSync(ENGINE_CONFIG, JSON.stringify(mountSpecs(config), null, '\t'));
83
+ writeConfig();
79
84
 
80
85
  rmSync(ASSETS_DIR, { recursive: true, force: true });
81
86
  cpSync(ENGINE_STATIC, ASSETS_DIR, { recursive: true });
@@ -102,7 +107,9 @@ const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
102
107
  const banner = (sub) => process.stdout.write(`\n ${mark} ${bold('axerity')} ${dim(sub)}\n\n`);
103
108
 
104
109
  const NOISE =
105
- /^\s*(VITE v|➜|press h|ready in|Local:|Network:|\[vite\].*(optimiz|dependencies)|\[optimizer\]|Forced re-opt|watching for file changes|use --host)/i;
110
+ /^\s*(VITE v|➜|press h|ready in|Local:|Network:|use --host|watching for file changes)/i;
111
+ const VITE_CHATTER =
112
+ /\[optimizer\]|\[vite\].*(re-?optimiz|optimized dependencies|new dependencies|page reload|hmr update|dependencies because)/i;
106
113
 
107
114
  function streamServer(child) {
108
115
  let shown = false;
@@ -120,7 +127,7 @@ function streamServer(child) {
120
127
  process.stdout.write(` ${dim('Ctrl+C to stop')}\n\n`);
121
128
  continue;
122
129
  }
123
- if (!clean.trim() || NOISE.test(clean.trim())) continue;
130
+ if (!clean.trim() || NOISE.test(clean.trim()) || VITE_CHATTER.test(clean)) continue;
124
131
  process.stdout.write(` ${line}\n`);
125
132
  }
126
133
  };
@@ -163,10 +170,27 @@ function runEngine(sub, extra, { mounted, onSuccess }) {
163
170
  banner(sub);
164
171
  const build = sub === 'build' ? streamBuild(child) : (streamServer(child), null);
165
172
 
173
+ let configWatcher = null;
174
+ if (mounted && sub === 'dev') {
175
+ let timer = null;
176
+ configWatcher = watch(userRoot, (_event, filename) => {
177
+ if (filename !== 'axerity.json') return;
178
+ clearTimeout(timer);
179
+ timer = setTimeout(() => {
180
+ try {
181
+ writeConfig();
182
+ } catch {
183
+ return;
184
+ }
185
+ }, 80);
186
+ });
187
+ }
188
+
166
189
  let cleaned = false;
167
190
  const cleanup = () => {
168
191
  if (cleaned || !mounted) return;
169
192
  cleaned = true;
193
+ configWatcher?.close();
170
194
  tidy();
171
195
  };
172
196
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axerity/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A documentation site generator built with Svelte.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/vite.config.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { existsSync, readFileSync, watch } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import tailwindcss from '@tailwindcss/vite';
4
4
  import { sveltekit } from '@sveltejs/kit/vite';
5
5
  import { defineConfig } from 'vite';
6
6
  import { generateApiDocs } from './src/lib/openapi/generate';
7
7
 
8
- const allow = process.env.AXERITY_FS_ALLOW;
8
+ const mounted = !!process.env.AXERITY_FS_ALLOW;
9
9
 
10
10
  function openapi() {
11
11
  const localSpecs: string[] = [];
@@ -40,7 +40,28 @@ function openapi() {
40
40
  };
41
41
  }
42
42
 
43
+ function configReload() {
44
+ const file = resolve('axerity.json');
45
+ let watcher: ReturnType<typeof watch> | null = null;
46
+ return {
47
+ name: 'axerity:config-reload',
48
+ configureServer(server: import('vite').ViteDevServer) {
49
+ if (!existsSync(file)) return;
50
+ let timer: ReturnType<typeof setTimeout> | null = null;
51
+ watcher = watch(file, () => {
52
+ if (timer) clearTimeout(timer);
53
+ timer = setTimeout(() => server.watcher.emit('change', file), 50);
54
+ });
55
+ },
56
+ closeBundle() {
57
+ watcher?.close();
58
+ watcher = null;
59
+ }
60
+ };
61
+ }
62
+
43
63
  export default defineConfig({
44
- plugins: [openapi(), tailwindcss(), sveltekit()],
45
- server: allow ? { fs: { strict: false } } : undefined
64
+ plugins: [openapi(), ...(mounted ? [configReload()] : []), tailwindcss(), sveltekit()],
65
+ server: mounted ? { fs: { strict: false } } : undefined,
66
+ optimizeDeps: mounted ? { noDiscovery: true, include: ['@orama/orama', 'mermaid'] } : undefined
46
67
  });