From c02abfafed49e000dfebee72d25966b8ff754341 Mon Sep 17 00:00:00 2001 From: "bigopon.777@gmail.com" Date: Fri, 9 Nov 2018 21:57:22 +1100 Subject: [PATCH 1/5] refactor(all): move build to rollup, adjust configure fn --- .gitignore | 1 + build/args.ts | 29 ++ build/build.ts | 162 ++++++++++ build/changelog.ts | 20 ++ build/interfaces.ts | 5 + build/shared.ts | 99 ++++++ build/tsconfig.json | 14 + build/types.d.ts | 4 + package-lock.json | 418 +++++++++++++++++++++++--- package.json | 18 +- src/aurelia-i18n.ts | 66 ++-- src/df/df-binding-behavior.ts | 3 +- src/df/df-value-converter.ts | 2 + src/i18n.ts | 16 +- src/nf/nf-binding-behavior.ts | 3 +- src/nf/nf-value-converter.ts | 3 + src/rt/rt-binding-behavior.ts | 3 +- src/rt/rt-value-converter.ts | 3 + src/t/t-binding-behavior.ts | 5 +- src/t/t-value-converter.ts | 2 + test/unit/aurelia.integration.spec.ts | 15 +- test/unit/staging-helpers.ts | 2 +- tsconfig.json | 9 +- 23 files changed, 789 insertions(+), 113 deletions(-) create mode 100644 build/args.ts create mode 100644 build/build.ts create mode 100644 build/changelog.ts create mode 100644 build/interfaces.ts create mode 100644 build/shared.ts create mode 100644 build/tsconfig.json create mode 100644 build/types.d.ts diff --git a/.gitignore b/.gitignore index 164024fa..dd0a402d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ jspm_packages bower_components .idea .DS_STORE +.rollupcache build/reports .vscode/ test/coverage-jest diff --git a/build/args.ts b/build/args.ts new file mode 100644 index 00000000..b95cff04 --- /dev/null +++ b/build/args.ts @@ -0,0 +1,29 @@ +import yargs from 'yargs'; +import { IBuildTargetFormat } from './shared'; + +export interface IArguments { + target: string; + format: IBuildTargetFormat[]; + dev: boolean; +} + +export const args: IArguments = yargs + .options( + 'target', + { + alias: 't', + // tslint:disable-next-line:max-line-length + description: 'target module dir to copy build results into (eg. "--target ../other-module" to copy build results into "../other-module/node_modules/this-module/dist/…" whenever they change)' + } + ) + .options('format', { + alias: 'f', + array: true, + description: 'format to compile to (eg. "es2015", "commonjs", …). Can be set muliple times to compile to multiple formats. Default is all formats.' + }) + .options('dev', { + alias: 'd', + boolean: true, + description: 'Enable dev move to watch for change and copy dist over target folder' + }) + .argv as any; diff --git a/build/build.ts b/build/build.ts new file mode 100644 index 00000000..0e9cdce7 --- /dev/null +++ b/build/build.ts @@ -0,0 +1,162 @@ +import rollup from 'rollup'; +import { build, IBuildTargetFormat, watchAndReBuild, copy } from './shared'; +import { args } from './args'; +import packageJson from '../package.json'; +import { IRollupWatchOptions } from './interfaces'; +import * as path from 'path'; +import ChildProcess from 'child_process'; + +const BASE_DIR = process.cwd(); +const DIST_DIR = path.join(BASE_DIR, 'dist'); +const NODE_MODULES = 'node_modules'; +const LIB_NAME = 'aurelia-i18n'; +const DIST_FILE_NAME = `${LIB_NAME}.js`; +const TYPE_DIST_FILE_NAME = `${LIB_NAME}.d.ts`; +const ENTRY_PATH = `src/${LIB_NAME}.ts`; +const EXTERNAL_LIBS = [ + 'aurelia-framework', + 'i18next', + ...Object + .keys({ ...packageJson.dependencies, ...packageJson.devDependencies }) + .filter(dev => /^(?:aurelia)/.test(dev) && dev !== LIB_NAME) +]; +const configs: Record = { + es2017: { + input: ENTRY_PATH, + outputs: [ + { file: `dist/es2017/${DIST_FILE_NAME}`, format: 'esm' } + ] + }, + es2015: { + input: ENTRY_PATH, + outputs: [ + { file: `dist/es2015/${DIST_FILE_NAME}`, format: 'esm' } + ] + }, + es5: { + input: ENTRY_PATH, + outputs: [ + { file: `dist/commonjs/${DIST_FILE_NAME}`, format: 'cjs' }, + { file: `dist/amd/${DIST_FILE_NAME}`, format: 'amd', amd: { id: LIB_NAME } }, + { file: `dist/native-modules/${DIST_FILE_NAME}`, format: 'esm' }, + { file: `dist/system/${DIST_FILE_NAME}`, format: 'system' } + ] + }, + amd: { + input: ENTRY_PATH, + outputs: [ + { file: `dist/amd/${DIST_FILE_NAME}`, format: 'amd', amd: { id: LIB_NAME } } + ], + tsConfig: { + target: 'es5' + } + }, + system: { + input: ENTRY_PATH, + outputs: [ + { file: `dist/system/${DIST_FILE_NAME}`, format: 'system' } + ], + tsConfig: { + target: 'es5' + } + }, + commonjs: { + input: ENTRY_PATH, + outputs: [ + { file: `dist/commonjs/${DIST_FILE_NAME}`, format: 'cjs' } + ], + tsConfig: { + target: 'es5' + } + }, + 'native-modules': { + input: ENTRY_PATH, + outputs: [ + { file: `dist/native-modules/${DIST_FILE_NAME}`, format: 'esm' } + ], + tsConfig: { + target: 'es5' + } + } +}; + + +if (args.dev) { + // watch mode + let generateDtsTO: any; + const targetFormats: IBuildTargetFormat[] = args.format || ['commonjs']; + const options = targetFormats.reduce((formats, targetFormat) => { + const { outputs, tsConfig } = configs[targetFormat]; + formats[targetFormat] = { + input: ENTRY_PATH, + external: EXTERNAL_LIBS, + output: outputs, + tsConfig + }; + return formats; + }, {} as Record); + console.log('=============\nBuilding Started\n============='); + watchAndReBuild( + options, + () => { + console.log('=============\nFinished building\n============='); + clearTimeout(generateDtsTO); + generateDtsTO = setTimeout(() => { + generateDts().then(() => { + if (args.target) { + copyToTargetProject(targetFormats, args.target); + } + }); + }, 1000); + } + ); +} else { + // Single build + const targetFormats: IBuildTargetFormat[] = args.format || ['es5', 'es2015', 'es2017']; + Promise + .all(targetFormats.map(target => { + const { outputs, tsConfig, ...options } = configs[target]; + return build(target, { ...options, external: EXTERNAL_LIBS }, outputs as rollup.OutputOptionsFile[]); + })) + .then(() => generateDts()) + .then(() => { + if (args.target) { + copyToTargetProject(targetFormats, args.target); + } + }) + .catch(ex => { + console.log(ex); + }); +} + +async function generateDts(): Promise { + console.log('\n==============\nGenerating dts bundle...\n=============='); + return new Promise(resolve => { + ChildProcess.exec(`npm run build:dts`, (err, stdout, stderr) => { + if (err || stderr) { + console.log('Generating dts error:'); + console.log(stderr); + } else { + console.log('Generated dts bundle successfully'); + console.log(stdout); + } + resolve(); + }); + }); +} + +function copyToTargetProject(targetFormats: string[], targetProject: string) { + console.log('=============\nCopying to target\n============='); + targetFormats.forEach((targetFormat) => { + copy( + path.join(DIST_DIR, targetFormat, DIST_FILE_NAME), + path.join(BASE_DIR, targetProject, NODE_MODULES, LIB_NAME, 'dist', targetFormat, DIST_FILE_NAME) + ); + }); + copy( + path.join(DIST_DIR, TYPE_DIST_FILE_NAME), + path.join(BASE_DIR, targetProject, NODE_MODULES, LIB_NAME, 'dist', TYPE_DIST_FILE_NAME) + ); + console.log('=============\nCopied to target\n============='); +} + diff --git a/build/changelog.ts b/build/changelog.ts new file mode 100644 index 00000000..198dc871 --- /dev/null +++ b/build/changelog.ts @@ -0,0 +1,20 @@ +/// +import fs from 'fs'; +import path from 'path'; +import conventionalChangelog from 'conventional-changelog'; + +const BASE_DIR = process.cwd(); +const DOC_DIR = 'doc'; +const DOC_NAME = 'CHANGELOG.md'; +const DEST_PATH = path.resolve(BASE_DIR, DOC_DIR, DOC_NAME); + +let changelogChunk = ''; +const changelogStream = conventionalChangelog({ preset: 'angular' }) + .on('data', (chunk: any) => changelogChunk += chunk.toString('utf8')) + .on('end', () => { + changelogStream.removeAllListeners(); + const data = fs.readFileSync(DEST_PATH, 'utf-8'); + const fd = fs.openSync(DEST_PATH, 'w+'); + fs.writeSync(fd, Buffer.from(changelogChunk, 'utf8'), 0, changelogChunk.length, 0); + fs.writeSync(fd, Buffer.from(data, 'utf8'), 0, data.length, changelogChunk.length); + }); diff --git a/build/interfaces.ts b/build/interfaces.ts new file mode 100644 index 00000000..31729825 --- /dev/null +++ b/build/interfaces.ts @@ -0,0 +1,5 @@ +import * as rollup from 'rollup'; + +export interface IRollupWatchOptions extends rollup.RollupWatchOptions { + tsConfig?: { target: string }; +} diff --git a/build/shared.ts b/build/shared.ts new file mode 100644 index 00000000..97e6edeb --- /dev/null +++ b/build/shared.ts @@ -0,0 +1,99 @@ +import * as rollup from 'rollup'; +import typescript from 'rollup-plugin-typescript2'; +import rimraf from 'rimraf'; +import { IRollupWatchOptions } from './interfaces'; +import * as fs from 'fs'; + +const CACHE_DIR = '.rollupcache'; +export type IBuildTargetFormat = 'es5' | 'es2015' | 'es2017' | 'amd' | 'system' | 'commonjs' | 'native-modules'; + +export async function build( + target: IBuildTargetFormat, + options: rollup.RollupFileOptions, + outputs: rollup.OutputOptionsFile[] +): Promise { + return rollup + .rollup({ + ...options, + plugins: [ + typescript({ + tsconfigOverride: { + compilerOptions: { + target: target + } + }, + cacheRoot: CACHE_DIR + }) as rollup.Plugin, + ...(options.plugins || []) + ] + }) + .then(bundle => Promise.all(outputs.map(output => bundle.write(output)))) + .then(() => { + console.log(`Built [${target}] successfully.`); + }); +} + +export async function watchAndReBuild( + options: Record, + onBundleChanged: (e: any) => any +) { + const watcher = rollup + .watch(Object.keys(options).map(target => { + const { plugins = [], tsConfig, ...opts } = options[target]; + return { + ...opts, + plugins: [ + typescript({ + tsconfigOverride: { + compilerOptions: { + target: tsConfig ? tsConfig.target : target + } + }, + cacheRoot: CACHE_DIR + }) as rollup.Plugin, + ...plugins + ] + }; + })); + + watcher.on('event', (e) => { + if (e.code === 'ERROR') { + console.log('Error:', e); + return; + } + if (e.code === 'FATAL') { + console.log('==============='); + console.error('FATAL:', e); + console.log('==============='); + // rollup will exit + return; + } + if (e.code === 'END') { + onBundleChanged(e); + return; + } + }); +} + +export async function clean(folder: string): Promise { + console.log(`\n==============\nCleaning ${folder} folder...\n==============`); + return new Promise(resolve => { + rimraf(folder, (error) => { + if (error) { + throw error; + } + resolve(); + }); + }); +} + + +export async function copy(basePath: string, targetPath: string) { + try { + fs.createReadStream(basePath) + .pipe(fs.createWriteStream(targetPath)); + } catch (ex) { + console.log(`Error trying to copy file from "${basePath}" to "${targetPath}"`); + console.log(ex); + } +} diff --git a/build/tsconfig.json b/build/tsconfig.json new file mode 100644 index 00000000..24fb382a --- /dev/null +++ b/build/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": false, + "module": "commonjs", + "target": "es2017", + "noEmit": true, + "esModuleInterop": true, + "resolveJsonModule": true + }, + "include": [ + "./**/*.ts" + ] +} \ No newline at end of file diff --git a/build/types.d.ts b/build/types.d.ts new file mode 100644 index 00000000..14e14873 --- /dev/null +++ b/build/types.d.ts @@ -0,0 +1,4 @@ +declare module 'conventional-changelog' { + import { EventEmitter } from 'events'; + export default function (config: { preset: string }): EventEmitter; +} diff --git a/package-lock.json b/package-lock.json index 900826e2..ccea1903 100644 --- a/package-lock.json +++ b/package-lock.json @@ -138,6 +138,12 @@ "integrity": "sha1-oeUUrfvZLwOiJLpU1pMRHb8fN1Q=", "dev": true }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/events": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", @@ -218,6 +224,16 @@ "integrity": "sha512-zbteaWZ2mdduacm0byELwtRyhYE40aK+pAanQk415gr1eRuu67x7QGOLmn8jz5zI8LDK7d0WI/oT6r5Trz4rzQ==", "dev": true }, + "@types/rimraf": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/rimraf/-/rimraf-2.0.2.tgz", + "integrity": "sha512-Hm/bnWq0TCy7jmjeN5bKYij9vw5GrDFWME4IuxV08278NtU/VdGbzsBohcCUJ7+QMqmUq5hpRKB39HeQWJjztQ==", + "dev": true, + "requires": { + "@types/glob": "*", + "@types/node": "*" + } + }, "@types/shelljs": { "version": "0.7.8", "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.7.8.tgz", @@ -228,6 +244,12 @@ "@types/node": "*" } }, + "@types/yargs": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-12.0.1.tgz", + "integrity": "sha512-UVjo2oH79aRNcsDlFlnQ/iJ67Jd7j6uSg7jUJP/RZ/nUjAh5ElmnwlD5K/6eGgETJUgCHkiWn91B8JjXQ6ubAw==", + "dev": true + }, "JSONStream": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.4.tgz", @@ -963,9 +985,9 @@ } }, "aurelia-templating": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/aurelia-templating/-/aurelia-templating-1.8.2.tgz", - "integrity": "sha512-5suUaJzEhxfJ8yVhOysWJHRwZW54ZaNumAIGqu6Jtnx/5h/08s9aZw1Ev1PMS3lYyq/w4KucdXbG8NeXnJBUNA==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/aurelia-templating/-/aurelia-templating-1.9.0.tgz", + "integrity": "sha512-BJfAyHSBsSX6dUlfDEc2ZV7y2KTZF5pMsoF7m9xnv4oVQ8XCwbefD2QSbWr7CIRdG4u+IUMq0sbrnMal+3OStg==", "requires": { "aurelia-binding": "^2.0.0", "aurelia-dependency-injection": "^1.0.0", @@ -1212,7 +1234,7 @@ }, "babel-plugin-syntax-object-rest-spread": { "version": "6.13.0", - "resolved": "http://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=", "dev": true }, @@ -1548,11 +1570,10 @@ } }, "camelcase": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", - "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", - "dev": true, - "optional": true + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", + "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", + "dev": true }, "camelcase-keys": { "version": "4.2.0", @@ -1704,24 +1725,14 @@ } }, "cliui": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", - "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", + "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", "dev": true, - "optional": true, "requires": { - "center-align": "^0.1.1", - "right-align": "^0.1.1", - "wordwrap": "0.0.2" - }, - "dependencies": { - "wordwrap": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", - "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", - "dev": true, - "optional": true - } + "string-width": "^2.1.1", + "strip-ansi": "^4.0.0", + "wrap-ansi": "^2.0.0" } }, "co": { @@ -2436,6 +2447,38 @@ "is-obj": "^1.0.0" } }, + "dts-bundle-generator": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/dts-bundle-generator/-/dts-bundle-generator-1.6.1.tgz", + "integrity": "sha512-PXNbaDgYvJSCbAOKHqDxml0uojfRvrVHkKc7v/lcxe8vuGxvkZsEcijQp4KHuEvtLt1whVddhZmTrGqXCW1p7w==", + "dev": true, + "requires": { + "typescript": ">=2.6.1", + "yargs": "~11.0.0" + }, + "dependencies": { + "yargs": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-11.0.0.tgz", + "integrity": "sha512-Rjp+lMYQOWtgqojx1dEWorjCofi1YN7AoFvYV7b1gx/7dAAeuI4kN5SZiEvr0ZmsZTOpDRcCqrpI10L31tFkBw==", + "dev": true, + "requires": { + "cliui": "^4.0.0", + "decamelize": "^1.1.1", + "find-up": "^2.1.0", + "get-caller-file": "^1.0.1", + "os-locale": "^2.0.0", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^2.0.0", + "which-module": "^2.0.0", + "y18n": "^3.2.1", + "yargs-parser": "^9.0.2" + } + } + } + }, "duplexer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", @@ -2533,6 +2576,12 @@ "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", "dev": true }, + "estree-walker": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.5.2.tgz", + "integrity": "sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig==", + "dev": true + }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", @@ -3313,7 +3362,7 @@ "integrity": "sha512-E2s1b4GVbt8PyG+iaRN6ks8N0Oy2LOJz7SIMUwWWWx7Mr5Z08hKkfpkKQbOtOGqzkFpckDJHjjZ8qfigN2W86A==", "dev": true, "requires": { - "icu4c-data": "^0.59.2" + "icu4c-data": "^0.60.2" } }, "function-bind": { @@ -5122,6 +5171,12 @@ "yallist": "^2.1.2" } }, + "make-error": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", + "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", + "dev": true + }, "makeerror": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz", @@ -5131,6 +5186,15 @@ "tmpl": "1.0.x" } }, + "map-age-cleaner": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.2.tgz", + "integrity": "sha512-UN1dNocxQq44IhJyMI4TU8phc2m9BddacHRPRjKGLYaF0jqd3xLz0jS0skpAU9WgYyoR4gHtUpzytNBS385FWQ==", + "dev": true, + "requires": { + "p-defer": "^1.0.0" + } + }, "map-cache": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", @@ -5324,7 +5388,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { @@ -5333,7 +5397,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true } @@ -5669,12 +5733,24 @@ "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, + "p-defer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", + "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", + "dev": true + }, "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", "dev": true }, + "p-is-promise": { + "version": "1.1.0", + "resolved": "http://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", + "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=", + "dev": true + }, "p-limit": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", @@ -6279,6 +6355,60 @@ "glob": "^7.0.5" } }, + "rollup": { + "version": "0.67.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.67.0.tgz", + "integrity": "sha512-p34buXxArhwv9ieTdHvdhdo65Cbig68s/Z8llbZuiX5e+3zCqnBF02Ck9IH0tECrmvvrJVMws32Ry84hTnS1Tw==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "@types/node": "*" + } + }, + "rollup-plugin-typescript2": { + "version": "0.17.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.17.2.tgz", + "integrity": "sha512-QmrZElI+p4sytmv1S7uvtUbL4XADWWmM/dIuc3agGZTE+fO2X1KoRo8EbeR1x0ZO4I9KwPubGfmw/1rHeUR+Dg==", + "dev": true, + "requires": { + "fs-extra": "7.0.0", + "resolve": "1.8.1", + "rollup-pluginutils": "2.3.3", + "tslib": "1.9.3" + }, + "dependencies": { + "fs-extra": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.0.tgz", + "integrity": "sha512-EglNDLRpmaTWiD/qraZn6HREAEAHJcJOmxNEYwq6xeMKnVMAy3GUcFB+wXt2C6k4CNvB/mP1y/U3dzvKKj5OtQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "resolve": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", + "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", + "dev": true, + "requires": { + "path-parse": "^1.0.5" + } + } + } + }, + "rollup-pluginutils": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.3.3.tgz", + "integrity": "sha512-2XZwja7b6P5q4RZ5FhyX1+f46xi1Z3qBKigLRZ6VTZjwbN0K1IFGMlwm06Uu0Emcre2Z63l77nq/pzn+KxIEoA==", + "dev": true, + "requires": { + "estree-walker": "^0.5.2", + "micromatch": "^2.3.11" + } + }, "rsvp": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-3.6.2.tgz", @@ -7307,6 +7437,30 @@ } } }, + "ts-node": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", + "integrity": "sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==", + "dev": true, + "requires": { + "arrify": "^1.0.0", + "buffer-from": "^1.1.0", + "diff": "^3.1.0", + "make-error": "^1.1.1", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "source-map-support": "^0.5.6", + "yn": "^2.0.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", @@ -7422,7 +7576,7 @@ }, "typescript": { "version": "2.7.2", - "resolved": "http://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz", "integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==", "dev": true } @@ -7452,12 +7606,51 @@ "yargs": "~3.10.0" }, "dependencies": { + "camelcase": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", + "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", + "dev": true, + "optional": true + }, + "cliui": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", + "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", + "dev": true, + "optional": true, + "requires": { + "center-align": "^0.1.1", + "right-align": "^0.1.1", + "wordwrap": "0.0.2" + } + }, "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", "dev": true, "optional": true + }, + "wordwrap": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", + "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", + "dev": true, + "optional": true + }, + "yargs": { + "version": "3.10.0", + "resolved": "http://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", + "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", + "dev": true, + "optional": true, + "requires": { + "camelcase": "^1.0.2", + "cliui": "^2.1.0", + "decamelize": "^1.0.0", + "window-size": "0.1.0" + } } } }, @@ -7767,6 +7960,12 @@ "integrity": "sha1-TYuPHszTQZqjYgYb7O9RXh5VljU=", "dev": true }, + "xregexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.0.0.tgz", + "integrity": "sha512-PHyM+sQouu7xspQQwELlGwwd05mXUFqwFYfqPO0cC7x4fxyHnnuetmQr6CjJiafIDoH4MogHb9dOoJzR/Y4rFg==", + "dev": true + }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", @@ -7786,16 +7985,151 @@ "dev": true }, "yargs": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", - "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", - "dev": true, - "optional": true, - "requires": { - "camelcase": "^1.0.2", - "cliui": "^2.1.0", - "decamelize": "^1.0.0", - "window-size": "0.1.0" + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.2.tgz", + "integrity": "sha512-e7SkEx6N6SIZ5c5H22RTZae61qtn3PYUE8JYbBFlK9sYmh3DMQ6E5ygtaG/2BW0JZi4WGgTR2IV5ChqlqrDGVQ==", + "dev": true, + "requires": { + "cliui": "^4.0.0", + "decamelize": "^2.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^1.0.1", + "os-locale": "^3.0.0", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^2.0.0", + "which-module": "^2.0.0", + "y18n": "^3.2.1 || ^4.0.0", + "yargs-parser": "^10.1.0" + }, + "dependencies": { + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "dev": true, + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "decamelize": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-2.0.0.tgz", + "integrity": "sha512-Ikpp5scV3MSYxY39ymh45ZLEecsTdv/Xj2CaQfI8RLMuwi7XvjX9H/fhraiSuU+C5w5NTDu4ZU72xNiZnurBPg==", + "dev": true, + "requires": { + "xregexp": "4.0.0" + } + }, + "execa": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.10.0.tgz", + "integrity": "sha512-7XOMnz8Ynx1gGo/3hyV9loYNPWM94jG3+3T3Y8tsfSstFmETmENCMU/A/zj8Lyaj1lkgEepKepvd6240tBRvlw==", + "dev": true, + "requires": { + "cross-spawn": "^6.0.0", + "get-stream": "^3.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + } + }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, + "requires": { + "locate-path": "^3.0.0" + } + }, + "invert-kv": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", + "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", + "dev": true + }, + "lcid": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", + "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", + "dev": true, + "requires": { + "invert-kv": "^2.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "mem": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.0.0.tgz", + "integrity": "sha512-WQxG/5xYc3tMbYLXoXPm81ET2WDULiU5FxbuIoNbJqLOOI8zehXFdZuiUEgfdrU2mVB1pxBZUGlYORSrpuJreA==", + "dev": true, + "requires": { + "map-age-cleaner": "^0.1.1", + "mimic-fn": "^1.0.0", + "p-is-promise": "^1.1.0" + } + }, + "os-locale": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.0.1.tgz", + "integrity": "sha512-7g5e7dmXPtzcP4bgsZ8ixDVqA7oWYuEz4lOSujeWyliPai4gfVDiFIcwBg3aGCPnmSGfzOKTK3ccPn0CKv3DBw==", + "dev": true, + "requires": { + "execa": "^0.10.0", + "lcid": "^2.0.0", + "mem": "^4.0.0" + } + }, + "p-limit": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.0.0.tgz", + "integrity": "sha512-fl5s52lI5ahKCernzzIyAP0QAZbGIovtVHGwpcu1Jr/EpzLVDI2myISHwGqK7m8uQFugVWSrbxH7XnhGtvEc+A==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", + "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", + "dev": true + }, + "yargs-parser": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz", + "integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==", + "dev": true, + "requires": { + "camelcase": "^4.1.0" + } + } } }, "yargs-parser": { @@ -7814,6 +8148,12 @@ "dev": true } } + }, + "yn": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", + "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "dev": true } } } diff --git a/package.json b/package.json index 6a3615e5..ff9e0357 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,9 @@ "test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest", "test-ci": "cross-env NODE_ICU_DATA=node_modules/full-icu jest && cat ./test/coverage-jest/lcov.info | ./node_modules/coveralls/bin/coveralls.js", "test-watch": "concurrently \"tsc --watch\" \"jest --watch\"", - "build:amd": "cross-env tsc --p tsconfig-build.json --outDir dist/amd --module amd", - "build:commonjs": "cross-env tsc --p tsconfig-build.json --outDir dist/commonjs --module commonjs", - "build:es2015": "cross-env tsc --p tsconfig-build.json --outDir dist/es2015 --module es2015", - "build:es2017": "cross-env tsc --p tsconfig-build.json --outDir dist/es2017 --module es2015 --target es2017", - "build:native-modules": "cross-env tsc --p tsconfig-build.json --outDir dist/native-modules --module es2015", - "build:system": "cross-env tsc --p tsconfig-build.json --outDir dist/system --module system", "prebuild": "cross-env rimraf dist", - "build": "concurrently \"npm run build:amd\" \"npm run build:commonjs\" \"npm run build:es2015\" \"npm run build:es2017\" \"npm run build:native-modules\" \"npm run build:system\"", + "build": "cross-env TS_NODE_PROJECT=build/tsconfig.json ts-node build/build.ts", + "build:dts": "dts-bundle-generator -o dist/aurelia-i18n.d.ts src/aurelia-i18n.ts --external-types --no-check", "precommit": "npm run lint", "predoc": "cross-env rimraf doc/api.json && rimraf dist/doc-temp && tsc --p tsconfig-build.json --module amd --outFile dist/doc-temp/aurelia-store.js && node doc/shape-defs && copyfiles tsconfig.json dist/doc-temp", "doc": "cross-env typedoc --json doc/api.json --excludeExternals --includeDeclarations --mode modules --target ES6 --name aurelia-store-docs dist/doc-temp/", @@ -137,6 +132,8 @@ "@types/intl": "^1.2.0", "@types/jest": "^21.1.10", "@types/node": "^8.10.26", + "@types/rimraf": "^2.0.2", + "@types/yargs": "^12.0.1", "aurelia-bootstrapper": "^2.3.0", "aurelia-loader-nodejs": "^1.0.1", "aurelia-pal-browser": "^1.8.0", @@ -148,17 +145,22 @@ "copyfiles": "^2.0.0", "coveralls": "^3.0.2", "cross-env": "^5.2.0", + "dts-bundle-generator": "^1.6.1", "full-icu": "^1.2.1", "html-loader": "^0.5.5", "husky": "^0.14.3", + "intl": "^1.2.5", "jest": "^22.4.4", "jest-css-modules": "^1.1.0", "rimraf": "^2.6.1", + "rollup": "^0.67.0", + "rollup-plugin-typescript2": "^0.17.2", "ts-jest": "^22.4.6", + "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.11.1", "typescript": "^3.0.1", - "intl": "^1.2.5" + "yargs": "^12.0.2" }, "aurelia": { "build": { diff --git a/src/aurelia-i18n.ts b/src/aurelia-i18n.ts index b363cde8..cfcb641e 100644 --- a/src/aurelia-i18n.ts +++ b/src/aurelia-i18n.ts @@ -1,71 +1,47 @@ import { FrameworkConfiguration } from "aurelia-framework"; -import { EventAggregator } from "aurelia-event-aggregator"; import { ViewResources } from "aurelia-templating"; -import { BindingSignaler } from "aurelia-templating-resources"; -import { PLATFORM } from "aurelia-pal"; import { I18N, AureliaEnhancedI18Next } from "./i18n"; +import { TValueConverter, TBindingBehavior, TCustomAttribute, TParamsCustomAttribute } from "./t"; +import { NfValueConverter, NfBindingBehavior } from "./nf"; +import { DfValueConverter, DfBindingBehavior } from "./df"; +import { RtValueConverter, RtBindingBehavior } from "./rt"; export * from "./i18n"; export * from "./relativeTime"; export * from "./aurelia-i18n-loader"; -export { - DfValueConverter, - DfBindingBehavior -} from "./df"; -export { - NfValueConverter, - NfBindingBehavior -} from "./nf"; -export { - RtValueConverter, - RtBindingBehavior -} from "./rt"; -export { - TValueConverter, - TBindingBehavior, - TCustomAttribute, - TParamsCustomAttribute -} from "./t"; +export * from "./t"; export function configure( frameworkConfig: FrameworkConfiguration, cb: (instance: I18N) => AureliaEnhancedI18Next ) { - if (cb === undefined || typeof cb !== "function") { + if (typeof cb !== "function") { const errorMsg = "You need to provide a callback method to properly configure the library"; throw errorMsg; } + const instance: I18N = frameworkConfig.container.get(I18N); + const ret = cb(instance); + frameworkConfig.globalResources([ - PLATFORM.moduleName("./t/t-value-converter"), - PLATFORM.moduleName("./t/t-custom-attribute"), - PLATFORM.moduleName("./t/t-params-custom-attribute"), - PLATFORM.moduleName("./t/t-binding-behavior") - ]); - frameworkConfig.globalResources([ - PLATFORM.moduleName("./nf/nf-value-converter"), - PLATFORM.moduleName("./nf/nf-binding-behavior") - ]); - frameworkConfig.globalResources([ - PLATFORM.moduleName("./df/df-value-converter"), - PLATFORM.moduleName("./df/df-binding-behavior") - ]); - frameworkConfig.globalResources([ - PLATFORM.moduleName("./rt/rt-value-converter"), - PLATFORM.moduleName("./rt/rt-binding-behavior") - ]); + TValueConverter, + TBindingBehavior, + TCustomAttribute, + TParamsCustomAttribute, - const instance = new I18N( - frameworkConfig.container.get(EventAggregator), - frameworkConfig.container.get(BindingSignaler) - ); - frameworkConfig.container.registerInstance(I18N, instance); + NfValueConverter, + NfBindingBehavior, - const ret = cb(instance); + DfValueConverter, + DfBindingBehavior, + + RtValueConverter, + RtBindingBehavior + ]); frameworkConfig.postTask(() => { const resources = frameworkConfig.container.get(ViewResources); diff --git a/src/df/df-binding-behavior.ts b/src/df/df-binding-behavior.ts index 41529a14..85513aa2 100644 --- a/src/df/df-binding-behavior.ts +++ b/src/df/df-binding-behavior.ts @@ -1,6 +1,7 @@ import { SignalBindingBehavior } from "aurelia-templating-resources"; -import { ValueConverter } from "aurelia-binding"; +import { ValueConverter, bindingBehavior } from "aurelia-binding"; +@bindingBehavior("df") export class DfBindingBehavior { public static inject() { return [SignalBindingBehavior]; } diff --git a/src/df/df-value-converter.ts b/src/df/df-value-converter.ts index 0deab4f6..4add03ee 100644 --- a/src/df/df-value-converter.ts +++ b/src/df/df-value-converter.ts @@ -1,6 +1,8 @@ import { I18N } from "../i18n"; import { isInteger } from "../utils"; +import { valueConverter } from "aurelia-binding"; +@valueConverter("df") export class DfValueConverter { public static inject() { return [I18N]; } diff --git a/src/i18n.ts b/src/i18n.ts index 50a5444a..62ec8a1a 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,7 +1,4 @@ -import i18next, { - i18n, - InitOptions -} from "i18next"; +import i18next from "i18next"; import { DOM, PLATFORM @@ -9,14 +6,13 @@ import { import * as LogManager from "aurelia-logging"; import { EventAggregator } from "aurelia-event-aggregator"; import { BindingSignaler } from "aurelia-templating-resources"; -import { autoinject } from "aurelia-framework"; -export interface AureliaEnhancedOptions extends InitOptions { +export interface AureliaEnhancedOptions extends i18next.InitOptions { attributes?: string[]; skipTranslationOnMissingKey?: boolean; } -export interface AureliaEnhancedI18Next extends i18n { +export interface AureliaEnhancedI18Next extends i18next.i18n { options: AureliaEnhancedOptions; } @@ -28,8 +24,10 @@ export interface I18NEventPayload { export const I18N_EA_SIGNAL = "i18n:locale:changed"; -@autoinject() export class I18N { + + public static inject() { return [EventAggregator, BindingSignaler]; } + public i18nextDeferred: Promise; public i18next: AureliaEnhancedI18Next; public Intl: typeof Intl; @@ -40,7 +38,7 @@ export class I18N { this.Intl = PLATFORM.global.Intl; } - public async setup(options?: AureliaEnhancedOptions & InitOptions) { + public async setup(options?: AureliaEnhancedOptions & i18next.InitOptions) { const defaultOptions = { skipTranslationOnMissingKey: false, compatibilityAPI: "v1", diff --git a/src/nf/nf-binding-behavior.ts b/src/nf/nf-binding-behavior.ts index 20ff6b77..d646318e 100644 --- a/src/nf/nf-binding-behavior.ts +++ b/src/nf/nf-binding-behavior.ts @@ -1,6 +1,7 @@ import { SignalBindingBehavior } from "aurelia-templating-resources"; -import { ValueConverter } from "aurelia-binding"; +import { ValueConverter, bindingBehavior } from "aurelia-binding"; +@bindingBehavior("nf") export class NfBindingBehavior { public static inject() { return [SignalBindingBehavior]; } diff --git a/src/nf/nf-value-converter.ts b/src/nf/nf-value-converter.ts index 2afc85b9..a5cb4753 100644 --- a/src/nf/nf-value-converter.ts +++ b/src/nf/nf-value-converter.ts @@ -1,7 +1,10 @@ import { I18N } from "../i18n"; +import { valueConverter } from "aurelia-binding"; +@valueConverter("nf") export class NfValueConverter { public static inject() { return [I18N]; } + constructor(private service: I18N) {} public toView( diff --git a/src/rt/rt-binding-behavior.ts b/src/rt/rt-binding-behavior.ts index 5499b0a1..dc0cb6c4 100644 --- a/src/rt/rt-binding-behavior.ts +++ b/src/rt/rt-binding-behavior.ts @@ -1,6 +1,7 @@ import { SignalBindingBehavior } from "aurelia-templating-resources"; -import { ValueConverter } from "aurelia-binding"; +import { ValueConverter, bindingBehavior } from "aurelia-binding"; +@bindingBehavior("rt") export class RtBindingBehavior { public static inject() { return [SignalBindingBehavior]; } diff --git a/src/rt/rt-value-converter.ts b/src/rt/rt-value-converter.ts index 28a83e8e..b10f8ebf 100644 --- a/src/rt/rt-value-converter.ts +++ b/src/rt/rt-value-converter.ts @@ -1,7 +1,10 @@ import { RelativeTime } from "../relativeTime"; +import { valueConverter } from "aurelia-binding"; +@valueConverter("rt") export class RtValueConverter { public static inject() { return [RelativeTime]; } + constructor(private service: RelativeTime) {} public toView(value: any) { diff --git a/src/t/t-binding-behavior.ts b/src/t/t-binding-behavior.ts index c2bbf67c..7be829ce 100644 --- a/src/t/t-binding-behavior.ts +++ b/src/t/t-binding-behavior.ts @@ -1,8 +1,9 @@ import { SignalBindingBehavior } from "aurelia-templating-resources"; -import { ValueConverter } from "aurelia-binding"; +import { ValueConverter, bindingBehavior } from "aurelia-binding"; +@bindingBehavior("t") export class TBindingBehavior { - public static inject = [SignalBindingBehavior]; + public static inject() { return [SignalBindingBehavior]; } constructor(private signalBindingBehavior: SignalBindingBehavior) { } diff --git a/src/t/t-value-converter.ts b/src/t/t-value-converter.ts index f2505edf..c927b406 100644 --- a/src/t/t-value-converter.ts +++ b/src/t/t-value-converter.ts @@ -1,7 +1,9 @@ import i18next from "i18next"; import { I18N } from "../i18n"; +import { valueConverter } from "aurelia-framework"; +@valueConverter("t") export class TValueConverter { public static inject() { return [I18N]; } diff --git a/test/unit/aurelia.integration.spec.ts b/test/unit/aurelia.integration.spec.ts index 9d554afb..9ecd3496 100644 --- a/test/unit/aurelia.integration.spec.ts +++ b/test/unit/aurelia.integration.spec.ts @@ -1,7 +1,7 @@ import { FrameworkConfiguration, ViewResources, Container, Aurelia } from "aurelia-framework"; import { bootstrap } from "aurelia-bootstrapper"; -import { configure, I18N, Backend } from "../../src/aurelia-i18n"; +import { configure, I18N, Backend, AureliaBackendOptions } from "../../src/aurelia-i18n"; import { StageComponent } from "aurelia-testing"; describe("testing aurelia configure routine", () => { @@ -70,6 +70,17 @@ describe("testing aurelia configure routine", () => { .inView("
Hello!
") .boundTo({ mydate: new Date() }); + const originalInit = Backend.prototype.init; + Backend.prototype.init = function init(services: any, options: AureliaBackendOptions = {}) { + this.services = services; + this.options = Object.assign({}, { + loadPath: "./fixtures/locales/{{lng}}/{{ns}}.json", + addPath: "locales/add/{{lng}}/{{ns}}", + allowMultiLoading: false, + parse: JSON.parse + }, options); + }; + component.bootstrap((aurelia: Aurelia) => { return aurelia.use .standardConfiguration() @@ -93,6 +104,8 @@ describe("testing aurelia configure routine", () => { debug: false }); + Backend.prototype.init = originalInit; + component.dispose(); }); }); diff --git a/test/unit/staging-helpers.ts b/test/unit/staging-helpers.ts index 51335124..172668c7 100644 --- a/test/unit/staging-helpers.ts +++ b/test/unit/staging-helpers.ts @@ -27,7 +27,7 @@ export function bootstrapTestEnvironment( return instance.setup(Object.assign({ backend: { // <-- configure backend settings - loadPath: "./locales/{{lng}}/{{ns}}.json", // <-- XHR settings for where to get the files from + loadPath: "./fixtures/locales/{{lng}}/{{ns}}.json", // <-- XHR settings for where to get the files from }, interpolation: { prefix: "{{", diff --git a/tsconfig.json b/tsconfig.json index 12510ea2..cfc460b8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,18 @@ { "compilerOptions": { - "module": "commonjs", + "module": "esnext", "moduleResolution": "node", "target": "es5", "lib": [ "es2017", "dom" ], - "outDir": "dist/commonjs", "noImplicitAny": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "strictNullChecks": true, - "declaration": true, - "declarationDir": "dist/typings", + "declaration": false, "forceConsistentCasingInFileNames": true, "strictPropertyInitialization": false, "experimentalDecorators": true, @@ -28,6 +26,7 @@ ".vscode", "dist", "doc", - "node_modules" + "node_modules", + "build" ] } From 42f372621eb93afc5b758a54392417927642fcc9 Mon Sep 17 00:00:00 2001 From: "bigopon.777@gmail.com" Date: Sat, 10 Nov 2018 09:01:40 +1100 Subject: [PATCH 2/5] fix(package-json): adjust typings path, test watch script --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ff9e0357..d7d8d105 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "pretest": "cross-env npm run lint", "test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest", "test-ci": "cross-env NODE_ICU_DATA=node_modules/full-icu jest && cat ./test/coverage-jest/lcov.info | ./node_modules/coveralls/bin/coveralls.js", - "test-watch": "concurrently \"tsc --watch\" \"jest --watch\"", + "test-watch": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch", "prebuild": "cross-env rimraf dist", "build": "cross-env TS_NODE_PROJECT=build/tsconfig.json ts-node build/build.ts", "build:dts": "dts-bundle-generator -o dist/aurelia-i18n.d.ts src/aurelia-i18n.ts --external-types --no-check", @@ -90,7 +90,7 @@ "Rob Eisenberg (http://robeisenberg.com/)" ], "main": "dist/commonjs/aurelia-i18n.js", - "typings": "dist/typings/aurelia-i18n.d.ts", + "typings": "dist/aurelia-i18n.d.ts", "repository": { "type": "git", "url": "http://github.com/aurelia/i18n" From d2a61b62b5115afb9c8002221e481a8f405937ed Mon Sep 17 00:00:00 2001 From: "bigopon.777@gmail.com" Date: Mon, 12 Nov 2018 21:15:35 +1100 Subject: [PATCH 3/5] fix(main): reexport df, nf & rt --- src/aurelia-i18n.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/aurelia-i18n.ts b/src/aurelia-i18n.ts index cfcb641e..bcbb5196 100644 --- a/src/aurelia-i18n.ts +++ b/src/aurelia-i18n.ts @@ -13,7 +13,24 @@ import { RtValueConverter, RtBindingBehavior } from "./rt"; export * from "./i18n"; export * from "./relativeTime"; export * from "./aurelia-i18n-loader"; -export * from "./t"; +export { + DfValueConverter, + DfBindingBehavior +} from "./df"; +export { + NfValueConverter, + NfBindingBehavior +} from "./nf"; +export { + RtValueConverter, + RtBindingBehavior +} from "./rt"; +export { + TValueConverter, + TBindingBehavior, + TCustomAttribute, + TParamsCustomAttribute +} from "./t"; export function configure( frameworkConfig: FrameworkConfiguration, From a3b9056430a426714211bfa6023791e21a90b8ce Mon Sep 17 00:00:00 2001 From: "bigopon.777@gmail.com" Date: Mon, 12 Nov 2018 21:33:51 +1100 Subject: [PATCH 4/5] fix(build): auto fix type def generation --- build/build.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/build/build.ts b/build/build.ts index 0e9cdce7..b2c24a0c 100644 --- a/build/build.ts +++ b/build/build.ts @@ -5,6 +5,7 @@ import packageJson from '../package.json'; import { IRollupWatchOptions } from './interfaces'; import * as path from 'path'; import ChildProcess from 'child_process'; +import * as fs from 'fs'; const BASE_DIR = process.cwd(); const DIST_DIR = path.join(BASE_DIR, 'dist'); @@ -131,7 +132,7 @@ if (args.dev) { async function generateDts(): Promise { console.log('\n==============\nGenerating dts bundle...\n=============='); - return new Promise(resolve => { + return new Promise((resolve, reject) => { ChildProcess.exec(`npm run build:dts`, (err, stdout, stderr) => { if (err || stderr) { console.log('Generating dts error:'); @@ -140,11 +141,25 @@ async function generateDts(): Promise { console.log('Generated dts bundle successfully'); console.log(stdout); } + try { + fixI18nDefaultImport(path.resolve(DIST_DIR, TYPE_DIST_FILE_NAME)); + } catch (ex) { + console.log('Failure fixing default import.'); + reject(ex); + } resolve(); }); }); } +async function fixI18nDefaultImport(typeDefFileName: string) { + const importDeclaration = `import i18next from "i18next";\n`; + const data = fs.readFileSync(typeDefFileName, 'utf-8'); + const fd = fs.openSync(typeDefFileName, 'w+'); + fs.writeSync(fd, Buffer.from(importDeclaration, 'utf8'), 0, importDeclaration.length, 0); + fs.writeSync(fd, Buffer.from(data, 'utf8'), 0, data.length, importDeclaration.length); +} + function copyToTargetProject(targetFormats: string[], targetProject: string) { console.log('=============\nCopying to target\n============='); targetFormats.forEach((targetFormat) => { From 561c33e5dbeafb9b58af4372fcac63a8d77041db Mon Sep 17 00:00:00 2001 From: Vildan Softic Date: Tue, 13 Nov 2018 10:14:07 +0100 Subject: [PATCH 5/5] fix(test): path mappings for win and linux --- package.json | 2 +- test/unit/aurelia.integration.spec.ts | 13 ------------- test/unit/staging-helpers.ts | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index d7d8d105..55deea30 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "src(\\\\|/)df(\\\\|/)df-(.*)": "/src/df/df-$3.ts", "src(\\\\|/)rt(\\\\|/)rt-(.*)": "/src/rt/rt-$3.ts", "(test\\\\unit\\\\)aurelia-(.*)": "/node_modules/aurelia-$2", - "locales(\\\\|/)(.*)/(.*).json": "/test/unit/fixtures/locales/$2/$3.json", + "locales(\\\\|/)(.*)(\\\\|/)(.*).json": "/test/unit/fixtures/locales/$2/$4.json", "^.+\\.(css)$": "/test/jest-css-stub.js" }, "collectCoverage": true, diff --git a/test/unit/aurelia.integration.spec.ts b/test/unit/aurelia.integration.spec.ts index 9ecd3496..619c763c 100644 --- a/test/unit/aurelia.integration.spec.ts +++ b/test/unit/aurelia.integration.spec.ts @@ -70,17 +70,6 @@ describe("testing aurelia configure routine", () => { .inView("
Hello!
") .boundTo({ mydate: new Date() }); - const originalInit = Backend.prototype.init; - Backend.prototype.init = function init(services: any, options: AureliaBackendOptions = {}) { - this.services = services; - this.options = Object.assign({}, { - loadPath: "./fixtures/locales/{{lng}}/{{ns}}.json", - addPath: "locales/add/{{lng}}/{{ns}}", - allowMultiLoading: false, - parse: JSON.parse - }, options); - }; - component.bootstrap((aurelia: Aurelia) => { return aurelia.use .standardConfiguration() @@ -104,8 +93,6 @@ describe("testing aurelia configure routine", () => { debug: false }); - Backend.prototype.init = originalInit; - component.dispose(); }); }); diff --git a/test/unit/staging-helpers.ts b/test/unit/staging-helpers.ts index 172668c7..51335124 100644 --- a/test/unit/staging-helpers.ts +++ b/test/unit/staging-helpers.ts @@ -27,7 +27,7 @@ export function bootstrapTestEnvironment( return instance.setup(Object.assign({ backend: { // <-- configure backend settings - loadPath: "./fixtures/locales/{{lng}}/{{ns}}.json", // <-- XHR settings for where to get the files from + loadPath: "./locales/{{lng}}/{{ns}}.json", // <-- XHR settings for where to get the files from }, interpolation: { prefix: "{{",