UNPKG

9.67 kBSource Map (JSON)View Raw
1{"version":3,"file":"change.js","sourceRoot":"","sources":["../../../../../modules/store/schematics-core/utility/change.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAgCA;;GAEG;AACH;IAAA;QACE,gBAAW,GAAG,eAAe,CAAC;QAC9B,UAAK,GAAG,QAAQ,CAAC;QACjB,SAAI,GAAG,IAAI,CAAC;IAId,CAAC;IAHC,0BAAK,GAAL;QACE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACH,iBAAC;AAAD,CAAC,AAPD,IAOC;AAPY,gCAAU;AASvB;;GAEG;AACH;IAIE,sBAAmB,IAAY,EAAS,GAAW,EAAS,KAAa;QAAtD,SAAI,GAAJ,IAAI,CAAQ;QAAS,QAAG,GAAH,GAAG,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAQ;QACvE,IAAI,GAAG,GAAG,CAAC,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;SACnD;QACD,IAAI,CAAC,WAAW,GAAG,cAAY,KAAK,uBAAkB,GAAG,YAAO,IAAM,CAAC;QACvE,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,4BAAK,GAAL,UAAM,IAAU;QAAhB,iBAOC;QANC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAC,OAAO;YACvC,IAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,KAAI,CAAC,GAAG,CAAC,CAAC;YAC9C,IAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,KAAI,CAAC,GAAG,CAAC,CAAC;YAE3C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAI,CAAC,IAAI,EAAE,KAAG,MAAM,GAAG,KAAI,CAAC,KAAK,GAAG,MAAQ,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC;IACH,m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KACd;IAED,IAAM,QAAQ,GAAG,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC;AARD,sCAQC","sourcesContent":["import * as ts from 'typescript';\nimport { Tree, UpdateRecorder } from '@angular-devkit/schematics';\nimport { Path } from '@angular-devkit/core';\n\n/* istanbul ignore file */\n/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nexport interface Host {\n write(path: string, content: string): Promise<void>;\n read(path: string): Promise<string>;\n}\n\nexport interface Change {\n apply(host: Host): Promise<void>;\n\n // The file this change should be applied to. Some changes might not apply to\n // a file (maybe the config).\n readonly path: string | null;\n\n // The order this change should be applied. Normally the position inside the file.\n // Changes are applied from the bottom of a file to the top.\n readonly order: number;\n\n // The description of this change. This will be outputted in a dry or verbose run.\n readonly description: string;\n}\n\n/**\n * An operation that does nothing.\n */\nexport class NoopChange implements Change {\n description = 'No operation.';\n order = Infinity;\n path = null;\n apply() {\n return Promise.resolve();\n }\n}\n\n/**\n * Will add text to the source code.\n */\nexport class InsertChange implements Change {\n order: number;\n description: string;\n\n constructor(public path: string, public pos: number, public toAdd: string) {\n if (pos < 0) {\n throw new Error('Negative positions are invalid');\n }\n this.description = `Inserted ${toAdd} into position ${pos} of ${path}`;\n this.order = pos;\n }\n\n /**\n * This method does not insert spaces if there is none in the original string.\n */\n apply(host: Host) {\n return host.read(this.path).then((content) => {\n const prefix = content.substring(0, this.pos);\n const suffix = content.substring(this.pos);\n\n return host.write(this.path, `${prefix}${this.toAdd}${suffix}`);\n });\n }\n}\n\n/**\n * Will remove text from the source code.\n */\nexport class RemoveChange implements Change {\n order: number;\n description: string;\n\n constructor(public path: string, public pos: number, public end: number) {\n if (pos < 0 || end < 0) {\n throw new Error('Negative positions are invalid');\n }\n this.description = `Removed text in position ${pos} to ${end} of ${path}`;\n this.order = pos;\n }\n\n apply(host: Host): Promise<void> {\n return host.read(this.path).then((content) => {\n const prefix = content.substring(0, this.pos);\n const suffix = content.substring(this.end);\n\n // TODO: throw error if toRemove doesn't match removed string.\n return host.write(this.path, `${prefix}${suffix}`);\n });\n }\n}\n\n/**\n * Will replace text from the source code.\n */\nexport class ReplaceChange implements Change {\n order: number;\n description: string;\n\n constructor(\n public path: string,\n public pos: number,\n public oldText: string,\n public newText: string\n ) {\n if (pos < 0) {\n throw new Error('Negative positions are invalid');\n }\n this.description = `Replaced ${oldText} into position ${pos} of ${path} with ${newText}`;\n this.order = pos;\n }\n\n apply(host: Host): Promise<void> {\n return host.read(this.path).then((content) => {\n const prefix = content.substring(0, this.pos);\n const suffix = content.substring(this.pos + this.oldText.length);\n const text = content.substring(this.pos, this.pos + this.oldText.length);\n\n if (text !== this.oldText) {\n return Promise.reject(\n new Error(`Invalid replace: \"${text}\" != \"${this.oldText}\".`)\n );\n }\n\n // TODO: throw error if oldText doesn't match removed string.\n return host.write(this.path, `${prefix}${this.newText}${suffix}`);\n });\n }\n}\n\nexport function createReplaceChange(\n sourceFile: ts.SourceFile,\n node: ts.Node,\n oldText: string,\n newText: string\n): ReplaceChange {\n return new ReplaceChange(\n sourceFile.fileName,\n node.getStart(sourceFile),\n oldText,\n newText\n );\n}\n\nexport function createRemoveChange(\n sourceFile: ts.SourceFile,\n node: ts.Node,\n from = node.getStart(sourceFile),\n to = node.getEnd()\n): RemoveChange {\n return new RemoveChange(sourceFile.fileName, from, to);\n}\n\nexport function createChangeRecorder(\n tree: Tree,\n path: string,\n changes: Change[]\n): UpdateRecorder {\n const recorder = tree.beginUpdate(path);\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n } else if (change instanceof RemoveChange) {\n recorder.remove(change.pos, change.end - change.pos);\n } else if (change instanceof ReplaceChange) {\n recorder.remove(change.pos, change.oldText.length);\n recorder.insertLeft(change.pos, change.newText);\n }\n }\n return recorder;\n}\n\nexport function commitChanges(tree: Tree, path: string, changes: Change[]) {\n if (changes.length === 0) {\n return false;\n }\n\n const recorder = createChangeRecorder(tree, path, changes);\n tree.commitUpdate(recorder);\n return true;\n}\n"]}
\No newline at end of file