Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

View file

@ -0,0 +1,38 @@
/**
* @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.io/license
*/
import { FileOperator, Rule, Source } from '../engine/interface';
import { FilePredicate, MergeStrategy, Tree } from '../tree/interface';
/**
* A Source that returns an tree as its single value.
*/
export declare function source(tree: Tree): Source;
/**
* A source that returns an empty tree.
*/
export declare function empty(): Source;
/**
* Chain multiple rules into a single rule.
*/
export declare function chain(rules: Iterable<Rule> | AsyncIterable<Rule>): Rule;
/**
* Apply multiple rules to a source, and returns the source transformed.
*/
export declare function apply(source: Source, rules: Rule[]): Source;
/**
* Merge an input tree with the source passed in.
*/
export declare function mergeWith(source: Source, strategy?: MergeStrategy): Rule;
export declare function noop(): Rule;
export declare function filter(predicate: FilePredicate<boolean>): Rule;
export declare function asSource(rule: Rule): Source;
export declare function branchAndMerge(rule: Rule, strategy?: MergeStrategy): Rule;
export declare function when(predicate: FilePredicate<boolean>, operator: FileOperator): FileOperator;
export declare function partitionApplyMerge(predicate: FilePredicate<boolean>, ruleYes: Rule, ruleNo?: Rule): Rule;
export declare function forEach(operator: FileOperator): Rule;
export declare function composeFileOperators(operators: FileOperator[]): FileOperator;
export declare function applyToSubtree(path: string, rules: Rule[]): Rule;

View file

@ -0,0 +1,158 @@
"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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyToSubtree = exports.composeFileOperators = exports.forEach = exports.partitionApplyMerge = exports.when = exports.branchAndMerge = exports.asSource = exports.filter = exports.noop = exports.mergeWith = exports.apply = exports.chain = exports.empty = exports.source = void 0;
const rxjs_1 = require("rxjs");
const exception_1 = require("../exception/exception");
const host_tree_1 = require("../tree/host-tree");
const interface_1 = require("../tree/interface");
const scoped_1 = require("../tree/scoped");
const static_1 = require("../tree/static");
const call_1 = require("./call");
/**
* A Source that returns an tree as its single value.
*/
function source(tree) {
return () => tree;
}
exports.source = source;
/**
* A source that returns an empty tree.
*/
function empty() {
return () => (0, static_1.empty)();
}
exports.empty = empty;
/**
* Chain multiple rules into a single rule.
*/
function chain(rules) {
return async (initialTree, context) => {
let intermediateTree;
for await (const rule of rules) {
intermediateTree = (0, call_1.callRule)(rule, intermediateTree ?? initialTree, context);
}
return () => intermediateTree;
};
}
exports.chain = chain;
/**
* Apply multiple rules to a source, and returns the source transformed.
*/
function apply(source, rules) {
return (context) => (0, call_1.callRule)(chain(rules), (0, call_1.callSource)(source, context), context);
}
exports.apply = apply;
/**
* Merge an input tree with the source passed in.
*/
function mergeWith(source, strategy = interface_1.MergeStrategy.Default) {
return (tree, context) => {
return (0, call_1.callSource)(source, context).pipe((0, rxjs_1.map)((sourceTree) => tree.merge(sourceTree, strategy || context.strategy)), (0, rxjs_1.mapTo)(tree));
};
}
exports.mergeWith = mergeWith;
function noop() {
return () => { };
}
exports.noop = noop;
function filter(predicate) {
return (tree) => {
if (host_tree_1.HostTree.isHostTree(tree)) {
return new host_tree_1.FilterHostTree(tree, predicate);
}
else {
throw new exception_1.SchematicsException('Tree type is not supported.');
}
};
}
exports.filter = filter;
function asSource(rule) {
return (context) => (0, call_1.callRule)(rule, (0, static_1.empty)(), context);
}
exports.asSource = asSource;
function branchAndMerge(rule, strategy = interface_1.MergeStrategy.Default) {
return (tree, context) => {
return (0, call_1.callRule)(rule, tree.branch(), context).pipe((0, rxjs_1.map)((branch) => tree.merge(branch, strategy || context.strategy)), (0, rxjs_1.mapTo)(tree));
};
}
exports.branchAndMerge = branchAndMerge;
function when(predicate, operator) {
return (entry) => {
if (predicate(entry.path, entry)) {
return operator(entry);
}
else {
return entry;
}
};
}
exports.when = when;
function partitionApplyMerge(predicate, ruleYes, ruleNo) {
return (tree, context) => {
const [yes, no] = (0, static_1.partition)(tree, predicate);
return (0, rxjs_1.concat)((0, call_1.callRule)(ruleYes, yes, context), (0, call_1.callRule)(ruleNo || noop(), no, context)).pipe((0, rxjs_1.toArray)(), (0, rxjs_1.map)(([yesTree, noTree]) => {
yesTree.merge(noTree, context.strategy);
return yesTree;
}));
};
}
exports.partitionApplyMerge = partitionApplyMerge;
function forEach(operator) {
return (tree) => {
tree.visit((path, entry) => {
if (!entry) {
return;
}
const newEntry = operator(entry);
if (newEntry === entry) {
return;
}
if (newEntry === null) {
tree.delete(path);
return;
}
if (newEntry.path != path) {
tree.rename(path, newEntry.path);
}
if (!newEntry.content.equals(entry.content)) {
tree.overwrite(newEntry.path, newEntry.content);
}
});
};
}
exports.forEach = forEach;
function composeFileOperators(operators) {
return (entry) => {
let current = entry;
for (const op of operators) {
current = op(current);
if (current === null) {
// Deleted, just return.
return null;
}
}
return current;
};
}
exports.composeFileOperators = composeFileOperators;
function applyToSubtree(path, rules) {
return (tree, context) => {
const scoped = new scoped_1.ScopedTree(tree, path);
return (0, call_1.callRule)(chain(rules), scoped, context).pipe((0, rxjs_1.map)((result) => {
if (result === scoped) {
return tree;
}
else {
throw new exception_1.SchematicsException('Original tree must be returned from all rules when using "applyToSubtree".');
}
}));
};
}
exports.applyToSubtree = applyToSubtree;

