Ver Fonte

locales-all uses glob

Adam Shaw há 3 anos atrás
pai
commit
ed8eab2530
2 ficheiros alterados com 10 adições e 24 exclusões
  1. 1 0
      packages/core/package.json
  2. 9 24
      packages/core/scripts/generate-locales-all.js

+ 1 - 0
packages/core/package.json

@@ -10,6 +10,7 @@
   },
   "devDependencies": {
     "@fullcalendar/workspace-scripts": "workspace:*",
+    "globby": "^13.1.2",
     "handlebars": "^4.1.2"
   },
   "scripts": {

+ 9 - 24
packages/core/scripts/generate-locales-all.js

@@ -1,35 +1,20 @@
-import { join as joinPaths, dirname } from 'path'
+import { join as joinPaths } from 'path'
 import { fileURLToPath } from 'url'
-import { readFile, readdir } from 'fs/promises'
+import { readFile } from 'fs/promises'
+import { globby } from 'globby'
 import { default as handlebars } from 'handlebars'
 
-const thisDir = dirname(fileURLToPath(import.meta.url))
-const templatePath = joinPaths(thisDir, '../src/locales-all.js.tpl')
-const localesDir = joinPaths(thisDir, '../src/locales')
+const pkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
+const templatePath = joinPaths(pkgDir, 'src/locales-all.js.tpl')
+const localesDir = joinPaths(pkgDir, 'src/locales')
 
 export default async function() {
   const templateText = await readFile(templatePath, 'utf8')
   const template = handlebars.compile(templateText)
-  const localeCodes = (await readdir(localesDir))
-    .filter((filename) => !isFilenameHidden(filename))
-    .map((filename) => removeExtension(filename))
 
-  const code = template({
-    localeCodes,
-  })
+  const localeFilenames = await globby('*.ts', { cwd: localesDir })
+  const localeCodes = localeFilenames.map((filename) => filename.replace(/\.ts$/, ''))
+  const code = template({ localeCodes })
 
   return code
 }
-
-/*
-TODO: more DRY
-*/
-
-function isFilenameHidden(filename) {
-  return Boolean(filename.match(/^\./))
-}
-
-function removeExtension(path) {
-  const match = path.match(/^(.*)\.([^\/]*)$/)
-  return match ? match[1] : path
-}