Olivier Massot 1 år sedan
förälder
incheckning
a51ae0554c
3 ändrade filer med 31 tillägg och 22 borttagningar
  1. 0 0
      assets/css/global.scss
  2. 14 10
      pages/dev/poc_models_index.vue
  3. 17 12
      prepare/buildIndex.ts

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
assets/css/global.scss


+ 14 - 10
pages/dev/poc_models_index.vue

@@ -10,20 +10,24 @@ Ainsi que les classes liées importées depuis celles ci : Person.ts
 Mais que les autres ne sont pas importés, par ex. : Country.ts ou File.ts
 -->
 <template>
-  <h1>POC Models index</h1>
-  <span>check result in console</span>
+  <div>
+    <h1>POC Models index</h1>
+    <span>check result in console</span>
+  </div>
 </template>
 
 <script setup lang="ts">
-  import {useEntityManager} from '~/composables/data/useEntityManager';
-  import Organization from '~/models/Organization/Organization';
+import { useEntityManager } from '~/composables/data/useEntityManager'
+import Organization from '~/models/Organization/Organization'
 
-  definePageMeta({
-    layout: false,
-  });
+definePageMeta({
+  layout: false,
+})
 
-  const { em } = useEntityManager()
+const { em } = useEntityManager()
 
-  console.log('Classe importée directement : ' + typeof Organization)
-  console.log('Classe importée dynamiquement : ' + await em.getModelFor('accesses'))
+console.log('Classe importée directement : ' + typeof Organization)
+console.log(
+  'Classe importée dynamiquement : ' + (await em.getModelFor('accesses')),
+)
 </script>

+ 17 - 12
prepare/buildIndex.ts

@@ -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'))

Vissa filer visades inte eftersom för många filer har ändrats