View file

@ -0,0 +1,22 @@
/**
* @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.io/license
*/
import { BaseException } from '@angular-devkit/core';
import { Observable } from 'rxjs';
import { Rule, SchematicContext, Source } from '../engine/interface';
import { Tree } from '../tree/interface';
/**
* When a rule or source returns an invalid value.
*/
export declare class InvalidRuleResultException extends BaseException {
constructor(value?: {});
}
export declare class InvalidSourceResultException extends BaseException {
constructor(value?: {});
}
export declare function callSource(source: Source, context: SchematicContext): Observable<Tree>;
export declare function callRule(rule: Rule, input: Tree | Observable<Tree>, context: SchematicContext): Observable<Tree>;

View file

@ -0,0 +1,92 @@
"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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.callRule = exports.callSource = exports.InvalidSourceResultException = exports.InvalidRuleResultException = void 0;
const core_1 = require("@angular-devkit/core");
const rxjs_1 = require("rxjs");
const interface_1 = require("../tree/interface");
function _getTypeOfResult(value) {
if (value === undefined) {
return 'undefined';
}
else if (value === null) {
return 'null';
}
else if (typeof value == 'function') {
return `Function()`;
}
else if (typeof value != 'object') {
return `${typeof value}(${JSON.stringify(value)})`;
}
else {
if (Object.getPrototypeOf(value) == Object) {
return `Object(${JSON.stringify(value)})`;
}
else if (value.constructor) {
return `Instance of class ${value.constructor.name}`;
}
else {
return 'Unknown Object';
}
}
}
/**
* When a rule or source returns an invalid value.
*/
class InvalidRuleResultException extends core_1.BaseException {
constructor(value) {
super(`Invalid rule result: ${_getTypeOfResult(value)}.`);
}
}
exports.InvalidRuleResultException = InvalidRuleResultException;
class InvalidSourceResultException extends core_1.BaseException {
constructor(value) {
super(`Invalid source result: ${_getTypeOfResult(value)}.`);
}
}
exports.InvalidSourceResultException = InvalidSourceResultException;
function callSource(source, context) {
return (0, rxjs_1.defer)(async () => {
let result = source(context);
if ((0, rxjs_1.isObservable)(result)) {
result = await (0, rxjs_1.lastValueFrom)(result.pipe((0, rxjs_1.defaultIfEmpty)(undefined)));
}
if (result && interface_1.TreeSymbol in result) {
return result;
}
throw new InvalidSourceResultException(result);
});
}
exports.callSource = callSource;
function callRule(rule, input, context) {
if ((0, rxjs_1.isObservable)(input)) {
return input.pipe((0, rxjs_1.mergeMap)((inputTree) => callRuleAsync(rule, inputTree, context)));
}
else {
return (0, rxjs_1.defer)(() => callRuleAsync(rule, input, context));
}
}
exports.callRule = callRule;
async function callRuleAsync(rule, tree, context) {
let result = await rule(tree, context);
while (typeof result === 'function') {
// This is considered a Rule, chain the rule and return its output.
result = await result(tree, context);
}
if (typeof result === 'undefined') {
return tree;
}
if ((0, rxjs_1.isObservable)(result)) {
result = await (0, rxjs_1.lastValueFrom)(result.pipe((0, rxjs_1.defaultIfEmpty)(tree)));
}
if (result && interface_1.TreeSymbol in result) {
return result;
}
throw new InvalidRuleResultException(result);
}

