diff --git a/src/operations/generate/UniversalSeed.ts b/src/operations/generate/UniversalSeed.ts deleted file mode 100644 index 2ccd57e4f..000000000 --- a/src/operations/generate/UniversalSeed.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Project } from "../../project/Project"; -import { doWithFiles } from "../../project/util/projectUtils"; - -/** - * Remove content from README specific to this project. - * - * @param project project whose README should be cleaned - * @param description brief description of newly created project - */ -export function cleanReadMe(description: string, project: Project): Promise { - return doWithFiles(project, "README.md", readMe => { - readMe.recordReplace(/^#[\\s\\S]*?## Development/, `# ${project.name} -This project contains ${description}. - -## Development`); - }); -} diff --git a/src/project/File.ts b/src/project/File.ts index ed33353ce..6a0cc1de6 100644 --- a/src/project/File.ts +++ b/src/project/File.ts @@ -22,30 +22,11 @@ export interface FileCore { } /** + * @deprecated * Convenient way to defer File operations with fluent API */ export interface FileScripting extends ScriptedFlushable { - /** - * Set entire file content to new string - * - * @param newContent {string} The content to set the file to - */ - recordSetContent(newContent: string): this; - - recordRename(name: string): this; - - recordSetPath(name: string): this; - - /** - * Replace all occurrences of the given regular expression with - * @param re - * @param replacement - */ - recordReplace(re: RegExp, replacement: string): this; - - recordReplaceAll(oldLiteral: string, newLiteral: string): this; - } export interface FileAsync extends FileCore { diff --git a/src/project/support/AbstractFile.ts b/src/project/support/AbstractFile.ts index d5b6c8993..cfadae819 100644 --- a/src/project/support/AbstractFile.ts +++ b/src/project/support/AbstractFile.ts @@ -26,24 +26,12 @@ export abstract class AbstractFile extends AbstractScriptedFlushable imple public abstract setContent(content: string): Promise; - public recordSetContent(newContent: string): this { - return this.recordAction(f => f.setContent(newContent)); - } - public rename(name: string): Promise { return this.setPath(this.path.replace(new RegExp(`${this.name}$`), name)); } - public recordRename(name: string): this { - return this.recordSetPath(this.path.replace(new RegExp(`${this.name}$`), name)); - } - public abstract setPath(path: string): Promise; - public recordSetPath(path: string): this { - return this.recordAction(f => f.setPath(path)); - } - public replace(re: RegExp, replacement: string): Promise { return this.getContent() .then(content => @@ -58,14 +46,6 @@ export abstract class AbstractFile extends AbstractScriptedFlushable imple ); } - public recordReplace(re: RegExp, replacement: string): this { - return this.recordAction(f => f.replace(re, replacement)); - } - - public recordReplaceAll(oldLiteral: string, newLiteral: string): this { - return this.recordAction(f => f.replaceAll(oldLiteral, newLiteral)); - } - public abstract isExecutable(): Promise; public abstract isReadable(): Promise; diff --git a/src/util/constructionUtils.ts b/src/util/constructionUtils.ts index 5b9015770..defeec949 100644 --- a/src/util/constructionUtils.ts +++ b/src/util/constructionUtils.ts @@ -1,5 +1,12 @@ + +/** + * Interface for a no-arg function that can create an instance of the given type + */ export type Factory = () => T; +/** + * Interface for objects with a no-arg constructor + */ export interface Constructor { new(): T; @@ -11,6 +18,12 @@ export interface Constructor { */ export type Maker = Factory | Constructor; +/** + * Convert a factory function with no arguments or a class with a no arg + * constructor to a factory function + * @param {Maker} fact + * @return {Factory} + */ export function toFactory(fact: Maker): Factory { const detyped = fact as any; try { diff --git a/test/project/local/NodeFsLocalFileTest.ts b/test/project/local/NodeFsLocalFileTest.ts index 2ad476064..60025ce53 100644 --- a/test/project/local/NodeFsLocalFileTest.ts +++ b/test/project/local/NodeFsLocalFileTest.ts @@ -41,32 +41,6 @@ describe("NodeFsLocalFile", () => { assert(p.findFileSync("config/Thing")); }); - it("should recordRename and read", done => { - const p = tempProject(); - p.addFileSync("config/Thing", "The quick brown"); - const f = p.findFileSync("config/Thing"); - f.recordRename("Thing2"); - f.flush().then(_ => { - assert(f.name === "Thing2"); - assert(f.path === "config/Thing2", `path was [${f.path}]`); - done(); - }).catch(done); - }); - - it("should recordRename and read from disk", done => { - const p = tempProject(); - p.addFileSync("config/Thing", "The quick brown"); - const f = p.findFileSync("config/Thing"); - f.recordRename("Thing2"); - f.flush() - .then(_ => { - assert(!p.findFileSync("config/Thing")); - assert(p.findFileSync("config/Thing2")); - done(); - }) - .catch(done); - }); - it("should set content sync and read back", () => { const p = tempProject(); p.addFileSync("Thing", "The quick brown"); @@ -76,20 +50,6 @@ describe("NodeFsLocalFile", () => { assert(f.getContentSync() === "The slow brown"); }); - it("should record set content and read back from disk", done => { - const p = tempProject(); - p.addFileSync("Thing", "The quick brown"); - const f = p.findFileSync("Thing"); - assert(f.getContentSync() === "The quick brown"); - f.recordSetContent("The slow brown") - .flush() - .then(() => { - assert(f.getContentSync() === "The slow brown"); - done(); - }, - ); - }); - it("should set content and read back from disk", done => { const p = tempProject(); p.addFileSync("Thing", "The quick brown"); @@ -103,91 +63,6 @@ describe("NodeFsLocalFile", () => { ); }); - it("should recordReplace content and read back", done => { - const p = tempProject(); - p.addFileSync("Thing", "The quick brown"); - const f = p.findFileSync("Thing"); - assert(!f.dirty); - assert(f.getContentSync() === "The quick brown"); - f.recordReplace(/(The )([a-z]+)( brown)/, "$1slow$3"); - assert(f.dirty); - f.flush().then(_ => { - assert(f.getContentSync() === "The slow brown"); - done(); - }); - }); - - it("should recordReplace content and read back from disk", done => { - const p = tempProject(); - p.addFileSync("Thing", "The quick brown"); - const f = p.findFileSync("Thing"); - assert(f.getContentSync() === "The quick brown"); - f.recordReplace(/(The )([a-z]+)( brown)/, "$1slow$3") - .flush() - .then(() => { - assert(f.getContentSync() === "The slow brown"); - done(); - }, - ).catch(done); - }); - - it("should recordReplaceAll and read back from disk", done => { - const p = tempProject(); - p.addFileSync("Thing", "One two three"); - const f = p.findFileSync("Thing"); - assert(f.getContentSync() === "One two three"); - f.recordReplaceAll("e", "z") - .flush() - .then(() => { - assert(f.getContentSync() === "Onz two thrzz"); - done(); - }, - ).catch(done); - }); - - it("should set path and read back", done => { - const p = tempProject(); - p.addFileSync("Thing1", "The quick brown"); - const f = p.findFileSync("Thing1"); - assert(f.getContentSync() === "The quick brown"); - f.recordSetPath("Thing2"); - f.flush().then(_ => { - assert(f.path === "Thing2"); - assert(!f.dirty); - done(); - }).catch(done); - }); - - it("should set path and read back from disk", done => { - const p = tempProject(); - p.addFileSync("Thing1", "The quick brown"); - const f = p.findFileSync("Thing1"); - assert(f.getContentSync() === "The quick brown"); - f.recordSetPath("Thing2"); - f.flush() - .then(_ => { - assert(p.findFileSync("Thing2")); - assert(!p.findFileSync("Thing1")); - done(); - }) - .catch(done); - }); - - it("should set path in different directory and read back from disk", done => { - const p = tempProject(); - p.addFileSync("Thing1", "The quick brown"); - const f = p.findFileSync("Thing1"); - assert(f.getContentSync() === "The quick brown"); - f.recordSetPath("dir/Thing2"); - f.flush() - .then(_ => { - assert(p.findFileSync("dir/Thing2")); - assert(!p.findFileSync("Thing1")); - done(); - }) - .catch(done); - }); - it("should test nonbinary file", done => { const p = tempProject(); p.addFile("Thing1", "The quick brown") diff --git a/test/project/local/NodeFsLocalProjectTest.ts b/test/project/local/NodeFsLocalProjectTest.ts index 3cc5c4963..d6a8188a9 100644 --- a/test/project/local/NodeFsLocalProjectTest.ts +++ b/test/project/local/NodeFsLocalProjectTest.ts @@ -232,20 +232,6 @@ describe("NodeFsLocalProject", () => { .then(() => done(), done); }); - it("changes content", done => { - const p = tempProject(); - p.addFileSync("thing", "1"); - const f1 = p.findFileSync("thing"); - assert(f1.getContentSync() === "1"); - f1.recordSetContent("2") - .flush() - .then(_ => { - const f2 = p.findFileSync("thing"); - assert(f2.getContentSync() === "2"); - }) - .then(() => done(), done); - }); - it("adds file", done => { const p = tempProject() as any as Project & ScriptedFlushable; defer(p, p.addFile("thing", "1")); diff --git a/test/project/mem/InMemoryProjectTest.ts b/test/project/mem/InMemoryProjectTest.ts index 4b3b081fe..9413c8459 100644 --- a/test/project/mem/InMemoryProjectTest.ts +++ b/test/project/mem/InMemoryProjectTest.ts @@ -202,20 +202,6 @@ describe("InMemoryProject", () => { }).catch(done); }).timeout(5000); - it("changes content", done => { - const p = new InMemoryProject(); - p.addFileSync("thing", "1"); - const f1 = p.findFileSync("thing"); - assert(f1.getContentSync() === "1"); - f1.recordSetContent("2") - .flush() - .then(_ => { - const f2 = p.findFileSync("thing"); - assert(f2.getContentSync() === "2"); - done(); - }).catch(done); - }); - it("adds file", done => { const p = new InMemoryProject(); p.recordAddFile("thing", "1"); diff --git a/test/project/util/projectUtilsTest.ts b/test/project/util/projectUtilsTest.ts index 755e08feb..911ef5a46 100644 --- a/test/project/util/projectUtilsTest.ts +++ b/test/project/util/projectUtilsTest.ts @@ -51,8 +51,8 @@ describe("projectUtils", () => { it("withFiles: run", done => { const t = tempProject(); t.addFileSync("Thing", "1"); - doWithFiles(t, AllFiles, f => { - f.recordSetContent(f.getContentSync() + "2"); + doWithFiles(t, AllFiles, async f => { + await f.setContent(f.getContentSync() + "2"); }) .then(p => { const f = t.findFileSync("Thing"); @@ -61,40 +61,6 @@ describe("projectUtils", () => { .then(done, done); }); - it("withFiles: defer", done => { - const t = tempProject(); - t.addFileSync("Thing", "1"); - defer(t, doWithFiles(t, AllFiles, f => { - f.recordSetContent(f.getContentSync() + "2"); - })); - assert(t.findFileSync("Thing").getContentSync() === "1"); - assert(t.dirty); - t.flush() - .then(files => { - assert(!t.dirty); - const f = t.findFileSync("Thing"); - assert(f.getContentSync() === "12"); - }) - .then(done, done); - }); - - it("withFiles: defer use of script", done => { - const t = tempProject(); - t.addFileSync("Thing", "1"); - defer(t, doWithFiles(t, AllFiles, f => { - return Promise.resolve(f.recordSetContent(f.getContentSync() + "2")); - })); - assert(t.findFileSync("Thing").getContentSync() === "1"); - assert(t.dirty); - t.flush() - .then(files => { - assert(!t.dirty); - const f = t.findFileSync("Thing"); - assert(f.getContentSync() === "12"); - }) - .then(done, done); - }); - it("withFiles: run with promise", done => { const t = tempProject(); t.addFileSync("Thing", "1");