adminforth 1.3.54-next.22 → 1.3.54-next.24
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/dist/auth.js +41 -56
- package/dist/auth.js.map +1 -1
- package/dist/dataConnectors/baseConnector.js +107 -128
- package/dist/dataConnectors/baseConnector.js.map +1 -1
- package/dist/dataConnectors/clickhouse.js +125 -148
- package/dist/dataConnectors/clickhouse.js.map +1 -1
- package/dist/dataConnectors/mongo.js +74 -101
- package/dist/dataConnectors/mongo.js.map +1 -1
- package/dist/dataConnectors/postgres.js +117 -142
- package/dist/dataConnectors/postgres.js.map +1 -1
- package/dist/dataConnectors/sqlite.js +106 -129
- package/dist/dataConnectors/sqlite.js.map +1 -1
- package/dist/index.js +196 -217
- package/dist/index.js.map +1 -1
- package/dist/modules/codeInjector.js +470 -495
- package/dist/modules/codeInjector.js.map +1 -1
- package/dist/modules/configValidator.js +13 -22
- package/dist/modules/configValidator.js.map +1 -1
- package/dist/modules/operationalResource.js +49 -70
- package/dist/modules/operationalResource.js.map +1 -1
- package/dist/modules/restApi.js +103 -116
- package/dist/modules/restApi.js.map +1 -1
- package/dist/plugins/audit-log/types.js +2 -0
- package/dist/plugins/audit-log/types.js.map +1 -0
- package/dist/plugins/chat-gpt/types.js +2 -0
- package/dist/plugins/chat-gpt/types.js.map +1 -0
- package/dist/plugins/email-password-reset/types.js +2 -0
- package/dist/plugins/email-password-reset/types.js.map +1 -0
- package/dist/plugins/foreign-inline-list/types.js +2 -0
- package/dist/plugins/foreign-inline-list/types.js.map +1 -0
- package/dist/plugins/import-export/types.js +2 -0
- package/dist/plugins/import-export/types.js.map +1 -0
- package/dist/plugins/rich-editor/custom/async-queue.js +29 -0
- package/dist/plugins/rich-editor/custom/async-queue.js.map +1 -0
- package/dist/plugins/rich-editor/dist/async-queue.js +41 -0
- package/dist/plugins/rich-editor/dist/custom/async-queue.js +29 -0
- package/dist/plugins/rich-editor/dist/custom/async-queue.js.map +1 -0
- package/dist/plugins/rich-editor/types.js +16 -0
- package/dist/plugins/rich-editor/types.js.map +1 -0
- package/dist/plugins/two-factors-auth/types.js +2 -0
- package/dist/plugins/two-factors-auth/types.js.map +1 -0
- package/dist/plugins/upload/types.js +2 -0
- package/dist/plugins/upload/types.js.map +1 -0
- package/dist/servers/express.js +29 -42
- package/dist/servers/express.js.map +1 -1
- package/package.json +4 -1
- package/auth.ts +0 -140
- package/basePlugin.ts +0 -70
- package/dataConnectors/baseConnector.ts +0 -222
- package/dataConnectors/clickhouse.ts +0 -343
- package/dataConnectors/mongo.ts +0 -202
- package/dataConnectors/postgres.ts +0 -310
- package/dataConnectors/sqlite.ts +0 -258
- package/index.ts +0 -428
- package/modules/codeInjector.ts +0 -747
- package/modules/configValidator.ts +0 -588
- package/modules/operationalResource.ts +0 -98
- package/modules/restApi.ts +0 -718
- package/modules/styleGenerator.ts +0 -55
- package/modules/styles.ts +0 -126
- package/modules/utils.ts +0 -472
- package/servers/express.ts +0 -259
- package/spa/.eslintrc.cjs +0 -14
- package/spa/README.md +0 -39
- package/spa/env.d.ts +0 -1
- package/spa/index.html +0 -23
- package/spa/package-lock.json +0 -4659
- package/spa/package.json +0 -52
- package/spa/postcss.config.js +0 -6
- package/spa/public/assets/favicon.png +0 -0
- package/spa/src/App.vue +0 -418
- package/spa/src/assets/base.css +0 -2
- package/spa/src/assets/logo.svg +0 -19
- package/spa/src/components/AcceptModal.vue +0 -45
- package/spa/src/components/Breadcrumbs.vue +0 -41
- package/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
- package/spa/src/components/CustomDatePicker.vue +0 -176
- package/spa/src/components/CustomDateRangePicker.vue +0 -218
- package/spa/src/components/CustomRangePicker.vue +0 -156
- package/spa/src/components/Dropdown.vue +0 -168
- package/spa/src/components/Filters.vue +0 -222
- package/spa/src/components/HelloWorld.vue +0 -17
- package/spa/src/components/MenuLink.vue +0 -27
- package/spa/src/components/ResourceForm.vue +0 -325
- package/spa/src/components/ResourceListTable.vue +0 -466
- package/spa/src/components/SingleSkeletLoader.vue +0 -13
- package/spa/src/components/SkeleteLoader.vue +0 -23
- package/spa/src/components/ThreeDotsMenu.vue +0 -43
- package/spa/src/components/Toast.vue +0 -78
- package/spa/src/components/ValueRenderer.vue +0 -141
- package/spa/src/components/icons/IconCalendar.vue +0 -5
- package/spa/src/components/icons/IconCommunity.vue +0 -7
- package/spa/src/components/icons/IconDocumentation.vue +0 -7
- package/spa/src/components/icons/IconEcosystem.vue +0 -7
- package/spa/src/components/icons/IconSupport.vue +0 -7
- package/spa/src/components/icons/IconTime.vue +0 -5
- package/spa/src/components/icons/IconTooling.vue +0 -19
- package/spa/src/composables/useFrontendApi.ts +0 -26
- package/spa/src/composables/useStores.ts +0 -131
- package/spa/src/index.scss +0 -31
- package/spa/src/main.ts +0 -18
- package/spa/src/renderers/CompactUUID.vue +0 -48
- package/spa/src/renderers/CountryFlag.vue +0 -69
- package/spa/src/router/index.ts +0 -59
- package/spa/src/spa_types/core.ts +0 -53
- package/spa/src/stores/core.ts +0 -148
- package/spa/src/stores/filters.ts +0 -27
- package/spa/src/stores/modal.ts +0 -48
- package/spa/src/stores/toast.ts +0 -31
- package/spa/src/stores/user.ts +0 -72
- package/spa/src/utils.ts +0 -160
- package/spa/src/views/CreateView.vue +0 -167
- package/spa/src/views/EditView.vue +0 -170
- package/spa/src/views/ListView.vue +0 -352
- package/spa/src/views/LoginView.vue +0 -192
- package/spa/src/views/ResourceParent.vue +0 -17
- package/spa/src/views/ShowView.vue +0 -194
- package/spa/tailwind.config.js +0 -17
- package/spa/tsconfig.app.json +0 -14
- package/spa/tsconfig.json +0 -11
- package/spa/tsconfig.node.json +0 -19
- package/spa/vite.config.ts +0 -56
- package/tsconfig.json +0 -112
- package/types/AdminForthConfig.ts +0 -1762
- package/types/FrontendAPI.ts +0 -143
|
@@ -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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
120
|
+
lock = JSON.parse(await fs.promises.readFile(lockPath, 'utf-8'));
|
|
128
121
|
}
|
|
129
122
|
catch (e) {
|
|
130
|
-
|
|
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
|
-
|
|
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(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (item.
|
|
179
|
-
if (
|
|
180
|
-
|
|
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
|
-
|
|
189
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
177
|
+
const componentName = `${getComponentNameFromPath(item.component)}`;
|
|
178
|
+
routerComponents += `import ${componentName} from '${item.component}';\n`;
|
|
198
179
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
277
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
359
|
-
Object.values(
|
|
360
|
-
checkInjections(
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
481
|
-
|
|
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
|
-
|
|
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(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
-
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (
|
|
552
|
-
|
|
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
|
-
|
|
540
|
+
files.push(path.join(dir, file.name));
|
|
593
541
|
}
|
|
594
542
|
}));
|
|
595
|
-
|
|
596
|
-
|
|
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
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
if (
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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
|
-
|
|
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');
|