Primeiro commit do projeto Angular

This commit is contained in:
2026-03-14 20:41:55 +00:00
parent 9bebe1de72
commit 94f4f46395
22413 changed files with 3221690 additions and 0 deletions
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
import type { MessageExtractor } from '@angular/localize/tools';
import type { BuilderContext } from '@angular-devkit/architect';
import type { ApplicationBuilderExtensions } from '../application/options';
import type { NormalizedExtractI18nOptions } from './options';
export declare function extractMessages(options: NormalizedExtractI18nOptions, builderName: string, context: BuilderContext, extractorConstructor: typeof MessageExtractor, extensions?: ApplicationBuilderExtensions): Promise<{
success: boolean;
basePath: string;
messages: LocalizeMessage[];
useLegacyIds: boolean;
}>;
@@ -0,0 +1,132 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractMessages = extractMessages;
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
const application_1 = require("../application");
const results_1 = require("../application/results");
const schema_1 = require("../application/schema");
async function extractMessages(options, builderName, context, extractorConstructor, extensions) {
const messages = [];
// Setup the build options for the application based on the buildTarget option
const buildOptions = (await context.validateOptions(await context.getTargetOptions(options.buildTarget), builderName));
buildOptions.optimization = false;
buildOptions.sourceMap = { scripts: true, vendor: true, styles: false };
buildOptions.localize = false;
buildOptions.budgets = undefined;
buildOptions.index = false;
buildOptions.serviceWorker = false;
buildOptions.outputMode = schema_1.OutputMode.Static;
buildOptions.appShell = undefined;
buildOptions.ssr = undefined;
buildOptions.prerender = undefined;
buildOptions.server = undefined;
// Build the application with the build options
const builderResult = await first((0, application_1.buildApplicationInternal)(buildOptions, context, extensions));
let success = false;
if (!builderResult || builderResult.kind === results_1.ResultKind.Failure) {
context.logger.error('Application build failed.');
}
else if (builderResult.kind !== results_1.ResultKind.Full) {
context.logger.error('Application build did not provide a full output.');
}
else {
// Setup the localize message extractor based on the in-memory files
const extractor = setupLocalizeExtractor(extractorConstructor, builderResult.files, context);
// Extract messages from each output JavaScript file.
// Output files are only present on a successful build.
for (const filePath of Object.keys(builderResult.files)) {
if (!filePath.endsWith('.js')) {
continue;
}
const fileMessages = extractor.extractMessages(filePath);
messages.push(...fileMessages);
}
success = true;
}
return {
success,
basePath: context.workspaceRoot,
messages,
// Legacy i18n identifiers are not supported with the new application builder
useLegacyIds: false,
};
}
function setupLocalizeExtractor(extractorConstructor, files, context) {
const textDecoder = new TextDecoder();
// Setup a virtual file system instance for the extractor
// * MessageExtractor itself uses readFile, relative and resolve
// * Internal SourceFileLoader (sourcemap support) uses dirname, exists, readFile, and resolve
const filesystem = {
readFile(path) {
// Output files are stored as relative to the workspace root
const requestedPath = node_path_1.default.relative(context.workspaceRoot, path);
const file = files[requestedPath];
let content;
if (file?.origin === 'memory') {
content = textDecoder.decode(file.contents);
}
else if (file?.origin === 'disk') {
content = (0, node_fs_1.readFileSync)(file.inputPath, 'utf-8');
}
if (content === undefined) {
throw new Error('Unknown file requested: ' + requestedPath);
}
return content;
},
relative(from, to) {
return node_path_1.default.relative(from, to);
},
resolve(...paths) {
return node_path_1.default.resolve(...paths);
},
exists(path) {
// Output files are stored as relative to the workspace root
const requestedPath = node_path_1.default.relative(context.workspaceRoot, path);
return files[requestedPath] !== undefined;
},
dirname(path) {
return node_path_1.default.dirname(path);
},
};
const logger = {
// level 2 is warnings
level: 2,
debug(...args) {
// eslint-disable-next-line no-console
console.debug(...args);
},
info(...args) {
context.logger.info(args.join(''));
},
warn(...args) {
context.logger.warn(args.join(''));
},
error(...args) {
context.logger.error(args.join(''));
},
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const extractor = new extractorConstructor(filesystem, logger, {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
basePath: context.workspaceRoot,
useSourceMaps: true,
});
return extractor;
}
async function first(iterable) {
for await (const value of iterable) {
return value;
}
}
//# sourceMappingURL=application-extraction.js.map
@@ -0,0 +1 @@
{"version":3,"file":"application-extraction.js","sourceRoot":"","sources":["application-extraction.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAgBH,0CAgEC;AA3ED,qCAAuC;AACvC,0DAAiC;AACjC,gDAA0D;AAK1D,oDAAgE;AAChE,kDAAmD;AAG5C,KAAK,UAAU,eAAe,CACnC,OAAqC,EACrC,WAAmB,EACnB,OAAuB,EACvB,oBAA6C,EAC7C,UAAyC;IAOzC,MAAM,QAAQ,GAAsB,EAAE,CAAC;IAEvC,8EAA8E;IAC9E,MAAM,YAAY,GAAG,CAAC,MAAM,OAAO,CAAC,eAAe,CACjD,MAAM,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,EACnD,WAAW,CACZ,CAAiD,CAAC;IACnD,YAAY,CAAC,YAAY,GAAG,KAAK,CAAC;IAClC,YAAY,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACxE,YAAY,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC9B,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;IACjC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;IAC3B,YAAY,CAAC,aAAa,GAAG,KAAK,CAAC;IACnC,YAAY,CAAC,UAAU,GAAG,mBAAU,CAAC,MAAM,CAAC;IAC5C,YAAY,CAAC,QAAQ,GAAG,SAAS,CAAC;IAClC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;IAC7B,YAAY,CAAC,SAAS,GAAG,SAAS,CAAC;IACnC,YAAY,CAAC,MAAM,GAAG,SAAS,CAAC;IAEhC,+CAA+C;IAC/C,MAAM,aAAa,GAA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ACb,sBAAsB;QACtB,KAAK,EAAE,CAAC;QACR,KAAK,CAAC,GAAG,IAAc;YACrB,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,GAAG,IAAc;YACpB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,GAAG,IAAc;YACpB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,CAAC,GAAG,IAAc;YACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;IAEF,8DAA8D;IAC9D,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,UAAiB,EAAE,MAAM,EAAE;QACpE,8DAA8D;QAC9D,QAAQ,EAAE,OAAO,CAAC,aAAoB;QACtC,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,KAAK,CAAI,QAA0B;IAChD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
+14
View File
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import type { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
import type { ApplicationBuilderExtensions } from '../application/options';
import { Schema as ExtractI18nBuilderOptions } from './schema';
/**
* @experimental Direct usage of this function is considered experimental.
*/
export declare function execute(options: ExtractI18nBuilderOptions, context: BuilderContext, extensions?: ApplicationBuilderExtensions): Promise<BuilderOutput>;
+161
View File
@@ -0,0 +1,161 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.execute = execute;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const version_1 = require("../../utils/version");
const options_1 = require("./options");
const schema_1 = require("./schema");
/**
* @experimental Direct usage of this function is considered experimental.
*/
async function execute(options, context, extensions) {
// Determine project name from builder context target
const projectName = context.target?.project;
if (!projectName) {
context.logger.error(`The 'extract-i18n' builder requires a target to be specified.`);
return { success: false };
}
const { projectType } = (await context.getProjectMetadata(projectName));
if (projectType !== 'application') {
context.logger.error(`Tried to extract from ${projectName} with 'projectType' ${projectType}, which is not supported.` +
` The 'extract-i18n' builder can only extract from applications.`);
return { success: false };
}
// Check Angular version.
(0, version_1.assertCompatibleAngularVersion)(context.workspaceRoot);
// Load the Angular localize package.
// The package is a peer dependency and might not be present
let localizeToolsModule;
try {
localizeToolsModule = await Promise.resolve().then(() => __importStar(require('@angular/localize/tools')));
}
catch {
return {
success: false,
error: `i18n extraction requires the '@angular/localize' package.` +
` You can add it by using 'ng add @angular/localize'.`,
};
}
// Normalize options
const normalizedOptions = await (0, options_1.normalizeOptions)(context, projectName, options);
const builderName = await context.getBuilderNameForTarget(normalizedOptions.buildTarget);
// Extract messages based on configured builder
const { extractMessages } = await Promise.resolve().then(() => __importStar(require('./application-extraction')));
const extractionResult = await extractMessages(normalizedOptions, builderName, context, localizeToolsModule.MessageExtractor, extensions);
if (!extractionResult.success) {
return { success: false };
}
// Perform duplicate message checks
const { checkDuplicateMessages } = localizeToolsModule;
// The filesystem is used to create a relative path for each file
// from the basePath. This relative path is then used in the error message.
const checkFileSystem = {
relative(from, to) {
return node_path_1.default.relative(from, to);
},
};
const duplicateTranslationBehavior = normalizedOptions.i18nOptions.duplicateTranslationBehavior;
const diagnostics = checkDuplicateMessages(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
checkFileSystem, extractionResult.messages, duplicateTranslationBehavior,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extractionResult.basePath);
if (diagnostics.messages.length > 0 && duplicateTranslationBehavior !== 'ignore') {
if (duplicateTranslationBehavior === 'error') {
context.logger.error(`Extraction Failed: ${diagnostics.formatDiagnostics('')}`);
return { success: false };
}
else {
context.logger.warn(diagnostics.formatDiagnostics(''));
}
}
// Serialize all extracted messages
const serializer = await createSerializer(localizeToolsModule, normalizedOptions.format, normalizedOptions.i18nOptions.sourceLocale, extractionResult.basePath, extractionResult.useLegacyIds, diagnostics);
const content = serializer.serialize(extractionResult.messages);
// Ensure directory exists
const outputPath = node_path_1.default.dirname(normalizedOptions.outFile);
if (!node_fs_1.default.existsSync(outputPath)) {
node_fs_1.default.mkdirSync(outputPath, { recursive: true });
}
// Write translation file
node_fs_1.default.writeFileSync(normalizedOptions.outFile, content);
if (normalizedOptions.progress) {
context.logger.info(`Extraction Complete. (Messages: ${extractionResult.messages.length})`);
}
return { success: true, outputPath: normalizedOptions.outFile };
}
async function createSerializer(localizeToolsModule, format, sourceLocale, basePath, useLegacyIds, diagnostics) {
const { XmbTranslationSerializer, LegacyMessageIdMigrationSerializer, ArbTranslationSerializer, Xliff1TranslationSerializer, Xliff2TranslationSerializer, SimpleJsonTranslationSerializer, } = localizeToolsModule;
switch (format) {
case schema_1.Format.Xmb:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new XmbTranslationSerializer(basePath, useLegacyIds);
case schema_1.Format.Xlf:
case schema_1.Format.Xlif:
case schema_1.Format.Xliff:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new Xliff1TranslationSerializer(sourceLocale, basePath, useLegacyIds, {});
case schema_1.Format.Xlf2:
case schema_1.Format.Xliff2:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new Xliff2TranslationSerializer(sourceLocale, basePath, useLegacyIds, {});
case schema_1.Format.Json:
return new SimpleJsonTranslationSerializer(sourceLocale);
case schema_1.Format.LegacyMigrate:
return new LegacyMessageIdMigrationSerializer(diagnostics);
case schema_1.Format.Arb:
return new ArbTranslationSerializer(sourceLocale,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
basePath, {
relative(from, to) {
return node_path_1.default.relative(from, to);
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
});
}
}
//# sourceMappingURL=builder.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"builder.js","sourceRoot":"","sources":["builder.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcH,0BAkHC;AA5HD,sDAAyB;AACzB,0DAA6B;AAC7B,iDAAqE;AAErE,uCAA6C;AAC7C,qCAAuE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KAAK,eAAM,CAAC,IAAI,CAAC;QACjB,KAAK,eAAM,CAAC,KAAK;YACf,8DAA8D;YAC9D,OAAO,IAAI,2BAA2B,CAAC,YAAY,EAAE,QAAe,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;QAC1F,KAAK,eAAM,CAAC,IAAI,CAAC;QACjB,KAAK,eAAM,CAAC,MAAM;YAChB,8DAA8D;YAC9D,OAAO,IAAI,2BAA2B,CAAC,YAAY,EAAE,QAAe,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;QAC1F,KAAK,eAAM,CAAC,IAAI;YACd,OAAO,IAAI,+BAA+B,CAAC,YAAY,CAAC,CAAC;QAC3D,KAAK,eAAM,CAAC,aAAa;YACvB,OAAO,IAAI,kCAAkC,CAAC,WAAW,CAAC,CAAC;QAC7D,KAAK,eAAM,CAAC,GAAG;YACb,OAAO,IAAI,wBAAwB,CACjC,YAAY;YACZ,8DAA8D;YAC9D,QAAe,EACf;gBACE,QAAQ,CAAC,IAAY,EAAE,EAAU;oBAC/B,OAAO,mBAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACjC,CAAC;gBACD,8DAA8D;aACxD,CACT,CAAC;IACN,CAAC;AACH,CAAC"}
+13
View File
@@ -0,0 +1,13 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Builder } from '@angular-devkit/architect';
import { execute } from './builder';
import type { Schema as ExtractI18nBuilderOptions } from './schema';
export { ExtractI18nBuilderOptions, execute };
declare const builder: Builder<ExtractI18nBuilderOptions>;
export default builder;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.execute = void 0;
const architect_1 = require("@angular-devkit/architect");
const builder_1 = require("./builder");
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return builder_1.execute; } });
const builder = (0, architect_1.createBuilder)(builder_1.execute);
exports.default = builder;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,yDAAmE;AACnE,uCAAoC;AAGA,wFAH3B,iBAAO,OAG2B;AAE3C,MAAM,OAAO,GACX,IAAA,yBAAa,EAA4B,iBAAO,CAAC,CAAC;AAEpD,kBAAe,OAAO,CAAC"}
+33
View File
@@ -0,0 +1,33 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { type DiagnosticHandlingStrategy } from '@angular/localize/tools';
import { BuilderContext } from '@angular-devkit/architect';
import { type I18nOptions } from '../../utils/i18n-options';
import { Schema as ExtractI18nOptions, Format } from './schema';
export type NormalizedExtractI18nOptions = Awaited<ReturnType<typeof normalizeOptions>>;
/**
* Normalize the user provided options by creating full paths for all path based options
* and converting multi-form options into a single form that can be directly used
* by the build process.
*
* @param context The context for current builder execution.
* @param projectName The name of the project for the current execution.
* @param options An object containing the options to use for the build.
* @returns An object containing normalized options required to perform the build.
*/
export declare function normalizeOptions(context: BuilderContext, projectName: string, options: ExtractI18nOptions): Promise<{
workspaceRoot: string;
projectRoot: string;
buildTarget: import("@angular-devkit/architect").Target;
i18nOptions: I18nOptions & {
duplicateTranslationBehavior: DiagnosticHandlingStrategy;
};
format: Format.Arb | Format.Json | Format.LegacyMigrate | Format.Xliff | Format.Xliff2 | Format.Xmb;
outFile: string;
progress: boolean;
}>;
+86
View File
@@ -0,0 +1,86 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeOptions = normalizeOptions;
const architect_1 = require("@angular-devkit/architect");
const node_assert_1 = require("node:assert");
const node_path_1 = __importDefault(require("node:path"));
const i18n_options_1 = require("../../utils/i18n-options");
const schema_1 = require("./schema");
/**
* Normalize the user provided options by creating full paths for all path based options
* and converting multi-form options into a single form that can be directly used
* by the build process.
*
* @param context The context for current builder execution.
* @param projectName The name of the project for the current execution.
* @param options An object containing the options to use for the build.
* @returns An object containing normalized options required to perform the build.
*/
async function normalizeOptions(context, projectName, options) {
const workspaceRoot = context.workspaceRoot;
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = node_path_1.default.join(workspaceRoot, projectMetadata.root ?? '');
// Target specifier defaults to the current project's build target with no specified configuration
const buildTargetSpecifier = options.buildTarget ?? ':';
const buildTarget = (0, architect_1.targetFromTargetString)(buildTargetSpecifier, projectName, 'build');
const i18nOptions = {
...(0, i18n_options_1.createI18nOptions)(projectMetadata, /** inline */ false, context.logger),
duplicateTranslationBehavior: options.i18nDuplicateTranslation || 'warning',
};
// Normalize xliff format extensions
let format = options.format;
switch (format) {
// Default format is xliff1
case undefined:
case schema_1.Format.Xlf:
case schema_1.Format.Xlif:
case schema_1.Format.Xliff:
format = schema_1.Format.Xliff;
break;
case schema_1.Format.Xlf2:
case schema_1.Format.Xliff2:
format = schema_1.Format.Xliff2;
break;
}
let outFile = options.outFile || getDefaultOutFile(format);
if (options.outputPath) {
outFile = node_path_1.default.join(options.outputPath, outFile);
}
outFile = node_path_1.default.resolve(context.workspaceRoot, outFile);
return {
workspaceRoot,
projectRoot,
buildTarget,
i18nOptions,
format,
outFile,
progress: options.progress ?? true,
};
}
function getDefaultOutFile(format) {
switch (format) {
case schema_1.Format.Xmb:
return 'messages.xmb';
case schema_1.Format.Xliff:
case schema_1.Format.Xliff2:
return 'messages.xlf';
case schema_1.Format.Json:
case schema_1.Format.LegacyMigrate:
return 'messages.json';
case schema_1.Format.Arb:
return 'messages.arb';
default:
(0, node_assert_1.fail)(`Invalid Format enum value: ${format}`);
}
}
//# sourceMappingURL=options.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAqBH,4CAkDC;AApED,yDAAmF;AACnF,6CAAmC;AACnC,0DAA6B;AAC7B,2DAA+E;AAC/E,qCAAgE;AAIhE;;;;;;;;;GASG;AACI,KAAK,UAAU,gBAAgB,CACpC,OAAuB,EACvB,WAAmB,EACnB,OAA2B;IAE3B,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAC5C,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,mBAAI,CAAC,IAAI,CAAC,aAAa,EAAG,eAAe,CAAC,IAA2B,IAAI,EAAE,CAAC,CAAC;IAEjG,kGAAkG;IAClG,MAAM,oBAAoB,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC;IACxD,MAAM,WAAW,GAAG,IAAA,kCAAsB,EAAC,oBAAoB,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IACvF,MAAM,WAAW,GAEb;QACF,GAAG,IAAA,gCAAiB,EAAC,eAAe,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC;QAC1E,4BAA4B,EAAE,OAAO,CAAC,wBAAwB,IAAI,SAAS;KAC5E,CAAC;IAEF,oCAAoC;IACpC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC5B,QAAQ,MAAM,EAAE,CAAC;QACf,2BAA2B;QAC3B,KAAK,SAAS,CAAC;QACf,KAAK,eAAM,CAAC,GAAG,CAAC;QAChB,KAAK,eAAM,CAAC,IAAI,CAAC;QACjB,KAAK,eAAM,CAAC,KAAK;YACf,MAAM,GAAG,eAAM,CAAC,KAAK,CAAC;YACtB,MAAM;QACR,KAAK,eAAM,CAAC,IAAI,CAAC;QACjB,KAAK,eAAM,CAAC,MAAM;YAChB,MAAM,GAAG,eAAM,CAAC,MAAM,CAAC;YACvB,MAAM;IACV,CAAC;IAED,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,OAAO,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,GAAG,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAEvD,OAAO;QACL,aAAa;QACb,WAAW;QACX,WAAW;QACX,WAAW;QACX,MAAM;QACN,OAAO;QACP,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;KACnC,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,eAAM,CAAC,GAAG;YACb,OAAO,cAAc,CAAC;QACxB,KAAK,eAAM,CAAC,KAAK,CAAC;QAClB,KAAK,eAAM,CAAC,MAAM;YAChB,OAAO,cAAc,CAAC;QACxB,KAAK,eAAM,CAAC,IAAI,CAAC;QACjB,KAAK,eAAM,CAAC,aAAa;YACvB,OAAO,eAAe,CAAC;QACzB,KAAK,eAAM,CAAC,GAAG;YACb,OAAO,cAAc,CAAC;QACxB;YACE,IAAA,kBAAI,EAAC,8BAA8B,MAAiB,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
+53
View File
@@ -0,0 +1,53 @@
/**
* Extract i18n target options for Build Facade.
*/
export type Schema = {
/**
* A builder target to extract i18n messages in the format of
* `project:target[:configuration]`. You can also pass in more than one configuration name
* as a comma-separated list. Example: `project:target:production,staging`.
*/
buildTarget?: string;
/**
* Output format for the generated file.
*/
format?: Format;
/**
* How to handle duplicate translations.
*/
i18nDuplicateTranslation?: I18NDuplicateTranslation;
/**
* Name of the file to output.
*/
outFile?: string;
/**
* Path where output will be placed.
*/
outputPath?: string;
/**
* Log progress to the console.
*/
progress?: boolean;
};
/**
* Output format for the generated file.
*/
export declare enum Format {
Arb = "arb",
Json = "json",
LegacyMigrate = "legacy-migrate",
Xlf = "xlf",
Xlf2 = "xlf2",
Xlif = "xlif",
Xliff = "xliff",
Xliff2 = "xliff2",
Xmb = "xmb"
}
/**
* How to handle duplicate translations.
*/
export declare enum I18NDuplicateTranslation {
Error = "error",
Ignore = "ignore",
Warning = "warning"
}
+30
View File
@@ -0,0 +1,30 @@
"use strict";
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
Object.defineProperty(exports, "__esModule", { value: true });
exports.I18NDuplicateTranslation = exports.Format = void 0;
/**
* Output format for the generated file.
*/
var Format;
(function (Format) {
Format["Arb"] = "arb";
Format["Json"] = "json";
Format["LegacyMigrate"] = "legacy-migrate";
Format["Xlf"] = "xlf";
Format["Xlf2"] = "xlf2";
Format["Xlif"] = "xlif";
Format["Xliff"] = "xliff";
Format["Xliff2"] = "xliff2";
Format["Xmb"] = "xmb";
})(Format || (exports.Format = Format = {}));
/**
* How to handle duplicate translations.
*/
var I18NDuplicateTranslation;
(function (I18NDuplicateTranslation) {
I18NDuplicateTranslation["Error"] = "error";
I18NDuplicateTranslation["Ignore"] = "ignore";
I18NDuplicateTranslation["Warning"] = "warning";
})(I18NDuplicateTranslation || (exports.I18NDuplicateTranslation = I18NDuplicateTranslation = {}));
//# sourceMappingURL=schema.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";AACA,mFAAmF;AACnF,oFAAoF;;;AAkCpF;;GAEG;AACH,IAAY,MAUX;AAVD,WAAY,MAAM;IACd,qBAAW,CAAA;IACX,uBAAa,CAAA;IACb,0CAAgC,CAAA;IAChC,qBAAW,CAAA;IACX,uBAAa,CAAA;IACb,uBAAa,CAAA;IACb,yBAAe,CAAA;IACf,2BAAiB,CAAA;IACjB,qBAAW,CAAA;AACf,CAAC,EAVW,MAAM,sBAAN,MAAM,QAUjB;AAED;;GAEG;AACH,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAChC,2CAAe,CAAA;IACf,6CAAiB,CAAA;IACjB,+CAAmB,CAAA;AACvB,CAAC,EAJW,wBAAwB,wCAAxB,wBAAwB,QAInC"}
+38
View File
@@ -0,0 +1,38 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Extract i18n Target",
"description": "Extract i18n target options for Build Facade.",
"type": "object",
"properties": {
"buildTarget": {
"type": "string",
"description": "A builder target to extract i18n messages in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.",
"pattern": "^[^:\\s]*:[^:\\s]*(:[^\\s]+)?$"
},
"format": {
"type": "string",
"description": "Output format for the generated file.",
"default": "xlf",
"enum": ["xmb", "xlf", "xlif", "xliff", "xlf2", "xliff2", "json", "arb", "legacy-migrate"]
},
"progress": {
"type": "boolean",
"description": "Log progress to the console.",
"default": true
},
"outputPath": {
"type": "string",
"description": "Path where output will be placed."
},
"outFile": {
"type": "string",
"description": "Name of the file to output."
},
"i18nDuplicateTranslation": {
"type": "string",
"description": "How to handle duplicate translations.",
"enum": ["error", "warning", "ignore"]
}
},
"additionalProperties": false
}