Explorar el Código

added injecting locale list template, used in locales.md

Co-Authored-By: Kevin van Zonneveld <kevin@transloadit.com>
Artur Paikin hace 6 años
padre
commit
68b7a62330
Se han modificado 1 ficheros con 36 adiciones y 0 borrados
  1. 36 0
      website/inject.js

+ 36 - 0
website/inject.js

@@ -8,6 +8,8 @@ const gzipSize = require('gzip-size')
 const bytes = require('pretty-bytes')
 const browserify = require('browserify')
 const touch = require('touch')
+const glob = require('glob')
+const LocaleCode = require('locale-code')
 
 const webRoot = __dirname
 const uppyRoot = path.join(__dirname, '../packages/uppy')
@@ -174,6 +176,38 @@ async function injectMarkdown () {
   touch(path.join(webRoot, `/src/support.md`))
 }
 
+function injectLocaleList () {
+  const mdTable = [
+    `<!-- WARNING! This file was automatically injected. Please run "${path.basename(__filename)}" to re-generate -->\n\n`,
+    '| Language        | NPM                | CDN                 | Source on GitHub |',
+    '| --------------- | ------------------ | ------------------- | ---------------- |'
+  ]
+  const mdRows = []
+
+  const localePackagePath = path.join(localesRoot, 'src', '*.js')
+  let localePackageVersion = require(path.join(localesRoot, 'package.json')).version
+  // @TODO: remove next line when upload-to-cdn is updated
+  localePackageVersion = '1.0.0'
+
+  glob.sync(localePackagePath).forEach((localePath) => {
+    const localeName = path.basename(localePath, '.js')
+    const localeNameWithDash = localeName.replace('_', '-')
+    const languageName = LocaleCode.getLanguageName(localeNameWithDash)
+    const countryName = LocaleCode.getCountryName(localeNameWithDash)
+    const npmPath = `<code><a href="https://www.npmjs.com/package/@uppy/locales">@uppy/locales</a>/lib/${localeName}</code>`
+    const cdnPath = `[\`${localeName}.min.js\`](https://transloadit.edgly.net/releases/uppy/v${localePackageVersion}/locales/${localeName}.min.js)`
+    const githubSource = `[\`${localeName}.js\`](https://github.com/transloadit/uppy/blob/master/packages/%40uppy/locales/src/${localeName}.js)`
+    const mdTableRow = `| ${languageName}<br/> <small>(${countryName})</small> | ${npmPath} | ${cdnPath} | ✏️ ${githubSource} |`
+    mdRows.push(mdTableRow)
+  })
+
+  const resultingMdTable = mdTable.concat(mdRows.sort()).join('\n')
+
+  let dstpath = path.join(webRoot, 'src', '_template', 'list_of_locale_packs.md')
+  fs.writeFileSync(dstpath, resultingMdTable, 'utf-8')
+  console.info(chalk.green(`✓ injected: `), chalk.grey(dstpath))
+}
+
 async function readConfig () {
   try {
     const buf = await promisify(fs.readFile)(configPath, 'utf8')
@@ -190,6 +224,8 @@ async function inject () {
 
   await injectMarkdown()
 
+  injectLocaleList()
+
   config.uppy_version = version
   config.uppy_version_anchor = version.replace(/[^\d]+/g, '')
   await injectSizes(config)