Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to Angular 17 #42

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "angular-t9n:build"
"buildTarget": "angular-t9n:build"
},
"configurations": {
"de": {
"browserTarget": "angular-t9n:build:de"
"buildTarget": "angular-t9n:build:de"
},
"production": {
"browserTarget": "angular-t9n:build:production"
"buildTarget": "angular-t9n:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-t9n:build",
"format": "xlf2",
"outputPath": "src/locale/xlf2"
"outputPath": "src/locale/xlf2",
"buildTarget": "angular-t9n:build"
},
"configurations": {
"xlf": {
Expand Down
10 changes: 5 additions & 5 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ export async function t9nStandalone(options: Options, currentWorkingDirectory?:
{
cors: true,
logger: ['error', 'warn'],
}
},
);
app.setGlobalPrefix('api');
app.useWebSocketAdapter(new WsAdapter(app));
app.useGlobalPipes(new ValidationPipe({ skipMissingProperties: true, whitelist: true }));
await app.listen(options.port ?? 4300, () =>
console.log(`Translation server started: http://localhost:${options.port}\n`)
console.log(`Translation server started: http://localhost:${options.port}\n`),
);
return new Promise(() => {});

Expand All @@ -127,7 +127,7 @@ export async function t9nStandalone(options: Options, currentWorkingDirectory?:
}

async function TRANSLATION_SOURCE_FACTORY(
serializationStrategy: SerializationStrategy
serializationStrategy: SerializationStrategy,
): Promise<TranslationSource> {
const result = await serializationStrategy.deserializeSource(sourceFile);
return new TranslationSource(result.language, result.unitMap);
Expand All @@ -136,7 +136,7 @@ export async function t9nStandalone(options: Options, currentWorkingDirectory?:
async function TRANSLATION_TARGET_REGISTRY_FACTORY(
source: TranslationSource,
serializationStrategy: SerializationStrategy,
persistenceStrategy: PersistenceStrategy
persistenceStrategy: PersistenceStrategy,
): Promise<TranslationTargetRegistry> {
const targetRegistry = new TranslationTargetRegistry(source, persistenceStrategy);
await Promise.all(
Expand All @@ -157,7 +157,7 @@ export async function t9nStandalone(options: Options, currentWorkingDirectory?:
console.log(`Detected ${relative(workspaceRoot, targetPath)}`);
targetRegistry.register(result.language, result.unitMap);
} catch {}
})
}),
);
return targetRegistry;
}
Expand Down
2 changes: 1 addition & 1 deletion bin/pattern-persistence-strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('PatternPersistenceStrategy', () => {
mockSerialization = new MockSerialization();
persistence = new PatternPersistenceStrategy(
builder,
mockSerialization as SerializationStrategy
mockSerialization as SerializationStrategy,
);
});

Expand Down
6 changes: 3 additions & 3 deletions bin/pattern-persistence-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
export class PatternPersistenceStrategy extends PersistenceStrategy {
constructor(
private readonly _targetPathBuilder: TargetPathBuilder,
private readonly _serializationStrategy: SerializationStrategy
private readonly _serializationStrategy: SerializationStrategy,
) {
super();
}
Expand All @@ -22,7 +22,7 @@ export class PatternPersistenceStrategy extends PersistenceStrategy {
console.log(
`${timestamp()}: Created translation file for ${
target.language
} at ${this._targetPathBuilder.createPath(target)}`
} at ${this._targetPathBuilder.createPath(target)}`,
);
}

Expand All @@ -31,7 +31,7 @@ export class PatternPersistenceStrategy extends PersistenceStrategy {
console.log(
`${timestamp()}: Updated translation file for ${
target.language
} at ${this._targetPathBuilder.createPath(target)}`
} at ${this._targetPathBuilder.createPath(target)}`,
);
}

Expand Down
22 changes: 11 additions & 11 deletions builders/t9n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
workspaceRoot,
context.target.project,
targetPathBuilder,
() => translationContext
() => translationContext,
);
const sourceLocale = await angularI18n.sourceLocale();

Expand All @@ -88,7 +88,7 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
useValue: new TargetInfo(
context.target.project,
options.translationFile,
sourceLocale.code
sourceLocale.code,
),
},
{ provide: SerializationOptions, useValue: options },
Expand Down Expand Up @@ -117,13 +117,13 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
{
cors: true,
logger: ['error', 'warn'],
}
},
);
app.setGlobalPrefix('api');
app.useWebSocketAdapter(new WsAdapter(app));
app.useGlobalPipes(new ValidationPipe({ skipMissingProperties: true, whitelist: true }));
await app.listen(options.port ?? 4300, () =>
context.logger.info(`Translation server started: http://localhost:${options.port}\n`)
context.logger.info(`Translation server started: http://localhost:${options.port}\n`),
);
return new Promise(() => {});

Expand All @@ -141,15 +141,15 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
}