View file

@ -0,0 +1,9 @@
/**
* @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.io/license
*/
import { Rule } from '../engine/interface';
export declare function move(from: string, to?: string): Rule;

View file

@ -0,0 +1,37 @@
"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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.move = void 0;
const core_1 = require("@angular-devkit/core");
const base_1 = require("./base");
function move(from, to) {
if (to === undefined) {
to = from;
from = '/';
}
const fromPath = (0, core_1.normalize)('/' + from);
const toPath = (0, core_1.normalize)('/' + to);
if (fromPath === toPath) {
return base_1.noop;
}
return (tree) => {
if (tree.exists(fromPath)) {
// fromPath is a file
tree.rename(fromPath, toPath);
}
else {
// fromPath is a directory
tree.getDir(fromPath).visit((path) => {
tree.rename(path, (0, core_1.join)(toPath, path.slice(fromPath.length)));
});
}
return tree;
};
}
exports.move = move;

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.io/license
*/
import { Source } from '../engine/interface';
export interface RandomOptions {
root?: string;
multi?: boolean | number;
multiFiles?: boolean | number;
}
export default function (options: RandomOptions): Source;

View file

@ -0,0 +1,40 @@
"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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
const host_tree_1 = require("../tree/host-tree");
function generateStringOfLength(l) {
return new Array(l)
.fill(0)
.map((_x) => {
return 'abcdefghijklmnopqrstuvwxyz'[Math.floor(Math.random() * 26)];
})
.join('');
}
function random(from, to) {
return Math.floor(Math.random() * (to - from)) + from;
}
function default_1(options) {
return () => {
const root = 'root' in options ? options.root : '/';
const map = new host_tree_1.HostTree();
const nbFiles = 'multiFiles' in options
? typeof options.multiFiles == 'number'
? options.multiFiles
: random(2, 12)
: 1;
for (let i = 0; i < nbFiles; i++) {
const path = 'a/b/c/d/e/f'.slice(Math.random() * 10);
const fileName = generateStringOfLength(20);
const content = generateStringOfLength(100);
map.create(root + '/' + path + '/' + fileName, content);
}
return map;
};
}
exports.default = default_1;

View file

@ -0,0 +1,23 @@
/**
* @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.io/license
*/
import { ExecutionOptions, Rule } from '../engine/interface';
/**
* Run a schematic from a separate collection.
*
* @param collectionName The name of the collection that contains the schematic to run.
* @param schematicName The name of the schematic to run.
* @param options The options to pass as input to the RuleFactory.
*/
export declare function externalSchematic<OptionT extends object>(collectionName: string, schematicName: string, options: OptionT, executionOptions?: Partial<ExecutionOptions>): Rule;
/**
* Run a schematic from the same collection.
*
* @param schematicName The name of the schematic to run.
* @param options The options to pass as input to the RuleFactory.
*/
export declare function schematic<OptionT extends object>(schematicName: string, options: OptionT, executionOptions?: Partial<ExecutionOptions>): Rule;

View file

