Skip to content

Commit

Permalink
xliffmerge builder
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroob committed Dec 2, 2018
1 parent 8107355 commit 39dbd9a
Show file tree
Hide file tree
Showing 23 changed files with 243 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ script:
- npm run coverall

# Send coverage data to Coveralls
after_script: "cat coverage/xliffmerge/lcov.info >coverage/xliffmerge.lcov\
after_script: "cat coverage/ngx-i18nsupport/lcov.info >coverage/ngx-i18nsupport.lcov\
&& cat coverage/tooling/lcov.info >coverage/tooling.lcov\
&& cat coverage/ngx-i18nsupport-lib/lcov.info >coverage/ngx-i18nsupport-lib.lcov\
&& node_modules/.bin/lcov-result-merger coverage/*.lcov | node_modules/.bin/coveralls"
16 changes: 16 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"de": {
"aot": true,
"outputPath": "dist/ngx-i18nsupport",
"i18nFile": "src/i18n/messages.de.xlf",
"i18nFormat": "xlf",
"i18nLocale": "de"
}
}
},
Expand All @@ -55,6 +62,9 @@
"configurations": {
"production": {
"browserTarget": "ngx-i18nsupport:build:production"
},
"de": {
"browserTarget": "ngx-i18nsupport:build:de"
}
}
},
Expand All @@ -64,6 +74,12 @@
"browserTarget": "ngx-i18nsupport:build"
}
},
"xliffmerge": {
"builder": "./dist/tooling:xliffmerge",
"options": {
"profile": "lmaa"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"extract-i18n": "ng xi18n --output-path i18n --i18n-locale en && ng run ngx-i18nsupport:xliffmerge",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
Expand All @@ -22,6 +23,7 @@
"dependencies": {
"@angular-devkit/core": "~7.0.0",
"@angular-devkit/schematics": "~7.0.0",
"@angular-devkit/architect": "~7.0.0",
"@angular/animations": "^7.0.0",
"@angular/cdk": "^7.0.0",
"@angular/common": "^7.0.0",
Expand Down
5 changes: 4 additions & 1 deletion projects/tooling/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"dest": "../../dist/tooling",
"lib": {
"entryFile": "src/public_api.ts"
}
},
"whitelistedNonPeerDependencies": [
"@ngx-i18nsupport/ngx-i18nsupport"
]
}
16 changes: 11 additions & 5 deletions projects/tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
"private": false,
"description": "Schematics to add the tooling to be used with the Angular 2 i18n workflow",
"schematics": "./schematics/src/collection.json",
"builders": "./builders/src/builders.json",
"scripts": {
"build": "ng build tooling && npm run build:schematics && npm run copy:schematics",
"build": "ng build tooling && npm run build:schematics && npm run copy:schematics && npm run build:builders && npm run copy:builders",
"build:schematics": "tsc -p src/schematics/tsconfig.json",
"copy:schematics": "cpx \"./src/schematics/**\" ../../dist/tooling/schematics",
"build:builders": "tsc -p src/builders/tsconfig.json",
"copy:builders": "cpx \"./src/builders/**\" ../../dist/tooling/builders",
"pretest": "npm run build",
"test": "jasmine ../../dist/tooling/schematics/**/*spec.js",
"debugtest": "node %NODE_DEBUG_OPTION% ../../node_modules/jasmine/bin/jasmine.js ../../dist/tooling/schematics/**/*spec.js",
Expand All @@ -31,12 +34,15 @@
"url": "https://github.com/martinroob/ngx-i18nsupport/issues"
},
"homepage": "https://github.com/martinroob/ngx-i18nsupport#readme",
"dependencies": {
"@ngx-i18nsupport/ngx-i18nsupport": "^1.1.0"
},
"devDependencies": {
},
"peerDependencies": {
"@angular-devkit/core": "^0.8.6",
"@angular-devkit/schematics": "^0.8.6",
"@angular/common": "^6.0.0",
"@angular/core": "^6.0.0"
"@angular-devkit/core": "~7.0.0",
"@angular-devkit/schematics": "~7.0.0",
"@angular/common": "^7.0.0",
"@angular/core": "^7.0.0"
}
}
10 changes: 10 additions & 0 deletions projects/tooling/src/builders/src/builders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "@angular-devkit/architect/src/builders-schema.json",
"builders": {
"xliffmerge": {
"class": "./xliffmergebuilder/xliffmerge.builder.js",
"schema": "./xliffmergebuilder//schema.json",
"description": "Builder to run xliffmerge after the ng xi18n build"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {IXliffMergeOptions} from '@ngx-i18nsupport/ngx-i18nsupport';

export interface XliffmergeBuilderSchema {
xliffmergeOptions?: IXliffMergeOptions;
profile?: string;
}
22 changes: 22 additions & 0 deletions projects/tooling/src/builders/src/xliffmergebuilder/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "http://json-schema.org/schema#",
"id": "https://github.com/martinroob/ngx-i18nsupport/configuration-schema.json",
"title": "ngx-i18nsupport-configuration",
"description": "config file for ngx-i18nsupport xliffmerge",
"type": "object",
"properties": {
"xliffmergeOptions": {
"description": "configuration options for xliffmerge, same schema as xliffmerge, see documentation for details",
"type": "object",
"properties": {
},
"required": [],
"additionalProperties": true
},
"profile": {
"description": "profile for xliffmerge (a file containing the options)",
"type": "string"
}
},
"required": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
An Angular Builder to run xliffmerge.
Work is based on nice blog article
https://medium.com/dailyjs/angular-cli-6-under-the-hood-builders-demystified-f0690ebcf01 by Evgeny Barabanov
**/
import {Observable, of} from 'rxjs';
import {catchError, map} from 'rxjs/operators';
import {getSystemPath} from '@angular-devkit/core';
import {Builder, BuilderConfiguration, BuilderContext, BuildEvent} from '@angular-devkit/architect';
import {XliffmergeBuilderSchema} from './schema';
import {XliffMerge, CommandOutput, WriterToString, ProgramOptions, IConfigFile} from '@ngx-i18nsupport/ngx-i18nsupport';

export default class XliffmergeBuilder implements Builder<XliffmergeBuilderSchema> {

constructor(private context: BuilderContext) {
}

run(builderConfig: BuilderConfiguration<Partial<XliffmergeBuilderSchema>>): Observable<BuildEvent> {
const {xliffmergeOptions, profile} = builderConfig.options;
console.log('xliffmergeOptions, profile', xliffmergeOptions, profile);
let programOptions: ProgramOptions = {};
let options: IConfigFile|undefined = {xliffmergeOptions: xliffmergeOptions};
if (profile) {
const root = this.context.workspace.root;
const profilePath = `${getSystemPath(root)}/${profile}`;
programOptions = {profilePath: profilePath};
options = undefined;
}
const ws: WriterToString = new WriterToString();
const commandOutput: CommandOutput = new CommandOutput(ws);
const xliffmerge = XliffMerge.createFromOptions(commandOutput, programOptions, options);
return xliffmerge.runAsync().pipe(
map((rc) => {
if (rc !== 0) {
this.context.logger.warn(`xliffmerge rc=${rc}`);
}
this.context.logger.info(ws.writtenData());
return {success: true};
}),
catchError((error) => {
this.context.logger.info(ws.writtenData());
this.context.logger.error('xliffmerge failed: ' + error);
return of({success: false});
})
);
}

}
32 changes: 32 additions & 0 deletions projects/tooling/src/builders/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "../../../../dist/tooling/builders",
"lib": [
"es2017",
"dom"
],
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"strictNullChecks": true,
"target": "es6",
"types": [
"jasmine",
"node"
]
},
"include": [
"src/**/*"
],
"exclude": [
]
}
2 changes: 1 addition & 1 deletion projects/tooling/src/schematics/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const xliffmergePackage = '@ngx-i18nsupport/ngx-i18nsupport';
* This value will be written into package.json of the project that uses ng add.
* TODO must be changed for every new release.
*/
export const xliffmergeVersion = '^1.0.1';
export const xliffmergeVersion = '^1.1.0';

