Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jguerinet committed Jul 10, 2017
2 parents 32e6807 + da7cd87 commit b4daeac
Show file tree
Hide file tree
Showing 5 changed files with 755 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ workspace.xml
.name
## We're not committing the test config file
config.txt
node_modules
mobile-string-parser.js.map
mobile-string-parser.js
mobile-string-parser.d.ts
STRING_TRANSLATIONS.json
51 changes: 51 additions & 0 deletions mobile-string-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env ts-node

/**************************************************************************************************
*
* @file ./mobile-string-parser.ts
*
* Note: must be run from node - will not work if used in the browser.
*
*/

/******************************************** IMPORTS *********************************************/
import { spawnSync } from 'child_process';
import { readFileSync, unlinkSync } from 'fs';
import { wasRunAsScript } from 'mad-utils/lib/node';


/******************************************** LOGGING *********************************************/
import { buildFileTag, nodeLogFactory, colors } from 'mad-logs/lib/node';
const log = nodeLogFactory(buildFileTag('mobile-string-parser.ts', colors.bgMagenta.white));


/********************************************* EXPORT *********************************************/
/**
* @export
*
* Get parsed string translations from googledoc. Erases old version, saves new downloaded & parsed
* version as a JSON file, then grabs the file's data, converts it to a JS object & returns it.
*
* TODO try downloading first and save to temp file. Only delete if dwl succeeds. Copy new version
* in temp file to STRING_TRANSLATIONS.json.
*
* @return {Object} Translation strings object, parsed from STRING_TRANSLATIONS.json.
*/
export const getTranslationsFromWeb = (): Object => {
try {
unlinkSync('./STRING_TRANSLATIONS.json');
} catch(e) {
log.verbose(`STRING_TRANSLATIONS.json doesn't yet exist - no need to delete.`);
}

spawnSync('java', ['-jar', 'build/libs/mobile-string-parser-3.0.0.jar'], { env: process.env });

const mobileStrings = require('./STRING_TRANSLATIONS.json');
log.silly('mobileStrings returned from google translations repo:', mobileStrings);

return mobileStrings;
};


/******************* RUN THE EXPORTED FUNCTION IF THE FILE WAS RUN AS A SCRIPT ********************/
if (wasRunAsScript(__filename)) getTranslationsFromWeb();
49 changes: 49 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@ottawamhealth/mobile-string-parser",
"version": "0.0.1",
"description": "Grab online CSV, parse it to produce JSON string file (for translations)",
"main": "mobile-string-parser.js",
"typings": "mobile-string-parser",
"files": [
"./mobile-string-parser.js",
"./mobile-string-parser.d.ts",
"./mobile-string-parser.js.map"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile-ts": "tsc",
"ts-compile": "tsc",
"start": "npm run ts-compile; node ./mobile-string-parser.js",
"prepublish": "npm run ts-compile"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jguerinet/mobile-string-parser.git"
},
"keywords": [
"java",
"jar",
"strings",
"parsing",
"csv"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/jguerinet/mobile-string-parser/issues"
},
"homepage": "https://github.com/jguerinet/mobile-string-parser#readme",
"private": true,
"dependencies": {
"mad-logs": "^8.3.0",
"mad-utils": "^0.5.7"
},
"devDependencies": {
"lodash": "^4.17.4",
"chai": "^3.5.0"
},
"peerDependencies": {
"lodash": "^4.17.4",
"chai": "^3.5.0"
}
}
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": "2.3.0",
"compilerOptions": {
"module": "commonjs",
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"strictNullChecks": false,
"outDir": "./",
"declaration": true,
"target": "ES5",
"skipLibCheck": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"jsx": "preserve",
"pretty": true,
"lib": ["ES2015", "DOM"]
},
"exclude": [
"*.js",
"*.json"
],
"include": [
"./mobile-string-parser.ts",
"./src/*.ts"
]
}

Loading

0 comments on commit b4daeac

Please sign in to comment.