Skip to content

Commit

Permalink
v3 (#23)
Browse files Browse the repository at this point in the history
* chore: change to ECMAScript modules

BREAKING CHANGE: The package won't support CJS anymore.
  • Loading branch information
dziraf committed Apr 18, 2023
1 parent 8c3778c commit 6a15e27
Show file tree
Hide file tree
Showing 30 changed files with 7,843 additions and 10,993 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'plugin:react/recommended',
],
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
Expand Down
40 changes: 3 additions & 37 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
jobs:
test:
name: test
name: Test and Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup
uses: actions/setup-node@v2
with:
node-version: '14.x'
- uses: actions/cache@v1
node-version: '18.x'
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
Expand All @@ -30,40 +30,6 @@ jobs:
run: yarn lint
- name: Build
run: yarn build
- name: Test
run: yarn test

publish:
name: Publish
needs: test
if: |
github.event_name == 'push'
&& (
contains(github.ref, 'refs/heads/next')
|| contains(github.ref, 'refs/heads/main')
|| contains(github.ref, 'refs/heads/next-major')
|| contains(github.ref, 'refs/heads/beta')
)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup
uses: actions/setup-node@v2
with:
node-version: '14.x'
- uses: actions/cache@v1
id: yarn-cache
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node_modules-
- name: Install
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install
- name: Build
run: yarn build
- name: Release
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions example-app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.7'

services:
adminjs-import-export:
container_name: adminjs-import-export
image: mongo
ports:
- "27017:27017"
volumes:
- adminjs-import-export:/data/db

volumes:
adminjs-import-export:
10 changes: 0 additions & 10 deletions example-app/nodemon.json

This file was deleted.

29 changes: 19 additions & 10 deletions example-app/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
{
"name": "adminjs-import-export-example",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"license": "MIT",
"scripts": {
"dev": "nodemon",
"lint": "eslint src --ext ts"
"start": "node dist/example-app/src/server",
"build": "tsc -p './tsconfig.json'"
},
"dependencies": {
"@adminjs/design-system": "^2.0.4",
"@adminjs/express": "^4.0.1",
"adminjs": "^5.5.1",
"express": "^4.17.1",
"@adminjs/express": "^6.0.0-beta.3",
"@adminjs/mongoose": "^4.0.0-beta.4",
"express": "^4.18.2",
"express-formidable": "^1.2.0",
"nodemon": "^2.0.6",
"ts-node": "^9.0.0"
"express-session": "^1.17.3",
"mongoose": "^7.0.3",
"ts-node": "^10.9.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@types/express": "^4.17.8"
"@types/express": "^4.17.17",
"@types/node": "^18.15.11",
"typescript": "^5.0.2"
},
"resolutions": {
"@adminjs/design-system": "^4.0.0-beta-v4.8",
"@adminjs/express": "6.0.0-beta.3",
"@adminjs/mongoose": "4.0.0-beta.4",
"adminjs": "7.0.0-beta-v7.4"
}
}
25 changes: 15 additions & 10 deletions example-app/src/admin/admin.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import mongoose from 'mongoose';
import AdminJSExpress from '@adminjs/express';
import MongooseAdapter from '@adminjs/mongoose';
import AdminJS from 'adminjs';
import * as MongooseAdapter from '@adminjs/mongoose';
import AdminJS, { ComponentLoader } from 'adminjs';
import { Express } from 'express';
import { createUserResource } from './resources/user/user.resource';
import mongoose from 'mongoose';

import { createUserResource } from './resources/user/user.resource.js';

const setupAdmin = async (app: Express): Promise<void> => {
await mongoose.connect('mongodb://localhost:27017/adminjs-import-export', {
useNewUrlParser: true,
useUnifiedTopology: true,
await mongoose.connect('mongodb://localhost:27017/adminjs-import-export');

const componentLoader = new ComponentLoader();

AdminJS.registerAdapter({
Database: MongooseAdapter.Database,
Resource: MongooseAdapter.Resource,
});

AdminJS.registerAdapter(MongooseAdapter);
const adminJs = new AdminJS({
resources: [createUserResource()],
componentLoader,
resources: [createUserResource(componentLoader)],
});

const router = await AdminJSExpress.buildRouter(adminJs);
const router = AdminJSExpress.buildRouter(adminJs);
app.use(adminJs.options.rootPath, router);
};

Expand Down
18 changes: 13 additions & 5 deletions example-app/src/admin/resources/user/user.resource.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { ResourceWithOptions } from 'adminjs';
import { User } from './user.entity';
import importExportFeature from '../../../../../src/index';
import type { ComponentLoader, ResourceWithOptions } from 'adminjs';

export const createUserResource = (): ResourceWithOptions => ({
import importExportFeature from '../../../../../src/index.js';

import { User } from './user.entity.js';

export const createUserResource = (
componentLoader: ComponentLoader
): ResourceWithOptions => ({
resource: User,
options: {
navigation: {
icon: 'User',
name: 'Users',
},
},
features: [importExportFeature()],
features: [
importExportFeature({
componentLoader,
}),
],
});
3 changes: 2 additions & 1 deletion example-app/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import setupAdmin from './admin/admin';

import setupAdmin from './admin/admin.js';

const app = express();
const port = 3000;
Expand Down
15 changes: 9 additions & 6 deletions example-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"compilerOptions": {
"outDir": "./built",
"target": "ES2016",
"module": "CommonJS",
"jsx": "preserve",
"baseUrl": "./",
"outDir": "./dist",
"target": "esnext",
"module": "nodenext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"strictNullChecks": true,
"strictPropertyInitialization": false,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
"emitDecoratorMetadata": true,
"skipLibCheck": true
},
"include": ["./src/**/*", "./spec/**/*"]
"include": ["./src/**/*.ts", "../src/**/*"]
}
Loading

0 comments on commit 6a15e27

Please sign in to comment.