@appxdigital/appx-core-cli 1.0.8 → 1.0.10
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/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {AdminConfigType} from '@appxdigital/appx-core';
|
|
2
|
+
import {ComponentLoader} from 'adminjs';
|
|
3
3
|
|
|
4
4
|
const componentLoader = new ComponentLoader();
|
|
5
5
|
|
|
6
6
|
export const AdminConfig: AdminConfigType = {
|
|
7
7
|
componentLoader,
|
|
8
|
+
adminRoles: ['ADMIN'],
|
|
8
9
|
resources: [
|
|
9
10
|
{
|
|
10
11
|
name: 'User',
|
package/wizard.js
CHANGED
|
@@ -10,6 +10,7 @@ import { fileURLToPath } from 'url';
|
|
|
10
10
|
import cliProgress from 'cli-progress';
|
|
11
11
|
import { gatherFileUploadSettings, insertFileUploadConfiguration } from './utils/fileUploadConfig.js';
|
|
12
12
|
import packageJson from './package.json' assert { type: 'json' };
|
|
13
|
+
import crypto from 'crypto';
|
|
13
14
|
|
|
14
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
16
|
const __dirname = path.dirname(__filename);
|
|
@@ -147,12 +148,6 @@ async function promptUser() {
|
|
|
147
148
|
message: 'Database Name:',
|
|
148
149
|
default: 'generic'
|
|
149
150
|
},
|
|
150
|
-
{
|
|
151
|
-
type: 'confirm',
|
|
152
|
-
name: 'backoffice',
|
|
153
|
-
message: 'Create backoffice?',
|
|
154
|
-
default: true
|
|
155
|
-
},
|
|
156
151
|
{
|
|
157
152
|
type: 'confirm',
|
|
158
153
|
name: 'showOutput',
|
|
@@ -223,7 +218,7 @@ APP_PORT=3000
|
|
|
223
218
|
USE_TRANSACTION=true
|
|
224
219
|
|
|
225
220
|
#Session secret
|
|
226
|
-
SESSION_SECRET="${
|
|
221
|
+
SESSION_SECRET="${crypto.randomBytes(32).toString('hex')}"
|
|
227
222
|
|
|
228
223
|
#Cookie name for the session token
|
|
229
224
|
SESSION_COOKIE_NAME="APPXCORE"
|
|
@@ -232,8 +227,8 @@ SESSION_COOKIE_NAME="APPXCORE"
|
|
|
232
227
|
SESSION_TTL=86400
|
|
233
228
|
|
|
234
229
|
# JWT
|
|
235
|
-
JWT_SECRET="${
|
|
236
|
-
JWT_REFRESH_SECRET="${
|
|
230
|
+
JWT_SECRET="${crypto.randomBytes(32).toString('hex')}"
|
|
231
|
+
JWT_REFRESH_SECRET="${crypto.randomBytes(32).toString('hex')}"
|
|
237
232
|
`;
|
|
238
233
|
|
|
239
234
|
fs.writeFileSync(`${projectPath}/.env`, envContent);
|
|
@@ -311,6 +306,7 @@ function setupProjectStructure(projectPath, answers) {
|
|
|
311
306
|
incrementProgress(answers?.showOutput, "prismaSetup");
|
|
312
307
|
createPrismaModule(projectPath);
|
|
313
308
|
createPermissionsConfig(projectPath);
|
|
309
|
+
setupAdminJS(projectPath);
|
|
314
310
|
createAdminConfig(projectPath);
|
|
315
311
|
addScriptsToPackageJson(projectPath);
|
|
316
312
|
}
|
|
@@ -346,6 +342,42 @@ function getAppModuleTemplate() {
|
|
|
346
342
|
return fs.readFileSync(appModuleTemplatePath, 'utf8');
|
|
347
343
|
}
|
|
348
344
|
|
|
345
|
+
function setupAdminJS(projectPath) {
|
|
346
|
+
const backoffice = path.join(projectPath, 'src/backoffice');
|
|
347
|
+
fs.ensureDirSync(backoffice);
|
|
348
|
+
|
|
349
|
+
const backofficeComponents = path.join(backoffice, 'components');
|
|
350
|
+
fs.ensureDirSync(backofficeComponents);
|
|
351
|
+
|
|
352
|
+
const dashboardContent = getDashboardTemplate();
|
|
353
|
+
fs.writeFileSync(path.join(backofficeComponents, 'dashboard.tsx'), dashboardContent);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function getComponentLoaderTemplate() {
|
|
357
|
+
const template = path.join(__dirname, 'templates', 'adminjs', 'component-loader.template.js');
|
|
358
|
+
return fs.readFileSync(template, 'utf8');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function getDashboardTemplate() {
|
|
362
|
+
const template = path.join(__dirname, 'templates', 'adminjs', 'dashboard.template.js');
|
|
363
|
+
return fs.readFileSync(template, 'utf8');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function getUtilsTemplate() {
|
|
367
|
+
const template = path.join(__dirname, 'templates', 'adminjs', 'utils.template.js');
|
|
368
|
+
return fs.readFileSync(template, 'utf8');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function getAdminTemplate() {
|
|
372
|
+
const template = path.join(__dirname, 'templates', 'adminjs', 'admin.template.js');
|
|
373
|
+
return fs.readFileSync(template, 'utf8');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function getAdminAppModuleTemplate() {
|
|
377
|
+
const appModuleTemplatePath = path.join(__dirname, 'templates', 'adminjs', 'adminjs-app.module.template.js');
|
|
378
|
+
return fs.readFileSync(appModuleTemplatePath, 'utf8');
|
|
379
|
+
}
|
|
380
|
+
|
|
349
381
|
function createPermissionsConfig(projectPath) {
|
|
350
382
|
const configDir = path.join(projectPath, 'src/config');
|
|
351
383
|
fs.ensureDirSync(configDir);
|
|
@@ -356,7 +388,7 @@ function createPermissionsConfig(projectPath) {
|
|
|
356
388
|
fs.writeFileSync(path.join(configDir, 'permissions.config.ts'), permissionsConfigContent);
|
|
357
389
|
}
|
|
358
390
|
|
|
359
|
-
function createAdminConfig(projectPath) {
|
|
391
|
+
function createAdminConfig (projectPath) {
|
|
360
392
|
const configDir = path.join(projectPath, 'src/config');
|
|
361
393
|
fs.ensureDirSync(configDir);
|
|
362
394
|
|