async function TRANSLATION_SOURCE_FACTORY(
serializationStrategy: SerializationStrategy
serializationStrategy: SerializationStrategy,
): Promise<TranslationSource> {
try {
context.logger.info(`Attempting to serialize source file ${sourceFile}`);
const result = await serializationStrategy.deserializeSource(sourceFile);
if (result.language && sourceLocale.code && result.language !== sourceLocale.code) {
context.logger.warn(
`Source locale in angular.json is ${sourceLocale} but in the ` +
` source file ${sourceFile} it is ${result.language}.`
` source file ${sourceFile} it is ${result.language}.`,
);
}

Expand All @@ -169,7 +169,7 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
async function TRANSLATION_TARGET_REGISTRY_FACTORY(
source: TranslationSource,
serializationStrategy: SerializationStrategy,
persistenceStrategy: PersistenceStrategy
persistenceStrategy: PersistenceStrategy,
): Promise<TranslationTargetRegistry> {
try {
context.logger.info(`Attempting to serialize target files`);
Expand All @@ -183,20 +183,20 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
const relativePath = relative(workspaceRoot, normalizedPath);
if (locale.translation.every((t) => join(workspaceRoot, t) !== normalizedPath)) {
context.logger.warn(
`Expected translation file ${relativePath} not found listed in i18n! It will be created and added to the i18n entry.`
`Expected translation file ${relativePath} not found listed in i18n! It will be created and added to the i18n entry.`,
);
const target = await targetRegistry.create(language, locale.baseHref);
await importExistingTranslationUnits(target, locale.translation, serializationStrategy);
} else if (!host.isFile(normalizedPath)) {
context.logger.warn(
`Expected translation file ${relativePath} does not exist! It will be created.`
`Expected translation file ${relativePath} does not exist! It will be created.`,
);
await targetRegistry.create(language, locale.baseHref);
} else {
const result = await serializationStrategy.deserializeTarget(normalizedPath);
targetRegistry.register(result.language, result.unitMap, locale.baseHref);
}
})
}),
);

await angularI18n.update();
Expand All @@ -211,7 +211,7 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
async function importExistingTranslationUnits(
target: TranslationTarget,
translationFiles: string[],
serializationStrategy: SerializationStrategy
serializationStrategy: SerializationStrategy,
) {
for (const translation of translationFiles) {
const targetPath = join(workspaceRoot, translation);
Expand Down
8 changes: 4 additions & 4 deletions builders/t9n/persistence/angular-i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('AngularI18n', () => {
workspaceRoot,
projectName,
builder,
() => translationContext
() => translationContext,
);
}

Expand All @@ -51,7 +51,7 @@ describe('AngularI18n', () => {
locales: {
de: 'src/locale/xlf2/messages.de.xlf',
},
})
}),
);

it('should throw without source', () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('AngularI18n', () => {
baseHref: '/en/',
language: 'en-US',
},
})
}),
);

it('should update the angular.json when changed', async () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('AngularI18n', () => {
fr: 'locales/xlf2/messages.fr.xlf',
'fr-CH': ['locales/xlf2/messages.fr-CH.xlf', 'locales/xlf2/messages2.fr-CH.xlf'],
},
})
}),
);

it('should return the source locale', async () => {
Expand Down
6 changes: 3 additions & 3 deletions builders/t9n/persistence/angular-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AngularI18n {
private _translationContextFactory: () => {
source: TranslationSource;
targetRegistry: TranslationTargetRegistry;
}
},
) {}

async sourceLocale(): Promise<{ code: string; baseHref?: string }> {
Expand All @@ -38,7 +38,7 @@ export class AngularI18n {
Object.assign(current, {
[next]: this._normalizeI18nLocale(locales[next]),
}),
{} as { [locale: string]: { translation: string[]; baseHref?: string } }
{} as { [locale: string]: { translation: string[]; baseHref?: string } },
);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ export class AngularI18n {
Object.assign(current, {
[next.language]: this._i18nLocale(next, locales[next.language]),
}),
{}
{},
);

const { project, workspace } = await this._readProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('AngularJsonPersistenceStrategy', () => {
persistenceStrategy = new AngularJsonPersistenceStrategy(
new MockAngularI18n() as AngularI18n,
new logging.NullLogger(),
serializationStrategy as unknown as SerializationStrategy
serializationStrategy as unknown as SerializationStrategy,
);
});

Expand Down
6 changes: 3 additions & 3 deletions builders/t9n/persistence/angular-json-persistence-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AngularJsonPersistenceStrategy extends PersistenceStrategy {
constructor(
private readonly _i18n: AngularI18n,
private readonly _logger: logging.Logger,
private readonly _serializationStrategy: SerializationStrategy
private readonly _serializationStrategy: SerializationStrategy,
) {
super();
}
Expand All @@ -25,7 +25,7 @@ export class AngularJsonPersistenceStrategy extends PersistenceStrategy {
this._logger.info(
`${timestamp()}: Created translation file for ${
target.language
} at ${this._i18n.projectRelativePath(target)}`
} at ${this._i18n.projectRelativePath(target)}`,
);
}

Expand All @@ -34,7 +34,7 @@ export class AngularJsonPersistenceStrategy extends PersistenceStrategy {
this._logger.info(
`${timestamp()}: Updated translation file for ${
target.language
} at ${this._i18n.projectRelativePath(target)}`
} at ${this._i18n.projectRelativePath(target)}`,
);
}

Expand Down
Loading