Skip to content

Commit

Permalink
Add extract-messages script
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jan 11, 2018
1 parent 4e2e34c commit 388a33e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/zanata-frontend/src/frontend/package.json
Expand Up @@ -8,6 +8,7 @@
"js": "yarn run check && webpack",
"build": "yarn run check && node scripts/build",
"draft": "yarn run check && node scripts/build --draft",
"extract-messages": "yarn run check && node scripts/extract-messages",
"watch": "yarn run check && node scripts/dev-server",
"watch:editor": "yarn run check && node scripts/dev-server --editor",
"styleguide-server": "yarn run check && styleguidist server",
Expand Down Expand Up @@ -159,6 +160,7 @@
"suitcss-utils-text": "0.4.1",
"svg-sprite": "1.3.6",
"text-diff": "1.0.1",
"typescript-react-intl": "^0.1.7",
"webfontloader": "1.6.24"
}
}
33 changes: 33 additions & 0 deletions server/zanata-frontend/src/frontend/scripts/extract-messages.js
@@ -0,0 +1,33 @@
var fs = require('fs')
var glob = require('glob')
var parse = require('typescript-react-intl').default

function runner (pattern, cb) {
var results = []
pattern = pattern || 'app/**/*.@(js|jsx|ts|tsx)'
glob(pattern, function (err, files) {
if (err) {
throw new Error(err)
}
files.forEach(f => {
var contents = fs.readFileSync(f).toString()
var res = parse(contents)
results = results.concat(res)
})

cb && cb(results)
})
}

runner(null, function (res) {

var messages = {}

res.forEach(r => {
messages[r.id] = {
defaultMessage: r.defaultMessage,
description: r.description
}
})
fs.writeFileSync(`messages/en-us.json`, JSON.stringify(messages, undefined, 2))
})
8 changes: 7 additions & 1 deletion server/zanata-frontend/src/frontend/yarn.lock
Expand Up @@ -8507,7 +8507,13 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.6.2:
typescript-react-intl@^0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/typescript-react-intl/-/typescript-react-intl-0.1.7.tgz#8e8f2242190dbb442d9ac7d2e70e778988abaf2e"
dependencies:
typescript "^2.3.4"

typescript@^2.3.4, typescript@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"

Expand Down

0 comments on commit 388a33e

Please sign in to comment.