Skip to content

Commit

Permalink
feat: v6.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mle-moni committed May 7, 2024
1 parent 06d708a commit 2978a2c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 90 deletions.
77 changes: 1 addition & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,4 @@ Adomin is a starting point for creating a custom backoffice for your Adonis appl
- backend files that will be imported on your adonis backend
- a react/vite frontend repository to clone

Adomin is for grown up people that are ready to **OWN** the code that they will download.
If you want a software with easy update, Adomin is **NOT** for you.
Adomin is meant to be used as a base for a quick and solid backoffice with the ability to add infinite customisations (you own the code)

## Install

To install Adomin, you will need to copy the folder `./app/adomin` into your backend code,
to do so, git clone this project and copy the `./app/adomin` into your project

Then :
install xlsx package (needed for excel import)
if you don't need excel export and you don't want to import xlsx, remove the excel export related code

```bash
yarn add xlsx # needed for excel export
```

- edit `package.json` and add `"#adomin/*": "./app/adomin/*.js"` inside the `"imports"` object

- edit `tsconfig.json` and add `"#adomin/*": ["./app/adomin/*.js"]` inside the `"paths"` object

- edit `start/routes.ts` : add this import statement to enable all of Adomin routes

```
import '#adomin/routes/adomin_router'
```

- check the content of `app/adomin/routes/adomin_router.ts` this is all the backend routes of Adomin, it's here that you can change things to restrict route access

- add some config inside `app/adomin/adomin_config.ts`

```ts
const USER_CONFIG = createModelViewConfig(() => User, {
label: 'Adominer',
columns: {
email: { type: 'string', isEmail: true, label: 'Super email' },
password: { type: 'string', isPassword: true, label: 'Strong password' },
},
})

export const ADOMIN_CONFIG: AdominConfig = {
title: 'Adomin',
models: [USER_CONFIG],
}
```

💡 Fields configurated inside the `columns` field will be shown on the admin frontend, additionnaly, the primary key field will be shown
(Adomin uses Lucid model primaryKey field to know which is the primary key)

💡 To show the primary key on the frontend, Adomin applies a default config to your primary key field:

```ts
const PRIMARY_KEY_DEFAULT_CONFIG: AdominNumberFieldConfig = {
type: 'number',
editable: false,
creatable: false,
}
```

You can overwrite this config as you please (but I think you should keep creatable: false!)

- get the frontend

```
git clone https://github.com/galadrimteam/adomin-frontend.git
```

- edit the .env to point to your backend

```
VITE_API_URL=http://localhost:3333
```

- :tada:

![Adomin frontend](./docs/assets/images/frontend.png)
See the documentation [here](https://galadrimteam.github.io/adomin/)
95 changes: 93 additions & 2 deletions configure_adomin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,98 @@ git sparse-checkout set --no-cone app/adomin
git checkout > /dev/null 2> /dev/null
cd ../..
mkdir -p app
cp -r ${tmpDir}/adomin-sparse/app/adomin app/adomin && echo "Adomin files copied into ./app/adomin"
cp -r ${tmpDir}/adomin-sparse/app/adomin app/adomin && echo "Adomin files copied into ./app/adomin"
rm -rf ${tmpDir}`

execSync(COMMAND, { stdio: 'inherit', shell: true })
const alreadyCloned = fs.existsSync('app/adomin')

if (!alreadyCloned) {
execSync(COMMAND, { stdio: 'inherit', shell: true })
} else {
console.log('⏩ Adomin files already exist in ./app/adomin skipping cloning.')
}

const packageJson = fs.readFileSync('package.json', { encoding: 'utf-8' })
let packageLines = packageJson.split('\n')

const importsIndex = packageLines.findIndex((l) => l.includes('"imports":'))

if (importsIndex === -1) {
console.error('❌ Could not find the imports section in the package.json')
process.exit(1)
}

const ADOMIN_IMPORT_LINE = ` "#adomin/*": "./app/adomin/*.js",`

packageLines.splice(importsIndex + 1, 0, ADOMIN_IMPORT_LINE)

const newPackageJson = packageLines.join('\n')

const isPackageConfigured = packageJson.includes(`"#adomin/*":`)

if (!isPackageConfigured) {
fs.writeFileSync('package.json', newPackageJson)
console.log('✅ Modified ./package.json')
} else {
console.log('⏩ package.json already configured')
}

const FULL_ADOMIN_PATH_OPTION = `"paths": {
"#adomin/*": ["./app/adomin/*.js"]
},`
const ADOMIN_PATH_OPTION = ` "#adomin/*": ["./app/adomin/*.js"],`

const tsconfigJson = fs.readFileSync('tsconfig.json', { encoding: 'utf-8' })

const tsconfigLines = tsconfigJson.split('\n')

const pathsIndex = tsconfigLines.findIndex((l) => l.includes('"paths":'))

if (pathsIndex === -1) {
const fullPathIndex = tsconfigLines.findIndex((l) => l.includes(`"compilerOptions":`))

if (fullPathIndex === -1) {
console.error('❌ Could not find the compilerOptions section in the tsconfig.json')
process.exit(1)
}

tsconfigLines.splice(fullPathIndex + 1, 0, FULL_ADOMIN_PATH_OPTION)
} else {
tsconfigLines.splice(pathsIndex + 1, 0, ADOMIN_PATH_OPTION)
}

const newTsconfigJson = tsconfigLines.join('\n')

const isTsconfigConfigured = tsconfigJson.includes(`"#adomin/*":`)

if (!isTsconfigConfigured) {
fs.writeFileSync('tsconfig.json', newTsconfigJson)
console.log('✅ Modified ./tsconfig.json')
} else {
console.log('⏩ tsconfig.json already configured')
}

const routesFile = fs.readFileSync('start/routes.ts', { encoding: 'utf-8' })
const routesLines = routesFile.split('\n')
const IMPORT_LINE = `import '#adomin/routes/adomin_router'`
const isRoutesConfigured = routesFile.includes('#adomin/routes/adomin_router')
const routerIndex = routesLines.findIndex((l) => l.includes('import router from'))

if (routerIndex === -1) {
console.error('❌ Could not find the router import in the routes.ts')
process.exit(1)
}

routesLines.splice(routerIndex, 0, IMPORT_LINE)

if (!isRoutesConfigured) {
fs.writeFileSync('start/routes.ts', routesLines.join('\n'))
console.log('✅ Modified ./start/routes.ts')
} else {
console.log('⏩ routes.ts already configured')
}

console.log('🎉 Adomin is now ready to be used in your project.')
console.log(
'📚 configuration docs: https://galadrimteam.github.io/adomin/docs/backend/configuration/'
)
37 changes: 26 additions & 11 deletions docs/content/docs/backend/installation/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,36 @@ title: 'Installation'

{{< br >}}

To install Adomin, you will need to copy the folder `./app/adomin` into your backend code,
to do so, git clone this project and copy the `./app/adomin` into your project
Adomin needs the following npm packages:

{{< br >}}
- `xlsx` needed for excel export
- `@adonisjs/validator` adomin uses the adonis v5 way of dealing with validation, I plan to use vine later but in the meantime you will need it

```fish
yarn add xlsx @adonisjs/validator
```

💡 If you don't need excel export and you don't want to import xlsx, remove the excel export related code

After running the command, see the [post install instructions](#post-install)

### Automatic install

Then you will have to install a few packages :
Run the following command at the root of your adonis backend folder, it will:

- xlsx
needed for excel import if you don't need excel export and you don't want to import xlsx, remove the excel export related code
- @adonisjs/validator this is the adonis v5 way of dealing with validation, I plan to use vine later but in the meantime you will need it
- copy adomin files into `./app/adomin`
- modify `imports` inside `./package.json`
- modify `paths` inside `./tsconfig.json`
- import `adomin_router` inside `./start/routes.ts`

```fish
yarn add xlsx @adonisjs/validator
npx @galadrim/adomin@latest
```

{{< br >}}
### Manual install

To install Adomin, you will need to copy the folder `./app/adomin` into your backend code,
to do so, git clone this project and copy the `./app/adomin` into your project

Adomin use imports starting with `#adomin` so you will have to configure this:

Expand Down Expand Up @@ -52,11 +66,12 @@ inside the `"paths"` object
import '#adomin/routes/adomin_router'
```

## Post install

⚠️ You should check the content of `app/adomin/routes/adomin_router.ts` this is where all the backend routes of Adomin are defined.
By default only the `middleware.auth()` is used.
I recommend that you can change this to restrict route access to only admins of your app.

{{< br >}}

Adomin is now installed and ready.

To add some configuration, [go this way](/adomin/docs/backend/configuration)
5 changes: 5 additions & 0 deletions docs/content/docs/frontend/routing/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ title: 'Routing'

{{< br >}}

You might have some questions:

- how does the frontend routing work ?
- how to add custom routes ?

It all begins with the **react-router-dom** router, you can find it [here](https://github.com/galadrimteam/adomin-frontend/blob/main/src/router.tsx)

Inside this file is all the routing
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galadrim/adomin",
"version": "6.1.4",
"version": "6.1.5",
"type": "module",
"license": "UNLICENSED",
"scripts": {
Expand Down

0 comments on commit 2978a2c

Please sign in to comment.