/**
* The default language (i18nLocale) when you do not specify anything.
Expand Down
1 change: 1 addition & 0 deletions projects/tooling/src/schematics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "../../../../dist/tooling/schematics",
"lib": [
"es2017",
Expand Down
40 changes: 0 additions & 40 deletions projects/xliffmerge/dist.package.json

This file was deleted.

2 changes: 1 addition & 1 deletion projects/xliffmerge/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/xliffmerge",
"dest": "../../dist/ngx-i18nsupport",
"lib": {
"entryFile": "src/public_api.ts",
"umdModuleIds": {
Expand Down
8 changes: 4 additions & 4 deletions projects/xliffmerge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ngx-i18nsupport/ngx-i18nsupport",
"version": "1.0.1",
"version": "1.1.0",
"description": "Some tooling to be used with the Angular 2 i18n workflow",
"private": false,
"bin": {
Expand All @@ -12,13 +12,13 @@
"scripts": {
"build": "ng build xliffmerge && npm run build:apiAndLib && npm run build:copy",
"build:apiAndLib": "tsc -p src/tsconfig.json",
"build:copy": "cpx ./README.md ../../dist/xliffmerge && cpx ./src/xliffmerge/xliffmerge ../../dist/xliffmerge/xliffmerge && cpx ./src/xliffmerge/configuration-schema.json ../../dist/xliffmerge/xliffmerge/configuration-schema.json",
"build:copy": "cpx ./README.md ../../dist/ngx-i18nsupport && cpx ./src/xliffmerge/xliffmerge ../../dist/ngx-i18nsupport/xliffmerge && cpx ./src/xliffmerge/configuration-schema.json ../../dist/ngx-i18nsupport/xliffmerge/configuration-schema.json",
"xliffmerge": "npm link && xliffmerge",
"pretest": "npm run build",
"test": "jasmine ../../dist/xliffmerge/**/*spec.js",
"test": "jasmine ../../dist/ngx-i18nsupport/**/*spec.js",
"testintern": "set API_KEY_FILE=s:\\experimente\\ngx-i18nsupport\\projects\\xliffmerge\\googleTranslateApiKey.txt&& npm run test",
"precover": "npm run build",
"cover": "istanbul cover --dir ../../coverage/xliffmerge --root ../../dist/xliffmerge/src --include-all-sources ../../node_modules/jasmine-node/bin/jasmine-node -- ../../dist/xliffmerge/src",
"cover": "istanbul cover --dir ../../coverage/ngx-i18nsupport --root ../../dist/ngx-i18nsupport/src --include-all-sources ../../node_modules/jasmine-node/bin/jasmine-node -- ../../dist/ngx-i18nsupport/src",
"prepublish": "npm run build"
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions projects/xliffmerge/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
// The module is here only because ng-packagr needs it
export * from './lib/xliffmerge.module';
export {IXliffMergeOptions, IConfigFile, ProgramOptions} from './xliffmerge/i-xliff-merge-options';
export {WriterToString} from './common/writer-to-string';
export {CommandOutput} from './common/command-output';
export {XliffMerge} from './xliffmerge/xliff-merge';
2 changes: 1 addition & 1 deletion projects/xliffmerge/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.lib.json",
"compilerOptions": {
"outDir": "../../../dist/xliffmerge/src",
"outDir": "../../../dist/ngx-i18nsupport/src",
"lib": [
"es2017",
"dom"
Expand Down
11 changes: 10 additions & 1 deletion projects/xliffmerge/src/xliffmerge/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
*/
import * as path from 'path';

const pkg = require(path.resolve(__dirname, '..', '..', 'package.json'));
let pkg = null;
try {
pkg = require(path.resolve(__dirname, '..', 'package.json'));
} catch (e) {
try {
pkg = require(path.resolve(__dirname, '..', '..', 'package.json'));
} catch (e) {
pkg = null;
}
}

export const VERSION = (pkg ? pkg.version : 'unknown');
4 changes: 2 additions & 2 deletions projects/xliffmerge/src/xliffmerge/xliff-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class XliffMerge {
* @param errorFunction callbackFunction for error handling
*/
public run(callbackFunction?: ((retcode: number) => any), errorFunction?: ((error: any) => any)) {
this.doRun()
this.runAsync()
.subscribe((retcode: number) => {
if (!isNullOrUndefined(callbackFunction)) {
callbackFunction(retcode);
Expand All @@ -132,7 +132,7 @@ export class XliffMerge {
* Execute merge-Process.
* @return Async operation, on completion returns retcode 0=ok, other = error.
*/
private doRun(): Observable<number> {
public runAsync(): Observable<number> {
if (this.options && this.options.quiet) {
this.commandOutput.setQuiet();
}
Expand Down
Loading

0 comments on commit 39dbd9a

Please sign in to comment.