@ -0,0 +1,50 @@
"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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.schematic = exports.externalSchematic = void 0;
const rxjs_1 = require("rxjs");
const interface_1 = require("../tree/interface");
const static_1 = require("../tree/static");
/**
* Run a schematic from a separate collection.
*
* @param collectionName The name of the collection that contains the schematic to run.
* @param schematicName The name of the schematic to run.
* @param options The options to pass as input to the RuleFactory.
*/
function externalSchematic(collectionName, schematicName, options, executionOptions) {
return (input, context) => {
const collection = context.engine.createCollection(collectionName, context.schematic.collection);
const schematic = collection.createSchematic(schematicName);
return schematic.call(options, (0, rxjs_1.of)((0, static_1.branch)(input)), context, executionOptions).pipe((0, rxjs_1.last)(), (0, rxjs_1.map)((x) => {
input.merge(x, interface_1.MergeStrategy.AllowOverwriteConflict);
return input;
}));
};
}
exports.externalSchematic = externalSchematic;
/**
* Run a schematic from the same collection.
*
* @param schematicName The name of the schematic to run.
* @param options The options to pass as input to the RuleFactory.
*/
function schematic(schematicName, options, executionOptions) {
return (input, context) => {
const collection = context.schematic.collection;
const schematic = collection.createSchematic(schematicName, true);
return schematic.call(options, (0, rxjs_1.of)((0, static_1.branch)(input)), context, executionOptions).pipe((0, rxjs_1.last)(), (0, rxjs_1.map)((x) => {
// We allow overwrite conflict here because they're the only merge conflict we particularly
// don't want to deal with; the input tree might have an OVERWRITE which the sub
input.merge(x, interface_1.MergeStrategy.AllowOverwriteConflict);
return input;
}));
};
}
exports.schematic = schematic;

View file

@ -0,0 +1,39 @@
/**
* @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.io/license
*/
import { BaseException } from '@angular-devkit/core';
import { FileOperator, Rule } from '../engine/interface';
export declare const TEMPLATE_FILENAME_RE: RegExp;
export declare class OptionIsNotDefinedException extends BaseException {
constructor(name: string);
}
export declare class UnknownPipeException extends BaseException {
constructor(name: string);
}
export declare class InvalidPipeException extends BaseException {
constructor(name: string);
}
export type PathTemplateValue = boolean | string | number | undefined;
export type PathTemplatePipeFunction = (x: string) => PathTemplateValue;
export type PathTemplateData = {
[key: string]: PathTemplateValue | PathTemplateData | PathTemplatePipeFunction;
};
export interface PathTemplateOptions {
interpolationStart: string;
interpolationEnd: string;
pipeSeparator?: string;
}
export declare function applyContentTemplate<T>(options: T): FileOperator;
export declare function contentTemplate<T>(options: T): Rule;
export declare function applyPathTemplate<T extends PathTemplateData>(data: T, options?: PathTemplateOptions): FileOperator;
export declare function pathTemplate<T extends PathTemplateData>(options: T): Rule;
/**
* Remove every `.template` suffix from file names.
*/
export declare function renameTemplateFiles(): Rule;
export declare function template<T extends object>(options: T): Rule;
export declare function applyTemplates<T extends object>(options: T): Rule;

View file

