Explorar el Código

change how generators and watching is done

Adam Shaw hace 3 años
padre
commit
9aecd6b086

+ 7 - 3
packages/core/scripts/generate-locale-iife.js

@@ -3,10 +3,14 @@ import { fileURLToPath } from 'url'
 import { readFile } from 'fs/promises'
 import handlebars from 'handlebars'
 
-const pkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
-const templatePath = joinPaths(pkgDir, 'src/locales/iife.js.tpl')
+const thisPkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
+const templatePath = joinPaths(thisPkgDir, 'src/locales/iife.js.tpl')
 
-export default async function(entryAlias) {
+export function getWatchPaths(pkgDir) {
+  return [templatePath]
+}
+
+export default async function(pkgDir, entryAlias) {
   const localeCode = basename(entryAlias)
 
   const templateText = await readFile(templatePath, 'utf8')

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

@@ -4,16 +4,19 @@ import { readFile } from 'fs/promises'
 import { globby } from 'globby'
 import { default as handlebars } from 'handlebars'
 
-const pkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
-const templatePath = joinPaths(pkgDir, 'src/locales-all.js.tpl')
-const localesDir = joinPaths(pkgDir, 'src/locales')
+const thisPkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
+const templatePath = joinPaths(thisPkgDir, 'src/locales-all.js.tpl')
+const localesDir = joinPaths(thisPkgDir, 'src/locales')
 
-export const watchPaths = [localesDir]
+export function getWatchPaths() {
+  return [
+    templatePath,
+    localesDir,
+  ]
+}
 
 export default async function() {
   const localeFilenames = await globby('*.ts', { cwd: localesDir })
-
-  // TODO: use basename to remove extension
   const localeCodes = localeFilenames.map((filename) => filename.replace(/\.ts$/, ''))
 
   const templateText = await readFile(templatePath, 'utf8')

+ 10 - 4
tests/scripts/generate-index-iife.js

@@ -4,11 +4,17 @@ import { readFile } from 'fs/promises'
 import handlebars from 'handlebars'
 import { execCapture } from '@fullcalendar/workspace-scripts/utils/exec'
 
-const pkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
-const templatePath = joinPaths(pkgDir, 'src/index.iife.js.tpl')
+const thisPkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
+const templatePath = joinPaths(thisPkgDir, 'src/index.iife.js.tpl')
 
-export default async function main() {
-  const srcDir = resolvePath('./src') // HACK: works when called from other test dirs
+export function getWatchPaths(pkgDir) {
+  const srcDir = joinPaths(pkgDir, 'src')
+
+  return [srcDir]
+}
+
+export default async function(pkgDir) {
+  const srcDir = joinPaths(pkgDir, 'src')
 
   let testPaths = await execCapture(
     'find . -mindepth 2 -type f \\( -name \'*.ts\' -or -name \'*.tsx\' \\) -print0 | ' +