@aeriajs/cli 0.0.263 → 0.0.264

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.
Files changed (3) hide show
  1. package/README.md +6 -7
  2. package/dist/watch.js +31 -24
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,11 +6,10 @@ This package ships the `aeria` command.
6
6
 
7
7
  ## Usage
8
8
 
9
- - `-w`: watch mode
10
- - `-c`: compile mode
11
- - `-i`: extract icons to `node_modules/.aeria` (required by `aeria-ui`)
12
- - `-m`: migrate mode (create indexes in MongoDB to speed up queries)
13
- - `-b`: generate a single minified file from the API
14
- - `-k`: generate (mirror) SDK files
15
- - `-t`: use `tsc` to transpile code instead of `esbuild` (slower)
9
+ - `-w --watch`: watch mode
10
+ - `-c --compile`: compile mode
11
+ - `-i --icons`: extract icons to `node_modules/.aeria` (required by `aeria-ui`)
12
+ - `-m --migrate`: migrate mode (create indexes in MongoDB to speed up queries)
13
+ - `-k --sdk`: generate (mirror) SDK files
14
+ - `-t --tsc`: use `tsc` to transpile code instead of `esbuild` (slower)
16
15
 
package/dist/watch.js CHANGED
@@ -58,6 +58,32 @@ export const spawnApi = async () => {
58
58
  return api;
59
59
  };
60
60
  export const watch = async (options = {}) => {
61
+ const handleChange = async (path) => {
62
+ if (runningApi) {
63
+ runningApi.kill();
64
+ if (!runningApi.killed && runningApi.exitCode === null) {
65
+ await new Promise((resolve) => {
66
+ runningApi.on('exit', () => {
67
+ resolve();
68
+ });
69
+ });
70
+ }
71
+ }
72
+ console.clear();
73
+ log('info', `change detected in file: ${path}`);
74
+ log('info', 'compiling...');
75
+ const compilationResult = await compileOnChanges(transpileCtx);
76
+ if (compilationResult.success) {
77
+ runningApi = await spawnApi();
78
+ if (compilationWorker) {
79
+ compilationWorker.send({});
80
+ }
81
+ fork(fileURLToPath(import.meta.resolve('./watchWorker.js')), {
82
+ env: await processEnv(),
83
+ detached: true,
84
+ });
85
+ }
86
+ };
61
87
  const tsConfig = await getUserTsconfig();
62
88
  const transpileCtx = !options.useTsc
63
89
  ? await transpile.init({
@@ -108,30 +134,11 @@ export const watch = async (options = {}) => {
108
134
  'tsconfig.json',
109
135
  '.env',
110
136
  ]);
111
- srcWatcher.on('change', async (filePath) => {
112
- if (runningApi) {
113
- runningApi.kill();
114
- if (!runningApi.killed && runningApi.exitCode === null) {
115
- await new Promise((resolve) => {
116
- runningApi.on('exit', () => {
117
- resolve();
118
- });
119
- });
120
- }
121
- }
122
- console.clear();
123
- log('info', `change detected in file: ${filePath}`);
124
- log('info', 'compiling...');
125
- const compilationResult = await compileOnChanges(transpileCtx);
126
- if (compilationResult.success) {
127
- runningApi = await spawnApi();
128
- if (compilationWorker) {
129
- compilationWorker.send({});
130
- }
131
- fork(fileURLToPath(import.meta.resolve('./watchWorker.js')), {
132
- env: await processEnv(),
133
- detached: true,
134
- });
137
+ let timeout;
138
+ srcWatcher.on('change', (path) => {
139
+ if (timeout) {
140
+ clearTimeout(timeout);
135
141
  }
142
+ timeout = setTimeout(() => handleChange(path), 100);
136
143
  });
137
144
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aeriajs/cli",
3
3
  "type": "module",
4
- "version": "0.0.263",
4
+ "version": "0.0.264",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",