adminforth 1.3.54-next.22 → 1.3.54-next.23

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.
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { exec, spawn } from 'child_process';
11
2
  import crypto from 'crypto';
12
3
  import filewatcher from 'filewatcher';
@@ -38,21 +29,19 @@ function findHomePage(menuItem) {
38
29
  }
39
30
  return undefined;
40
31
  }
41
- function findFirstMenuItemWithResource(menuItem) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- for (const item of menuItem) {
44
- if (item.path || item.resourceId) {
45
- return item;
46
- }
47
- if (item.children) {
48
- const found = yield findFirstMenuItemWithResource(item.children);
49
- if (found) {
50
- return found;
51
- }
32
+ async function findFirstMenuItemWithResource(menuItem) {
33
+ for (const item of menuItem) {
34
+ if (item.path || item.resourceId) {
35
+ return item;
36
+ }
37
+ if (item.children) {
38
+ const found = await findFirstMenuItemWithResource(item.children);
39
+ if (found) {
40
+ return found;
52
41
  }
53
42
  }
54
- return undefined;
55
- });
43
+ }
44
+ return undefined;
56
45
  }
57
46
  const execAsync = promisify(exec);
58
47
  function hashify(obj) {
@@ -88,556 +77,542 @@ class CodeInjector {
88
77
  // console.timeEnd(`${command} done in`);
89
78
  // console.log(`Command ${command} output:`, out, err);
90
79
  // }
91
- runNpmShell(_a) {
92
- return __awaiter(this, arguments, void 0, function* ({ command, cwd }) {
93
- const nodeBinary = process.execPath; // Path to the Node.js binary running this script
94
- const npmPath = path.join(path.dirname(nodeBinary), 'npm'); // Path to the npm executable
95
- const env = Object.assign({ VITE_ADMINFORTH_PUBLIC_PATH: this.adminforth.config.baseUrl, FORCE_COLOR: '1' }, process.env);
96
- console.log(`⚙️ exec: npm ${command}...`);
97
- console.time(`npm ${command} done in`);
98
- const { stdout: out, stderr: err } = yield execAsync(`${nodeBinary} ${npmPath} ${command}`, {
99
- cwd,
100
- env,
101
- });
102
- console.timeEnd(`npm ${command} done in`);
103
- process.env.HEAVY_DEBUG && console.log(`🪲 npm ${command} output:`, out);
104
- if (err) {
105
- process.env.HEAVY_DEBUG && console.error(`🪲npm ${command} errors/warnings:`, err);
106
- }
80
+ async runNpmShell({ command, cwd }) {
81
+ const nodeBinary = process.execPath; // Path to the Node.js binary running this script
82
+ const npmPath = path.join(path.dirname(nodeBinary), 'npm'); // Path to the npm executable
83
+ const env = Object.assign({ VITE_ADMINFORTH_PUBLIC_PATH: this.adminforth.config.baseUrl, FORCE_COLOR: '1' }, process.env);
84
+ console.log(`⚙️ exec: npm ${command}...`);
85
+ console.time(`npm ${command} done in`);
86
+ const { stdout: out, stderr: err } = await execAsync(`${nodeBinary} ${npmPath} ${command}`, {
87
+ cwd,
88
+ env,
107
89
  });
90
+ console.timeEnd(`npm ${command} done in`);
91
+ process.env.HEAVY_DEBUG && console.log(`🪲 npm ${command} output:`, out);
92
+ if (err) {
93
+ process.env.HEAVY_DEBUG && console.error(`🪲npm ${command} errors/warnings:`, err);
94
+ }
108
95
  }
109
- rmTmpDir() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- // remove spa_tmp folder if it is exists
112
- try {
113
- yield fs.promises.rm(CodeInjector.SPA_TMP_PATH, { recursive: true });
114
- }
115
- catch (e) {
116
- // ignore
117
- }
118
- });
96
+ async rmTmpDir() {
97
+ // remove spa_tmp folder if it is exists
98
+ try {
99
+ await fs.promises.rm(CodeInjector.SPA_TMP_PATH, { recursive: true });
100
+ }
101
+ catch (e) {
102
+ // ignore
103
+ }
119
104
  }
120
- packagesFromNpm(dir) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- const usersPackagePath = path.join(dir, 'package.json');
123
- let packageContent = null;
124
- let lockHash = '';
125
- let packages = [];
105
+ async packagesFromNpm(dir) {
106
+ const usersPackagePath = path.join(dir, 'package.json');
107
+ let packageContent = null;
108
+ let lockHash = '';
109
+ let packages = [];
110
+ try {
111
+ packageContent = JSON.parse(await fs.promises.readFile(usersPackagePath, 'utf-8'));
112
+ }
113
+ catch (e) {
114
+ // user package.json does not exist, user does not have custom components
115
+ }
116
+ if (packageContent) {
117
+ const lockPath = path.join(dir, 'package-lock.json');
118
+ let lock = null;
126
119
  try {
127
- packageContent = JSON.parse(yield fs.promises.readFile(usersPackagePath, 'utf-8'));
120
+ lock = JSON.parse(await fs.promises.readFile(lockPath, 'utf-8'));
128
121
  }
129
122
  catch (e) {
130
- // user package.json does not exist, user does not have custom components
131
- }
132
- if (packageContent) {
133
- const lockPath = path.join(dir, 'package-lock.json');
134
- let lock = null;
135
- try {
136
- lock = JSON.parse(yield fs.promises.readFile(lockPath, 'utf-8'));
137
- }
138
- catch (e) {
139
- throw new Error(`Custom package-lock.json does not exist in ${dir}, but package.json does.
123
+ throw new Error(`Custom package-lock.json does not exist in ${dir}, but package.json does.
140
124
  We can't determine version of packages without package-lock.json. Please run npm install in ${dir}`);
141
- }
142
- lockHash = hashify(lock);
143
- packages = [
144
- ...Object.keys(packageContent.dependencies || []),
145
- ...Object.keys(packageContent.devDependencies || [])
146
- ].reduce((acc, packageName) => {
147
- const pack = lock.packages[`node_modules/${packageName}`];
148
- if (!pack) {
149
- throw new Error(`Package ${packageName} is not in package-lock.json but is in package.json. Please run 'npm install' in ${dir}`);
150
- }
151
- const version = pack.version;
152
- acc.push(`${packageName}@${version}`);
153
- return acc;
154
- }, []);
155
125
  }
156
- return [lockHash, packages];
157
- });
126
+ lockHash = hashify(lock);
127
+ packages = [
128
+ ...Object.keys(packageContent.dependencies || []),
129
+ ...Object.keys(packageContent.devDependencies || [])
130
+ ].reduce((acc, packageName) => {
131
+ const pack = lock.packages[`node_modules/${packageName}`];
132
+ if (!pack) {
133
+ throw new Error(`Package ${packageName} is not in package-lock.json but is in package.json. Please run 'npm install' in ${dir}`);
134
+ }
135
+ const version = pack.version;
136
+ acc.push(`${packageName}@${version}`);
137
+ return acc;
138
+ }, []);
139
+ }
140
+ return [lockHash, packages];
158
141
  }
159
- prepareSources(_a) {
160
- return __awaiter(this, arguments, void 0, function* ({ filesUpdated }) {
161
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
162
- // check SPA_TMP_PATH exists and create if not
163
- try {
164
- yield fs.promises.access(CodeInjector.SPA_TMP_PATH, fs.constants.F_OK);
165
- }
166
- catch (e) {
167
- yield fs.promises.mkdir(CodeInjector.SPA_TMP_PATH, { recursive: true });
168
- }
169
- const icons = [];
170
- let routes = '';
171
- let routerComponents = '';
172
- const collectAssetsFromMenu = (menu) => {
173
- menu.forEach((item) => {
174
- var _a, _b, _c, _d;
175
- if (item.icon) {
176
- icons.push(item.icon);
177
- }
178
- if (item.component) {
179
- if (Object.keys(item).includes('isStaticRoute')) {
180
- if (!item.isStaticRoute) {
181
- routes += `{
142
+ async prepareSources({ filesUpdated }) {
143
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
144
+ // check SPA_TMP_PATH exists and create if not
145
+ try {
146
+ await fs.promises.access(CodeInjector.SPA_TMP_PATH, fs.constants.F_OK);
147
+ }
148
+ catch (e) {
149
+ await fs.promises.mkdir(CodeInjector.SPA_TMP_PATH, { recursive: true });
150
+ }
151
+ const icons = [];
152
+ let routes = '';
153
+ let routerComponents = '';
154
+ const collectAssetsFromMenu = (menu) => {
155
+ menu.forEach((item) => {
156
+ var _a, _b, _c, _d;
157
+ if (item.icon) {
158
+ icons.push(item.icon);
159
+ }
160
+ if (item.component) {
161
+ if (Object.keys(item).includes('isStaticRoute')) {
162
+ if (!item.isStaticRoute) {
163
+ routes += `{
182
164
  path: '${item.path}',
183
165
  name: '${item.path}',
184
166
  component: () => import('${item.component}'),
185
167
  meta: { title: '${((_a = item === null || item === void 0 ? void 0 : item.meta) === null || _a === void 0 ? void 0 : _a.title) || item.path.replace('/', '')}'}
186
168
  },\n`;
187
- }
188
- else {
189
- routes += `{
169
+ }
170
+ else {
171
+ routes += `{
190
172
  path: '${item.path}',
191
173
  name: '${item.path}',
192
174
  component: ${getComponentNameFromPath(item.component)},
193
175
  meta: { title: '${((_b = item === null || item === void 0 ? void 0 : item.meta) === null || _b === void 0 ? void 0 : _b.title) || item.path.replace('/', '')}'}
194
176
  },\n`;
195
- const componentName = `${getComponentNameFromPath(item.component)}`;
196
- routerComponents += `import ${componentName} from '${item.component}';\n`;
197
- }
177
+ const componentName = `${getComponentNameFromPath(item.component)}`;
178
+ routerComponents += `import ${componentName} from '${item.component}';\n`;
198
179
  }
199
- else {
200
- if (item.homepage) {
201
- routes += `{
180
+ }
181
+ else {
182
+ if (item.homepage) {
183
+ routes += `{
202
184
  path: '${item.path}',
203
185
  name: '${item.path}',
204
186
  component: ${getComponentNameFromPath(item.component)},
205
187
  meta: { title: '${((_c = item === null || item === void 0 ? void 0 : item.meta) === null || _c === void 0 ? void 0 : _c.title) || item.path.replace('/', '')}'}
206
188
  },\n`;
207
- const componentName = `${getComponentNameFromPath(item.component)}`;
208
- routerComponents += `import ${componentName} from '${item.component}';\n`;
209
- }
210
- else {
211
- routes += `{
189
+ const componentName = `${getComponentNameFromPath(item.component)}`;
190
+ routerComponents += `import ${componentName} from '${item.component}';\n`;
191
+ }
192
+ else {
193
+ routes += `{
212
194
  path: '${item.path}',
213
195
  name: '${item.path}',
214
196
  component: () => import('${item.component}'),
215
197
  meta: { title: '${((_d = item === null || item === void 0 ? void 0 : item.meta) === null || _d === void 0 ? void 0 : _d.title) || item.path.replace('/', '')}'}
216
198
  },\n`;
217
- }
218
199
  }
219
200
  }
220
- if (item.children) {
221
- collectAssetsFromMenu(item.children);
222
- }
223
- });
224
- };
225
- const registerCustomPages = (config) => {
226
- if (config.customization.customPages) {
227
- config.customization.customPages.forEach((page) => {
228
- var _a, _b, _c;
229
- routes += `{
201
+ }
202
+ if (item.children) {
203
+ collectAssetsFromMenu(item.children);
204
+ }
205
+ });
206
+ };
207
+ const registerCustomPages = (config) => {
208
+ if (config.customization.customPages) {
209
+ config.customization.customPages.forEach((page) => {
210
+ var _a, _b, _c;
211
+ routes += `{
230
212
  path: '${page.path}',
231
213
  name: '${page.path}',
232
214
  component: () => import('${((_a = page === null || page === void 0 ? void 0 : page.component) === null || _a === void 0 ? void 0 : _a.file) || page.component}'),
233
215
  meta: ${JSON.stringify(Object.assign(Object.assign({}, (((_b = page === null || page === void 0 ? void 0 : page.component) === null || _b === void 0 ? void 0 : _b.meta) || {})), { title: ((_c = page.meta) === null || _c === void 0 ? void 0 : _c.title) || page.path.replace('/', '') }))}
234
216
  },`;
235
- });
236
- }
237
- };
238
- registerCustomPages(this.adminforth.config);
239
- collectAssetsFromMenu(this.adminforth.config.menu);
240
- if (filesUpdated) {
241
- // copy only updated files
242
- yield Promise.all(filesUpdated.map((file) => __awaiter(this, void 0, void 0, function* () {
243
- const src = path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa', file);
244
- const dest = path.join(CodeInjector.SPA_TMP_PATH, file);
245
- // overwrite:true can't be used to not destroy cache
246
- yield fsExtra.copy(src, dest, {
247
- dereference: true, // needed to dereference types
248
- });
249
- if (process.env.HEAVY_DEBUG) {
250
- console.log('🪲⚙️ fsExtra.copy copy single file', src, dest);
251
- }
252
- })));
217
+ });
253
218
  }
254
- else {
255
- if (process.env.HEAVY_DEBUG) {
256
- console.log(`🪲⚙️ fsExtra.copy from ${path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa')}, -> ${CodeInjector.SPA_TMP_PATH}`);
257
- }
258
- // try to rm SPA_TMP_PATH/src/types directory
259
- try {
260
- yield fs.promises.rm(path.join(CodeInjector.SPA_TMP_PATH, 'src', 'types'), { recursive: true });
261
- }
262
- catch (e) {
263
- // ignore
264
- }
265
- // overwrite can't be used to not destroy cache
266
- yield fsExtra.copy(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa'), CodeInjector.SPA_TMP_PATH, {
267
- filter: (src) => {
268
- const filterPasses = !src.includes('/adminforth/spa/node_modules') && !src.includes('/adminforth/spa/dist');
269
- if (process.env.HEAVY_DEBUG && !filterPasses) {
270
- console.log('🪲⚙️ fsExtra.copy filtered out', src);
271
- }
272
- return filterPasses;
273
- },
219
+ };
220
+ registerCustomPages(this.adminforth.config);
221
+ collectAssetsFromMenu(this.adminforth.config.menu);
222
+ if (filesUpdated) {
223
+ // copy only updated files
224
+ await Promise.all(filesUpdated.map(async (file) => {
225
+ const src = path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa', file);
226
+ const dest = path.join(CodeInjector.SPA_TMP_PATH, file);
227
+ // overwrite:true can't be used to not destroy cache
228
+ await fsExtra.copy(src, dest, {
274
229
  dereference: true, // needed to dereference types
275
230
  });
276
- // copy whole custom directory
277
- if ((_b = this.adminforth.config.customization) === null || _b === void 0 ? void 0 : _b.customComponentsDir) {
278
- // resolve customComponentsDir to absolute path, so ./aa will be resolved to /path/to/current/dir/aa
279
- const customCompAbsPath = path.resolve(this.adminforth.config.customization.customComponentsDir);
280
- this.srcFoldersToSync[customCompAbsPath] = './';
281
- }
282
- // if this.adminforth.config.customization.favicon is set, copy it to assets
283
- const customFav = (_c = this.adminforth.config.customization) === null || _c === void 0 ? void 0 : _c.favicon;
284
- if (customFav) {
285
- const faviconPath = path.join((_d = this.adminforth.config.customization) === null || _d === void 0 ? void 0 : _d.customComponentsDir, customFav.replace('@@/', ''));
286
- const dest = path.join(CodeInjector.SPA_TMP_PATH, 'public', 'assets', customFav.replace('@@/', ''));
287
- // make sure all folders in dest exist
288
- yield fsExtra.ensureDir(path.dirname(dest));
289
- yield fsExtra.copy(faviconPath, dest);
231
+ if (process.env.HEAVY_DEBUG) {
232
+ console.log('🪲⚙️ fsExtra.copy copy single file', src, dest);
290
233
  }
291
- for (const [src, dest] of Object.entries(this.srcFoldersToSync)) {
292
- const to = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'custom', dest);
293
- if (process.env.HEAVY_DEBUG) {
294
- console.log(`🪲⚙️ fsExtra.copy from ${src}, ${to}`);
234
+ }));
235
+ }
236
+ else {
237
+ if (process.env.HEAVY_DEBUG) {
238
+ console.log(`🪲⚙️ fsExtra.copy from ${path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa')}, -> ${CodeInjector.SPA_TMP_PATH}`);
239
+ }
240
+ // try to rm SPA_TMP_PATH/src/types directory
241
+ try {
242
+ await fs.promises.rm(path.join(CodeInjector.SPA_TMP_PATH, 'src', 'types'), { recursive: true });
243
+ }
244
+ catch (e) {
245
+ // ignore
246
+ }
247
+ // overwrite can't be used to not destroy cache
248
+ await fsExtra.copy(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa'), CodeInjector.SPA_TMP_PATH, {
249
+ filter: (src) => {
250
+ const filterPasses = !src.includes('/adminforth/spa/node_modules') && !src.includes('/adminforth/spa/dist');
251
+ if (process.env.HEAVY_DEBUG && !filterPasses) {
252
+ console.log('🪲⚙️ fsExtra.copy filtered out', src);
295
253
  }
296
- yield fsExtra.copy(src, to, {
297
- recursive: true,
298
- dereference: true,
299
- });
254
+ return filterPasses;
255
+ },
256
+ dereference: true, // needed to dereference types
257
+ });
258
+ // copy whole custom directory
259
+ if ((_a = this.adminforth.config.customization) === null || _a === void 0 ? void 0 : _a.customComponentsDir) {
260
+ // resolve customComponentsDir to absolute path, so ./aa will be resolved to /path/to/current/dir/aa
261
+ const customCompAbsPath = path.resolve(this.adminforth.config.customization.customComponentsDir);
262
+ this.srcFoldersToSync[customCompAbsPath] = './';
263
+ }
264
+ // if this.adminforth.config.customization.favicon is set, copy it to assets
265
+ const customFav = (_b = this.adminforth.config.customization) === null || _b === void 0 ? void 0 : _b.favicon;
266
+ if (customFav) {
267
+ const faviconPath = path.join((_c = this.adminforth.config.customization) === null || _c === void 0 ? void 0 : _c.customComponentsDir, customFav.replace('@@/', ''));
268
+ const dest = path.join(CodeInjector.SPA_TMP_PATH, 'public', 'assets', customFav.replace('@@/', ''));
269
+ // make sure all folders in dest exist
270
+ await fsExtra.ensureDir(path.dirname(dest));
271
+ await fsExtra.copy(faviconPath, dest);
272
+ }
273
+ for (const [src, dest] of Object.entries(this.srcFoldersToSync)) {
274
+ const to = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'custom', dest);
275
+ if (process.env.HEAVY_DEBUG) {
276
+ console.log(`🪲⚙️ fsExtra.copy from ${src}, ${to}`);
300
277
  }
278
+ await fsExtra.copy(src, to, {
279
+ recursive: true,
280
+ dereference: true,
281
+ });
301
282
  }
302
- //collect all 'icon' fields from resources bulkActions
303
- this.adminforth.config.resources.forEach((resource) => {
304
- var _a;
305
- if ((_a = resource.options) === null || _a === void 0 ? void 0 : _a.bulkActions) {
306
- resource.options.bulkActions.forEach((action) => {
307
- if (action.icon) {
308
- icons.push(action.icon);
309
- }
310
- });
311
- }
312
- });
313
- const uniqueIcons = Array.from(new Set(icons));
314
- // icons are collectionName:iconName. Get list of all unique collection names:
315
- const collections = new Set(icons.map((icon) => icon.split(':')[0]));
316
- // package names @iconify-prerendered/vue-<collection name>
317
- const iconPackageNames = Array.from(collections).map((collection) => `@iconify-prerendered/vue-${collection}`);
318
- // for each icon generate import statement
319
- const iconImports = uniqueIcons.map((icon) => {
320
- const [collection, iconName] = icon.split(':');
321
- const PascalIconName = 'Icon' + iconName.split('-').map((part, index) => {
322
- return part[0].toUpperCase() + part.slice(1);
323
- }).join('');
324
- return `import { ${PascalIconName} } from '@iconify-prerendered/vue-${collection}';`;
325
- }).join('\n');
326
- // for each custom component generate import statement
327
- const customResourceComponents = [];
328
- function checkInjections(filePathes) {
329
- filePathes.forEach(({ file }) => {
330
- if (!customResourceComponents.includes(file)) {
331
- if (file === undefined) {
332
- throw new Error('file is undefined');
333
- }
334
- customResourceComponents.push(file);
283
+ }
284
+ //collect all 'icon' fields from resources bulkActions
285
+ this.adminforth.config.resources.forEach((resource) => {
286
+ var _a;
287
+ if ((_a = resource.options) === null || _a === void 0 ? void 0 : _a.bulkActions) {
288
+ resource.options.bulkActions.forEach((action) => {
289
+ if (action.icon) {
290
+ icons.push(action.icon);
335
291
  }
336
292
  });
337
293
  }
338
- this.adminforth.config.resources.forEach((resource) => {
339
- var _a;
340
- resource.columns.forEach((column) => {
341
- if (column.components) {
342
- Object.values(column.components).forEach(({ file }) => {
343
- if (!customResourceComponents.includes(file)) {
344
- if (file === undefined) {
345
- throw new Error('file is undefined from field.components, field:' + JSON.stringify(column));
346
- }
347
- customResourceComponents.push(file);
348
- }
349
- });
294
+ });
295
+ const uniqueIcons = Array.from(new Set(icons));
296
+ // icons are collectionName:iconName. Get list of all unique collection names:
297
+ const collections = new Set(icons.map((icon) => icon.split(':')[0]));
298
+ // package names @iconify-prerendered/vue-<collection name>
299
+ const iconPackageNames = Array.from(collections).map((collection) => `@iconify-prerendered/vue-${collection}`);
300
+ // for each icon generate import statement
301
+ const iconImports = uniqueIcons.map((icon) => {
302
+ const [collection, iconName] = icon.split(':');
303
+ const PascalIconName = 'Icon' + iconName.split('-').map((part, index) => {
304
+ return part[0].toUpperCase() + part.slice(1);
305
+ }).join('');
306
+ return `import { ${PascalIconName} } from '@iconify-prerendered/vue-${collection}';`;
307
+ }).join('\n');
308
+ // for each custom component generate import statement
309
+ const customResourceComponents = [];
310
+ function checkInjections(filePathes) {
311
+ filePathes.forEach(({ file }) => {
312
+ if (!customResourceComponents.includes(file)) {
313
+ if (file === undefined) {
314
+ throw new Error('file is undefined');
350
315
  }
351
- });
352
- (Object.values(((_a = resource.options) === null || _a === void 0 ? void 0 : _a.pageInjections) || {})).forEach((injection) => {
353
- Object.values(injection).forEach((filePathes) => {
354
- checkInjections(filePathes);
316
+ customResourceComponents.push(file);
317
+ }
318
+ });
319
+ }
320
+ this.adminforth.config.resources.forEach((resource) => {
321
+ var _a;
322
+ resource.columns.forEach((column) => {
323
+ if (column.components) {
324
+ Object.values(column.components).forEach(({ file }) => {
325
+ if (!customResourceComponents.includes(file)) {
326
+ if (file === undefined) {
327
+ throw new Error('file is undefined from field.components, field:' + JSON.stringify(column));
328
+ }
329
+ customResourceComponents.push(file);
330
+ }
355
331
  });
356
- });
332
+ }
357
333
  });
358
- if ((_e = this.adminforth.config.customization) === null || _e === void 0 ? void 0 : _e.globalInjections) {
359
- Object.values(this.adminforth.config.customization.globalInjections).forEach((injection) => {
360
- checkInjections(injection);
334
+ (Object.values(((_a = resource.options) === null || _a === void 0 ? void 0 : _a.pageInjections) || {})).forEach((injection) => {
335
+ Object.values(injection).forEach((filePathes) => {
336
+ checkInjections(filePathes);
361
337
  });
362
- }
363
- customResourceComponents.forEach((filePath) => {
364
- const componentName = getComponentNameFromPath(filePath);
365
- this.allComponentNames[filePath] = componentName;
366
338
  });
367
- // console.log('🔧 Injecting code into Vue sources...', this.allComponentNames);
368
- let customComponentsImports = '';
369
- for (const [targetPath, component] of Object.entries(this.allComponentNames)) {
370
- customComponentsImports += `import ${component} from '${targetPath}';\n`;
371
- }
372
- // Generate Vue.component statements for each icon
373
- const iconComponents = uniqueIcons.map((icon) => {
374
- const [collection, iconName] = icon.split(':');
375
- const PascalIconName = 'Icon' + iconName.split('-').map((part, index) => {
376
- return part[0].toUpperCase() + part.slice(1);
377
- }).join('');
378
- return `app.component('${PascalIconName}', ${PascalIconName});`;
379
- }).join('\n');
380
- // Generate Vue.component statements for each custom component
381
- let customComponentsComponents = '';
382
- for (const name of Object.values(this.allComponentNames)) {
383
- customComponentsComponents += `app.component('${name}', ${name});\n`;
384
- }
385
- let imports = iconImports + '\n';
386
- imports += customComponentsImports + '\n';
387
- if ((_f = this.adminforth.config.customization) === null || _f === void 0 ? void 0 : _f.vueUsesFile) {
388
- imports += `import addCustomUses from '${this.adminforth.config.customization.vueUsesFile}';\n`;
389
- }
390
- // inject that code into spa_tmp/src/App.vue
391
- const appVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'main.ts');
392
- let appVueContent = yield fs.promises.readFile(appVuePath, 'utf-8');
393
- appVueContent = appVueContent.replace('/* IMPORTANT:ADMINFORTH IMPORTS */', imports);
394
- appVueContent = appVueContent.replace('/* IMPORTANT:ADMINFORTH COMPONENT REGISTRATIONS */', iconComponents + '\n' + customComponentsComponents + '\n');
395
- if ((_g = this.adminforth.config.customization) === null || _g === void 0 ? void 0 : _g.vueUsesFile) {
396
- appVueContent = appVueContent.replace('/* IMPORTANT:ADMINFORTH CUSTOM USES */', 'addCustomUses(app);');
397
- }
398
- yield fs.promises.writeFile(appVuePath, appVueContent);
399
- // generate tailwind extend styles
400
- const stylesGenerator = new StylesGenerator((_h = this.adminforth.config.customization) === null || _h === void 0 ? void 0 : _h.styles);
401
- const stylesText = JSON.stringify(stylesGenerator.mergeStyles(), null, 2).slice(1, -1);
402
- let tailwindConfigPath = path.join(CodeInjector.SPA_TMP_PATH, 'tailwind.config.js');
403
- let tailwindConfigContent = yield fs.promises.readFile(tailwindConfigPath, 'utf-8');
404
- tailwindConfigContent = tailwindConfigContent.replace('/* IMPORTANT:ADMINFORTH TAILWIND STYLES */', stylesText);
405
- yield fs.promises.writeFile(tailwindConfigPath, tailwindConfigContent);
406
- const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
407
- let routerVueContent = yield fs.promises.readFile(routerVuePath, 'utf-8');
408
- routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES IMPORTS */', routerComponents);
409
- // inject title to index.html
410
- const indexHtmlPath = path.join(CodeInjector.SPA_TMP_PATH, 'index.html');
411
- let indexHtmlContent = yield fs.promises.readFile(indexHtmlPath, 'utf-8');
412
- indexHtmlContent = indexHtmlContent.replace('/* IMPORTANT:ADMINFORTH TITLE */', `${this.adminforth.config.customization.title || 'AdminForth'}`);
413
- indexHtmlContent = indexHtmlContent.replace('/* IMPORTANT:ADMINFORTH FAVICON */', ((_j = this.adminforth.config.customization.favicon) === null || _j === void 0 ? void 0 : _j.replace('@@/', `${this.adminforth.baseUrlSlashed}assets/`))
414
- ||
415
- `${this.adminforth.baseUrlSlashed}assets/favicon.png`);
416
- yield fs.promises.writeFile(indexHtmlPath, indexHtmlContent);
417
- /* generate custom routes */
418
- let homepageMenuItem = findHomePage(this.adminforth.config.menu);
419
- if (!homepageMenuItem) {
420
- // find first item with path or resourceId. If we face a menu item with children earlier then path/resourceId, we should search in children
421
- homepageMenuItem = yield findFirstMenuItemWithResource(this.adminforth.config.menu);
422
- }
423
- if (!homepageMenuItem) {
424
- throw new Error('No homepage found in menu and no menu item with path/resourceId found. AdminForth can not generate routes');
425
- }
426
- let homePagePath = homepageMenuItem.path || `/resource/${homepageMenuItem.resourceId}`;
427
- if (!homePagePath) {
428
- homePagePath = ((_k = this.adminforth.config.menu.filter((mi) => mi.path)[0]) === null || _k === void 0 ? void 0 : _k.path) || `/resource/${(_l = this.adminforth.config.menu.filter((mi) => mi.children)[0]) === null || _l === void 0 ? void 0 : _l.resourceId}`;
429
- }
430
- routes += `{
339
+ });
340
+ if ((_d = this.adminforth.config.customization) === null || _d === void 0 ? void 0 : _d.globalInjections) {
341
+ Object.values(this.adminforth.config.customization.globalInjections).forEach((injection) => {
342
+ checkInjections(injection);
343
+ });
344
+ }
345
+ customResourceComponents.forEach((filePath) => {
346
+ const componentName = getComponentNameFromPath(filePath);
347
+ this.allComponentNames[filePath] = componentName;
348
+ });
349
+ // console.log('🔧 Injecting code into Vue sources...', this.allComponentNames);
350
+ let customComponentsImports = '';
351
+ for (const [targetPath, component] of Object.entries(this.allComponentNames)) {
352
+ customComponentsImports += `import ${component} from '${targetPath}';\n`;
353
+ }
354
+ // Generate Vue.component statements for each icon
355
+ const iconComponents = uniqueIcons.map((icon) => {
356
+ const [collection, iconName] = icon.split(':');
357
+ const PascalIconName = 'Icon' + iconName.split('-').map((part, index) => {
358
+ return part[0].toUpperCase() + part.slice(1);
359
+ }).join('');
360
+ return `app.component('${PascalIconName}', ${PascalIconName});`;
361
+ }).join('\n');
362
+ // Generate Vue.component statements for each custom component
363
+ let customComponentsComponents = '';
364
+ for (const name of Object.values(this.allComponentNames)) {
365
+ customComponentsComponents += `app.component('${name}', ${name});\n`;
366
+ }
367
+ let imports = iconImports + '\n';
368
+ imports += customComponentsImports + '\n';
369
+ if ((_e = this.adminforth.config.customization) === null || _e === void 0 ? void 0 : _e.vueUsesFile) {
370
+ imports += `import addCustomUses from '${this.adminforth.config.customization.vueUsesFile}';\n`;
371
+ }
372
+ // inject that code into spa_tmp/src/App.vue
373
+ const appVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'main.ts');
374
+ let appVueContent = await fs.promises.readFile(appVuePath, 'utf-8');
375
+ appVueContent = appVueContent.replace('/* IMPORTANT:ADMINFORTH IMPORTS */', imports);
376
+ appVueContent = appVueContent.replace('/* IMPORTANT:ADMINFORTH COMPONENT REGISTRATIONS */', iconComponents + '\n' + customComponentsComponents + '\n');
377
+ if ((_f = this.adminforth.config.customization) === null || _f === void 0 ? void 0 : _f.vueUsesFile) {
378
+ appVueContent = appVueContent.replace('/* IMPORTANT:ADMINFORTH CUSTOM USES */', 'addCustomUses(app);');
379
+ }
380
+ await fs.promises.writeFile(appVuePath, appVueContent);
381
+ // generate tailwind extend styles
382
+ const stylesGenerator = new StylesGenerator((_g = this.adminforth.config.customization) === null || _g === void 0 ? void 0 : _g.styles);
383
+ const stylesText = JSON.stringify(stylesGenerator.mergeStyles(), null, 2).slice(1, -1);
384
+ let tailwindConfigPath = path.join(CodeInjector.SPA_TMP_PATH, 'tailwind.config.js');
385
+ let tailwindConfigContent = await fs.promises.readFile(tailwindConfigPath, 'utf-8');
386
+ tailwindConfigContent = tailwindConfigContent.replace('/* IMPORTANT:ADMINFORTH TAILWIND STYLES */', stylesText);
387
+ await fs.promises.writeFile(tailwindConfigPath, tailwindConfigContent);
388
+ const routerVuePath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'router', 'index.ts');
389
+ let routerVueContent = await fs.promises.readFile(routerVuePath, 'utf-8');
390
+ routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES IMPORTS */', routerComponents);
391
+ // inject title to index.html
392
+ const indexHtmlPath = path.join(CodeInjector.SPA_TMP_PATH, 'index.html');
393
+ let indexHtmlContent = await fs.promises.readFile(indexHtmlPath, 'utf-8');
394
+ indexHtmlContent = indexHtmlContent.replace('/* IMPORTANT:ADMINFORTH TITLE */', `${this.adminforth.config.customization.title || 'AdminForth'}`);
395
+ indexHtmlContent = indexHtmlContent.replace('/* IMPORTANT:ADMINFORTH FAVICON */', ((_h = this.adminforth.config.customization.favicon) === null || _h === void 0 ? void 0 : _h.replace('@@/', `${this.adminforth.baseUrlSlashed}assets/`))
396
+ ||
397
+ `${this.adminforth.baseUrlSlashed}assets/favicon.png`);
398
+ await fs.promises.writeFile(indexHtmlPath, indexHtmlContent);
399
+ /* generate custom routes */
400
+ let homepageMenuItem = findHomePage(this.adminforth.config.menu);
401
+ if (!homepageMenuItem) {
402
+ // find first item with path or resourceId. If we face a menu item with children earlier then path/resourceId, we should search in children
403
+ homepageMenuItem = await findFirstMenuItemWithResource(this.adminforth.config.menu);
404
+ }
405
+ if (!homepageMenuItem) {
406
+ throw new Error('No homepage found in menu and no menu item with path/resourceId found. AdminForth can not generate routes');
407
+ }
408
+ let homePagePath = homepageMenuItem.path || `/resource/${homepageMenuItem.resourceId}`;
409
+ if (!homePagePath) {
410
+ homePagePath = ((_j = this.adminforth.config.menu.filter((mi) => mi.path)[0]) === null || _j === void 0 ? void 0 : _j.path) || `/resource/${(_k = this.adminforth.config.menu.filter((mi) => mi.children)[0]) === null || _k === void 0 ? void 0 : _k.resourceId}`;
411
+ }
412
+ routes += `{
431
413
  path: '/',
432
414
  name: 'home',
433
415
  //redirect to login
434
416
  redirect: '${homePagePath}'
435
417
  },\n`;
436
- routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES */', routes);
437
- yield fs.promises.writeFile(routerVuePath, routerVueContent);
438
- /* hash checking */
439
- const spaPackageLockPath = path.join(CodeInjector.SPA_TMP_PATH, 'package-lock.json');
440
- const spaPackageLock = JSON.parse(yield fs.promises.readFile(spaPackageLockPath, 'utf-8'));
441
- const spaLockHash = hashify(spaPackageLock);
442
- /* customPackageLock */
443
- let usersLockHash = '';
444
- let usersPackages = [];
445
- if ((_m = this.adminforth.config.customization) === null || _m === void 0 ? void 0 : _m.customComponentsDir) {
446
- [usersLockHash, usersPackages] = yield this.packagesFromNpm(this.adminforth.config.customization.customComponentsDir);
447
- }
448
- const pluginPackages = [];
449
- // for every installed plugin generate packages
450
- for (const plugin of this.adminforth.activatedPlugins) {
451
- process.env.HEAVY_DEBUG && console.log('🔧 Checking packages for plugin', plugin.constructor.name, plugin.customFolderPath);
452
- const [lockHash, packages] = yield this.packagesFromNpm(plugin.customFolderPath);
453
- if (packages.length) {
454
- pluginPackages.push({
455
- pluginName: plugin.constructor.name,
456
- lockHash,
457
- packages,
458
- });
459
- }
460
- }
461
- // form string "pluginName:lockHash::pLugin2Name:lockHash"
462
- const pluginsLockHash = pluginPackages.map(({ pluginName, lockHash }) => `${pluginName}>${lockHash}`).join('::');
463
- const iconPackagesNamesHash = hashify(iconPackageNames);
464
- const fullHash = `spa>${spaLockHash}::icons>${iconPackagesNamesHash}::user/custom>${usersLockHash}::${pluginsLockHash}`;
465
- const hashPath = path.join(CodeInjector.SPA_TMP_PATH, 'node_modules', '.adminforth_hash');
466
- try {
467
- const existingHash = yield fs.promises.readFile(hashPath, 'utf-8');
468
- if (existingHash === fullHash) {
469
- process.env.HEAVY_DEBUG && console.log(`🪲Hashes match, skipping npm ci/install, from file: ${existingHash}, actual: ${fullHash}`);
470
- return;
471
- }
472
- else {
473
- process.env.HEAVY_DEBUG && console.log(`🪲 Hashes do not match: from file: ${existingHash} actual: ${fullHash}, proceeding with npm ci/install`);
474
- }
418
+ routerVueContent = routerVueContent.replace('/* IMPORTANT:ADMINFORTH ROUTES */', routes);
419
+ await fs.promises.writeFile(routerVuePath, routerVueContent);
420
+ /* hash checking */
421
+ const spaPackageLockPath = path.join(CodeInjector.SPA_TMP_PATH, 'package-lock.json');
422
+ const spaPackageLock = JSON.parse(await fs.promises.readFile(spaPackageLockPath, 'utf-8'));
423
+ const spaLockHash = hashify(spaPackageLock);
424
+ /* customPackageLock */
425
+ let usersLockHash = '';
426
+ let usersPackages = [];
427
+ if ((_l = this.adminforth.config.customization) === null || _l === void 0 ? void 0 : _l.customComponentsDir) {
428
+ [usersLockHash, usersPackages] = await this.packagesFromNpm(this.adminforth.config.customization.customComponentsDir);
429
+ }
430
+ const pluginPackages = [];
431
+ // for every installed plugin generate packages
432
+ for (const plugin of this.adminforth.activatedPlugins) {
433
+ process.env.HEAVY_DEBUG && console.log('🔧 Checking packages for plugin', plugin.constructor.name, plugin.customFolderPath);
434
+ const [lockHash, packages] = await this.packagesFromNpm(plugin.customFolderPath);
435
+ if (packages.length) {
436
+ pluginPackages.push({
437
+ pluginName: plugin.constructor.name,
438
+ lockHash,
439
+ packages,
440
+ });
475
441
  }
476
- catch (e) {
477
- // ignore
478
- process.env.HEAVY_DEBUG && console.log('🪲Hash file does not exist, proceeding with npm ci/install');
442
+ }
443
+ // form string "pluginName:lockHash::pLugin2Name:lockHash"
444
+ const pluginsLockHash = pluginPackages.map(({ pluginName, lockHash }) => `${pluginName}>${lockHash}`).join('::');
445
+ const iconPackagesNamesHash = hashify(iconPackageNames);
446
+ const fullHash = `spa>${spaLockHash}::icons>${iconPackagesNamesHash}::user/custom>${usersLockHash}::${pluginsLockHash}`;
447
+ const hashPath = path.join(CodeInjector.SPA_TMP_PATH, 'node_modules', '.adminforth_hash');
448
+ try {
449
+ const existingHash = await fs.promises.readFile(hashPath, 'utf-8');
450
+ if (existingHash === fullHash) {
451
+ process.env.HEAVY_DEBUG && console.log(`🪲Hashes match, skipping npm ci/install, from file: ${existingHash}, actual: ${fullHash}`);
452
+ return;
479
453
  }
480
- yield this.runNpmShell({ command: 'ci', cwd: CodeInjector.SPA_TMP_PATH });
481
- const allPacks = [
482
- ...iconPackageNames,
483
- ...usersPackages,
484
- ...pluginPackages.reduce((acc, { packages }) => {
485
- acc.push(...packages);
486
- return acc;
487
- }, []),
488
- ];
489
- const EXCLUDE_PACKS = ['@iconify-prerendered/vue-flowbite'];
490
- const allPacksFiltered = allPacks.filter((pack) => {
491
- return !EXCLUDE_PACKS.some((exclude) => pack.startsWith(exclude));
492
- });
493
- const allPacksUnique = Array.from(new Set(allPacksFiltered));
494
- if (allPacks.length) {
495
- const npmInstallCommand = `install ${allPacksUnique.join(' ')}`;
496
- yield this.runNpmShell({ command: npmInstallCommand, cwd: CodeInjector.SPA_TMP_PATH });
454
+ else {
455
+ process.env.HEAVY_DEBUG && console.log(`🪲 Hashes do not match: from file: ${existingHash} actual: ${fullHash}, proceeding with npm ci/install`);
497
456
  }
498
- yield fs.promises.writeFile(hashPath, fullHash);
457
+ }
458
+ catch (e) {
459
+ // ignore
460
+ process.env.HEAVY_DEBUG && console.log('🪲Hash file does not exist, proceeding with npm ci/install');
461
+ }
462
+ await this.runNpmShell({ command: 'ci', cwd: CodeInjector.SPA_TMP_PATH });
463
+ const allPacks = [
464
+ ...iconPackageNames,
465
+ ...usersPackages,
466
+ ...pluginPackages.reduce((acc, { packages }) => {
467
+ acc.push(...packages);
468
+ return acc;
469
+ }, []),
470
+ ];
471
+ const EXCLUDE_PACKS = ['@iconify-prerendered/vue-flowbite'];
472
+ const allPacksFiltered = allPacks.filter((pack) => {
473
+ return !EXCLUDE_PACKS.some((exclude) => pack.startsWith(exclude));
499
474
  });
475
+ const allPacksUnique = Array.from(new Set(allPacksFiltered));
476
+ if (allPacks.length) {
477
+ const npmInstallCommand = `install ${allPacksUnique.join(' ')}`;
478
+ await this.runNpmShell({ command: npmInstallCommand, cwd: CodeInjector.SPA_TMP_PATH });
479
+ }
480
+ await fs.promises.writeFile(hashPath, fullHash);
500
481
  }
501
- watchForReprepare(_a) {
502
- return __awaiter(this, arguments, void 0, function* ({}) {
503
- const spaPath = path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa');
504
- // get list of all subdirectories in spa recursively
505
- const directories = [];
506
- const collectDirectories = (dir) => __awaiter(this, void 0, void 0, function* () {
507
- const files = yield fs.promises.readdir(dir, { withFileTypes: true });
508
- for (const file of files) {
509
- if (['node_modules', 'dist'].includes(file.name)) {
510
- continue;
511
- }
512
- if (file.isDirectory()) {
513
- directories.push(path.join(dir, file.name));
514
- yield collectDirectories(path.join(dir, file.name));
515
- }
482
+ async watchForReprepare({}) {
483
+ const spaPath = path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'spa');
484
+ // get list of all subdirectories in spa recursively
485
+ const directories = [];
486
+ const collectDirectories = async (dir) => {
487
+ const files = await fs.promises.readdir(dir, { withFileTypes: true });
488
+ for (const file of files) {
489
+ if (['node_modules', 'dist'].includes(file.name)) {
490
+ continue;
491
+ }
492
+ if (file.isDirectory()) {
493
+ directories.push(path.join(dir, file.name));
494
+ await collectDirectories(path.join(dir, file.name));
516
495
  }
517
- });
518
- yield collectDirectories(spaPath);
519
- if (process.env.HEAVY_DEBUG) {
520
- console.log('🪲🔎 Watch for:', directories.join(','));
521
496
  }
522
- const watcher = filewatcher();
523
- directories.forEach((dir) => {
524
- watcher.add(dir);
525
- });
526
- watcher.on('change', (file, x) => __awaiter(this, void 0, void 0, function* () {
527
- console.log(`File ${file} changed ${x}, preparing sources...`);
528
- yield this.prepareSources({ filesUpdated: [file.replace(spaPath + '/', '')] });
529
- }));
530
- watcher.on('fallback', notifyWatcherIssue);
531
- this.allWatchers.push(watcher);
497
+ };
498
+ await collectDirectories(spaPath);
499
+ if (process.env.HEAVY_DEBUG) {
500
+ console.log('🪲🔎 Watch for:', directories.join(','));
501
+ }
502
+ const watcher = filewatcher();
503
+ directories.forEach((dir) => {
504
+ watcher.add(dir);
505
+ });
506
+ watcher.on('change', async (file, x) => {
507
+ console.log(`File ${file} changed ${x}, preparing sources...`);
508
+ await this.prepareSources({ filesUpdated: [file.replace(spaPath + '/', '')] });
532
509
  });
510
+ watcher.on('fallback', notifyWatcherIssue);
511
+ this.allWatchers.push(watcher);
533
512
  }
534
- watchCustomComponentsForCopy(_a) {
535
- return __awaiter(this, arguments, void 0, function* ({ customComponentsDir, destination }) {
536
- if (!customComponentsDir) {
537
- return;
538
- }
539
- // check if folder exists
540
- try {
541
- yield fs.promises.access(customComponentsDir, fs.constants.F_OK);
542
- }
543
- catch (e) {
544
- process.env.HEAVY_DEBUG && console.log(`🪲Custom components dir ${customComponentsDir} does not exist, skipping watching`);
513
+ async watchCustomComponentsForCopy({ customComponentsDir, destination }) {
514
+ if (!customComponentsDir) {
515
+ return;
516
+ }
517
+ // check if folder exists
518
+ try {
519
+ await fs.promises.access(customComponentsDir, fs.constants.F_OK);
520
+ }
521
+ catch (e) {
522
+ process.env.HEAVY_DEBUG && console.log(`🪲Custom components dir ${customComponentsDir} does not exist, skipping watching`);
523
+ return;
524
+ }
525
+ // get all subdirs
526
+ const directories = [];
527
+ const files = [];
528
+ const collectDirectories = async (dir) => {
529
+ if (['node_modules', 'dist'].includes(path.basename(dir))) {
545
530
  return;
546
531
  }
547
- // get all subdirs
548
- const directories = [];
549
- const files = [];
550
- const collectDirectories = (dir) => __awaiter(this, void 0, void 0, function* () {
551
- if (['node_modules', 'dist'].includes(path.basename(dir))) {
552
- return;
553
- }
554
- directories.push(dir);
555
- const filesAndDirs = yield fs.promises.readdir(dir, { withFileTypes: true });
556
- yield Promise.all(filesAndDirs.map((file) => __awaiter(this, void 0, void 0, function* () {
557
- const isDir = fs.lstatSync(path.join(dir, file.name)).isDirectory();
558
- if (isDir) {
559
- yield collectDirectories(path.join(dir, file.name));
560
- }
561
- else {
562
- files.push(path.join(dir, file.name));
563
- }
564
- })));
565
- });
566
- yield collectDirectories(customComponentsDir);
567
- const watcher = filewatcher();
568
- files.forEach((file) => {
569
- process.env.HEAVY_DEBUG && console.log(`🪲🔎 Watch for file ${file}`);
570
- watcher.add(file);
571
- });
572
- if (process.env.HEAVY_DEBUG) {
573
- console.log('🪲🔎 Watch for:', directories.join(','));
574
- }
575
- watcher.on('change', (fileOrDir) => __awaiter(this, void 0, void 0, function* () {
576
- // copy one file
577
- const relativeFilename = fileOrDir.replace(customComponentsDir + '/', '');
578
- if (process.env.HEAVY_DEBUG) {
579
- console.log(`🔎 fileOrDir ${fileOrDir} changed`);
580
- console.log(`🔎 relativeFilename ${relativeFilename}`);
581
- console.log(`🔎 customComponentsDir ${customComponentsDir}`);
582
- console.log(`🔎 destination ${destination}`);
583
- }
584
- const isFile = fs.lstatSync(fileOrDir).isFile();
585
- if (isFile) {
586
- const destPath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'custom', destination, relativeFilename);
587
- process.env.HEAVY_DEBUG && console.log(`🔎 Copying file ${fileOrDir} to ${destPath}`);
588
- yield fsExtra.copy(fileOrDir, destPath);
589
- return;
532
+ directories.push(dir);
533
+ const filesAndDirs = await fs.promises.readdir(dir, { withFileTypes: true });
534
+ await Promise.all(filesAndDirs.map(async (file) => {
535
+ const isDir = fs.lstatSync(path.join(dir, file.name)).isDirectory();
536
+ if (isDir) {
537
+ await collectDirectories(path.join(dir, file.name));
590
538
  }
591
539
  else {
592
- // for now do nothing
540
+ files.push(path.join(dir, file.name));
593
541
  }
594
542
  }));
595
- watcher.on('fallback', notifyWatcherIssue);
596
- this.allWatchers.push(watcher);
543
+ };
544
+ await collectDirectories(customComponentsDir);
545
+ const watcher = filewatcher();
546
+ files.forEach((file) => {
547
+ process.env.HEAVY_DEBUG && console.log(`🪲🔎 Watch for file ${file}`);
548
+ watcher.add(file);
597
549
  });
598
- }
599
- bundleNow(_a) {
600
- return __awaiter(this, arguments, void 0, function* ({ hotReload = false }) {
601
- console.log(`AdminForth bundling ${hotReload ? ' and listening for changes (🔥 Hotreload)' : ' (no hot reload)'}`);
602
- this.adminforth.runningHotReload = hotReload;
603
- yield this.prepareSources({});
604
- if (hotReload) {
605
- yield Promise.all([
606
- this.watchForReprepare({}),
607
- ...Object.entries(this.srcFoldersToSync).map((_b) => __awaiter(this, [_b], void 0, function* ([src, dest]) {
608
- yield this.watchCustomComponentsForCopy({
609
- customComponentsDir: src,
610
- destination: dest,
611
- });
612
- })),
613
- ]);
614
- }
615
- console.log('AdminForth bundling');
616
- const cwd = CodeInjector.SPA_TMP_PATH;
617
- if (!hotReload) {
618
- // probably add option to build with tsh check (plain 'build')
619
- yield this.runNpmShell({ command: 'run build-only', cwd });
550
+ if (process.env.HEAVY_DEBUG) {
551
+ console.log('🪲🔎 Watch for:', directories.join(','));
552
+ }
553
+ watcher.on('change', async (fileOrDir) => {
554
+ // copy one file
555
+ const relativeFilename = fileOrDir.replace(customComponentsDir + '/', '');
556
+ if (process.env.HEAVY_DEBUG) {
557
+ console.log(`🔎 fileOrDir ${fileOrDir} changed`);
558
+ console.log(`🔎 relativeFilename ${relativeFilename}`);
559
+ console.log(`🔎 customComponentsDir ${customComponentsDir}`);
560
+ console.log(`🔎 destination ${destination}`);
561
+ }
562
+ const isFile = fs.lstatSync(fileOrDir).isFile();
563
+ if (isFile) {
564
+ const destPath = path.join(CodeInjector.SPA_TMP_PATH, 'src', 'custom', destination, relativeFilename);
565
+ process.env.HEAVY_DEBUG && console.log(`🔎 Copying file ${fileOrDir} to ${destPath}`);
566
+ await fsExtra.copy(fileOrDir, destPath);
567
+ return;
620
568
  }
621
569
  else {
622
- const command = 'run dev';
623
- console.log(`🪲⚙️ spawn: npm ${command}...`);
624
- const nodeBinary = process.execPath;
625
- const npmPath = path.join(path.dirname(nodeBinary), 'npm');
626
- const env = Object.assign({ VITE_ADMINFORTH_PUBLIC_PATH: this.adminforth.config.baseUrl, FORCE_COLOR: '1' }, process.env);
627
- const devServer = spawn(`${nodeBinary}`, [`${npmPath}`, ...command.split(' ')], {
628
- cwd,
629
- env,
630
- });
631
- devServer.stdout.on('data', (data) => {
632
- console.log(`[AdminForth SPA]:`);
633
- process.stdout.write(data);
634
- });
635
- devServer.stderr.on('data', (data) => {
636
- console.error(`[AdminForth SPA ERR]:`);
637
- process.stdout.write(data);
638
- });
570
+ // for now do nothing
639
571
  }
640
572
  });
573
+ watcher.on('fallback', notifyWatcherIssue);
574
+ this.allWatchers.push(watcher);
575
+ }
576
+ async bundleNow({ hotReload = false }) {
577
+ console.log(`AdminForth bundling ${hotReload ? ' and listening for changes (🔥 Hotreload)' : ' (no hot reload)'}`);
578
+ this.adminforth.runningHotReload = hotReload;
579
+ await this.prepareSources({});
580
+ if (hotReload) {
581
+ await Promise.all([
582
+ this.watchForReprepare({}),
583
+ ...Object.entries(this.srcFoldersToSync).map(async ([src, dest]) => {
584
+ await this.watchCustomComponentsForCopy({
585
+ customComponentsDir: src,
586
+ destination: dest,
587
+ });
588
+ }),
589
+ ]);
590
+ }
591
+ console.log('AdminForth bundling');
592
+ const cwd = CodeInjector.SPA_TMP_PATH;
593
+ if (!hotReload) {
594
+ // probably add option to build with tsh check (plain 'build')
595
+ await this.runNpmShell({ command: 'run build-only', cwd });
596
+ }
597
+ else {
598
+ const command = 'run dev';
599
+ console.log(`🪲⚙️ spawn: npm ${command}...`);
600
+ const nodeBinary = process.execPath;
601
+ const npmPath = path.join(path.dirname(nodeBinary), 'npm');
602
+ const env = Object.assign({ VITE_ADMINFORTH_PUBLIC_PATH: this.adminforth.config.baseUrl, FORCE_COLOR: '1' }, process.env);
603
+ const devServer = spawn(`${nodeBinary}`, [`${npmPath}`, ...command.split(' ')], {
604
+ cwd,
605
+ env,
606
+ });
607
+ devServer.stdout.on('data', (data) => {
608
+ console.log(`[AdminForth SPA]:`);
609
+ process.stdout.write(data);
610
+ });
611
+ devServer.stderr.on('data', (data) => {
612
+ console.error(`[AdminForth SPA ERR]:`);
613
+ process.stdout.write(data);
614
+ });
615
+ }
641
616
  }
642
617
  }
643
618
  CodeInjector.SPA_TMP_PATH = path.join(TMP_DIR, 'adminforth', 'spa_tmp');