|
|
@@ -8,24 +8,23 @@
|
|
|
* ...
|
|
|
* }
|
|
|
*/
|
|
|
-import { writeFileSync } from 'fs'
|
|
|
-import { glob } from 'glob'
|
|
|
import fs from 'fs'
|
|
|
+import { glob } from 'glob'
|
|
|
|
|
|
console.log('Build entity index')
|
|
|
|
|
|
-const modules: Array<{ entity: string, path: string }> = []
|
|
|
+const modules: Array<{ entity: string; path: string }> = []
|
|
|
|
|
|
const files = await glob('./models/*/*.ts')
|
|
|
|
|
|
-files.forEach(async (file) => {
|
|
|
+files.forEach((file) => {
|
|
|
const data = fs.readFileSync(file, 'utf8')
|
|
|
const lines = data.split('\n')
|
|
|
let entity = null
|
|
|
|
|
|
- for (let line of lines) {
|
|
|
- let match = line.match(/static entity = ['"]([\w-/]+)['"]/)
|
|
|
- if (match){
|
|
|
+ for (const line of lines) {
|
|
|
+ const match = line.match(/static entity = ['"]([\w-/]+)['"]/)
|
|
|
+ if (match) {
|
|
|
// afficher le groupe capturant
|
|
|
entity = match[1]
|
|
|
break
|
|
|
@@ -35,7 +34,7 @@ files.forEach(async (file) => {
|
|
|
if (entity) {
|
|
|
modules.push({ entity, path: file })
|
|
|
} else {
|
|
|
- console.warn("No match found for entity name in " + file)
|
|
|
+ console.warn('No match found for entity name in ' + file)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -43,17 +42,23 @@ const code = []
|
|
|
code.push('/**')
|
|
|
code.push(' * /!\\ Auto-generated file : do not modify directly /!\\')
|
|
|
code.push(' *')
|
|
|
-code.push(' * > This file is generated by the script prepare/buildIndex.ts when running `nuxt prepare`')
|
|
|
+code.push(
|
|
|
+ ' * > This file is generated by the script prepare/buildIndex.ts when running `nuxt prepare`',
|
|
|
+)
|
|
|
code.push('*/')
|
|
|
code.push("import type ApiResource from '~/models/ApiResource'")
|
|
|
code.push('')
|
|
|
|
|
|
// noinspection JSAnnotator
|
|
|
-code.push('const modelsIndex: Record<string, () => Promise<typeof ApiResource>> = {')
|
|
|
+code.push(
|
|
|
+ 'const modelsIndex: Record<string, () => Promise<typeof ApiResource>> = {',
|
|
|
+)
|
|
|
|
|
|
for (const module of modules) {
|
|
|
code.push(" '" + module.entity + "': async () => {")
|
|
|
- code.push(" const module = await import('~/" + module.path.slice(0, -3) + "')")
|
|
|
+ code.push(
|
|
|
+ " const module = await import('~/" + module.path.slice(0, -3) + "')",
|
|
|
+ )
|
|
|
code.push(' return module.default')
|
|
|
code.push(' },')
|
|
|
}
|
|
|
@@ -62,4 +67,4 @@ code.push('}')
|
|
|
code.push('')
|
|
|
code.push('export default modelsIndex')
|
|
|
|
|
|
-writeFileSync('models/models.ts', code.join('\n'))
|
|
|
+fs.writeFileSync('models/models.ts', code.join('\n'))
|