Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add example of assets versioning #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ coverage
public
.adminbro
.idea
public/*.bundle.*.js
src/assets-manifest.json
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"migration:up": "yarn sequelize db:migrate && yarn mikro-orm migration:up && yarn prisma migrate dev --schema src/sources/prisma/schema.prisma",
"docker:up": "docker-compose -f docker-compose.yaml up -d",
"start:dev": "nodemon --watch src",
"build": "tsc"
"build": "tsc",
"bundle-admin": "ts-node src/scripts/bundle-admin.ts"
},
"mikro-orm": {
"useTsNode": true,
Expand Down
10 changes: 8 additions & 2 deletions src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AdminJS from 'adminjs';
import AdminJS, { AdminJSOptions } from 'adminjs';
import AdminJSMongoose from '@adminjs/mongoose';
import AdminJSSequelize from '@adminjs/sequelize';
import { Database as MikroormDatabse, Resource as MikroormResource } from '@adminjs/mikroorm';
Expand Down Expand Up @@ -27,6 +27,7 @@ import { CreateOwnerResource, CreateSellerResource, CreateCarResource } from '..
import { CreatePostResource, CreatePublisherResource, CreateProfileResource } from '../sources/prisma/resources';
import { SOME_STATS } from './components.bundler';
import { CryptoDatabase } from '../sources/rest/crypto-database';
// import assetsManifest from '../assets-manifest.json';

AdminJS.registerAdapter(AdminJSMongoose);
AdminJS.registerAdapter(AdminJSSequelize);
Expand All @@ -52,9 +53,14 @@ export const menu = {
prisma: { name: 'Prisma Resources', icon: 'Industry' },
};

export const generateAdminJSConfig = () => ({
export const generateAdminJSConfig = (): AdminJSOptions => ({
locale,
rootPath: '/admin',
// Uncomment "assetsCDN" and "assets.coreScripts" to test js assets versioning
// assetsCDN: 'http://localhost:3000/',
// assets: {
// coreScripts: assetsManifest,
// },
branding: {
companyName: 'AdminJS demo page',
theme,
Expand Down
26 changes: 26 additions & 0 deletions src/scripts/bundle-admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable max-len */
/* eslint-disable import/first */
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config({ path: `${__dirname}/../../.env` });

import { bundle } from '@adminjs/bundler';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as components from '../admin/components.bundler';

(async () => {
const files = await bundle({
// Uncomment `designSystemDir` and `adminJsAssetsDir` if you are running
// the command using `adminjs-dev` workspace
// designSystemDir: '../adminjs-design-system',
// adminJsAssetsDir: '../adminjs/lib/frontend/assets/scripts',
customComponentsInitializationFilePath: 'src/admin/components.bundler.ts',
destinationDir: 'public',
versioning: {
manifestPath: 'src/assets-manifest.json',
},
});

// eslint-disable-next-line no-console
console.log(files);
})();
6 changes: 4 additions & 2 deletions src/servers/express.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createAdmin, generateAdminJSConfig } from '../admin';
import path from 'path';
import mongoose from 'mongoose';
import AdminJS from 'adminjs';
import { expressAuthenticatedRouter } from '../admin/router';
import { init } from '../sources/mikroorm/config';
import { connection } from '../sources/typeorm/config';
import AdminJS from 'adminjs';
import { createAdmin, generateAdminJSConfig } from '../admin';

const express = require('express');
const app = express();
Expand All @@ -20,6 +21,7 @@ app.listen(process.env.PORT, async () => {
await init();
await connection;

app.use(express.static(path.join(__dirname, '/../../public')));
await attachAdminJS();

console.log(`AdminJS is under localhost:${process.env.PORT}/admin`);
Expand Down