@ -0,0 +1,160 @@
"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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyTemplates = exports.template = exports.renameTemplateFiles = exports.pathTemplate = exports.applyPathTemplate = exports.contentTemplate = exports.applyContentTemplate = exports.InvalidPipeException = exports.UnknownPipeException = exports.OptionIsNotDefinedException = exports.TEMPLATE_FILENAME_RE = void 0;
const core_1 = require("@angular-devkit/core");
const node_os_1 = require("node:os");
const base_1 = require("./base");
exports.TEMPLATE_FILENAME_RE = /\.template$/;
class OptionIsNotDefinedException extends core_1.BaseException {
constructor(name) {
super(`Option "${name}" is not defined.`);
}
}
exports.OptionIsNotDefinedException = OptionIsNotDefinedException;
class UnknownPipeException extends core_1.BaseException {
constructor(name) {
super(`Pipe "${name}" is not defined.`);
}
}
exports.UnknownPipeException = UnknownPipeException;
class InvalidPipeException extends core_1.BaseException {
constructor(name) {
super(`Pipe "${name}" is invalid.`);
}
}
exports.InvalidPipeException = InvalidPipeException;
const decoder = new TextDecoder('utf-8', { fatal: true });
function applyContentTemplate(options) {
return (entry) => {
const { path, content } = entry;
try {
const decodedContent = decoder.decode(content).replace(/\r?\n/g, node_os_1.EOL);
return {
path,
content: Buffer.from((0, core_1.template)(decodedContent, {})(options)),
};
}
catch (e) {
if (e.code === 'ERR_ENCODING_INVALID_ENCODED_DATA') {
return entry;
}
throw e;
}
};
}
exports.applyContentTemplate = applyContentTemplate;
function contentTemplate(options) {
return (0, base_1.forEach)(applyContentTemplate(options));
}
exports.contentTemplate = contentTemplate;
function applyPathTemplate(data, options = {
interpolationStart: '__',
interpolationEnd: '__',
pipeSeparator: '@',
}) {
const is = options.interpolationStart;
const ie = options.interpolationEnd;
const isL = is.length;
const ieL = ie.length;
return (entry) => {
let path = entry.path;
const content = entry.content;
const original = path;
let start = path.indexOf(is);
// + 1 to have at least a length 1 name. `____` is not valid.
let end = path.indexOf(ie, start + isL + 1);
while (start != -1 && end != -1) {
const match = path.substring(start + isL, end);
let replacement = data[match];
if (!options.pipeSeparator) {
if (typeof replacement == 'function') {
replacement = replacement.call(data, original);
}
if (replacement === undefined) {
throw new OptionIsNotDefinedException(match);
}
}
else {
const [name, ...pipes] = match.split(options.pipeSeparator);
replacement = data[name];
if (typeof replacement == 'function') {
replacement = replacement.call(data, original);
}
if (replacement === undefined) {
throw new OptionIsNotDefinedException(name);
}
replacement = pipes.reduce((acc, pipe) => {
if (!pipe) {
return acc;
}
if (!(pipe in data)) {
throw new UnknownPipeException(pipe);
}
if (typeof data[pipe] != 'function') {
throw new InvalidPipeException(pipe);
}
// Coerce to string.
return '' + data[pipe](acc);
}, '' + replacement);
}
path = path.substring(0, start) + replacement + path.substring(end + ieL);
start = path.indexOf(options.interpolationStart);
// See above.
end = path.indexOf(options.interpolationEnd, start + isL + 1);
}
return { path: (0, core_1.normalize)(path), content };
};
}
exports.applyPathTemplate = applyPathTemplate;
function pathTemplate(options) {
return (0, base_1.forEach)(applyPathTemplate(options));
}
exports.pathTemplate = pathTemplate;
/**
* Remove every `.template` suffix from file names.
*/
function renameTemplateFiles() {
return (0, base_1.forEach)((entry) => {
if (entry.path.match(exports.TEMPLATE_FILENAME_RE)) {
return {
content: entry.content,
path: (0, core_1.normalize)(entry.path.replace(exports.TEMPLATE_FILENAME_RE, '')),
};
}
else {
return entry;
}
});
}
exports.renameTemplateFiles = renameTemplateFiles;
function template(options) {
return (0, base_1.chain)([
contentTemplate(options),
// Force cast to PathTemplateData. We need the type for the actual pathTemplate() call,
// but in this case we cannot do anything as contentTemplate are more permissive.
// Since values are coerced to strings in PathTemplates it will be fine in the end.
pathTemplate(options),
]);
}
exports.template = template;
function applyTemplates(options) {
return (0, base_1.forEach)((0, base_1.when)((path) => path.endsWith('.template'), (0, base_1.composeFileOperators)([
applyContentTemplate(options),
// See above for this weird cast.
applyPathTemplate(options),
(entry) => {
return {
content: entry.content,
path: entry.path.replace(exports.TEMPLATE_FILENAME_RE, ''),
};
},
])));
}
exports.applyTemplates = applyTemplates;

View file

@ -0,0 +1,9 @@
/**
* @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.io/license
*/
import { Source } from '../engine/interface';
export declare function url(urlString: string): Source;

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.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.url = void 0;
const url_1 = require("url");
function url(urlString) {
const url = (0, url_1.parse)(urlString);
return (context) => context.engine.createSourceFromUrl(url, context)(context);
}
exports.url = url;