Skip to content

Commit

Permalink
Auto merge pull request #355 from atomist/automation-client-ts
Browse files Browse the repository at this point in the history
* Remove unwanted file "scripting" methods

* Better typedoc

* Remove unused methods
  • Loading branch information
johnsonr authored and atomist-bot committed Sep 4, 2018
1 parent 39de4a1 commit 81c8f59
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 246 deletions.
17 changes: 0 additions & 17 deletions src/operations/generate/UniversalSeed.ts

This file was deleted.

21 changes: 1 addition & 20 deletions src/project/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,11 @@ export interface FileCore {
}

/**
* @deprecated
* Convenient way to defer File operations with fluent API
*/
export interface FileScripting extends ScriptedFlushable<File> {

/**
* 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 {
Expand Down
20 changes: 0 additions & 20 deletions src/project/support/AbstractFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,12 @@ export abstract class AbstractFile extends AbstractScriptedFlushable<File> imple

public abstract setContent(content: string): Promise<this>;

public recordSetContent(newContent: string): this {
return this.recordAction(f => f.setContent(newContent));
}

public rename(name: string): Promise<this> {
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<this>;

public recordSetPath(path: string): this {
return this.recordAction(f => f.setPath(path));
}

public replace(re: RegExp, replacement: string): Promise<this> {
return this.getContent()
.then(content =>
Expand All @@ -58,14 +46,6 @@ export abstract class AbstractFile extends AbstractScriptedFlushable<File> 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<boolean>;

public abstract isReadable(): Promise<boolean>;
Expand Down
13 changes: 13 additions & 0 deletions src/util/constructionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

/**
* Interface for a no-arg function that can create an instance of the given type
*/
export type Factory<T> = () => T;

/**
* Interface for objects with a no-arg constructor
*/
export interface Constructor<T> {

new(): T;
Expand All @@ -11,6 +18,12 @@ export interface Constructor<T> {
*/
export type Maker<T> = Factory<T> | Constructor<T>;

/**
* Convert a factory function with no arguments or a class with a no arg
* constructor to a factory function
* @param {Maker<T>} fact
* @return {Factory<T>}
*/
export function toFactory<T>(fact: Maker<T>): Factory<T> {
const detyped = fact as any;
try {
Expand Down
125 changes: 0 additions & 125 deletions test/project/local/NodeFsLocalFileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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")
Expand Down
14 changes: 0 additions & 14 deletions test/project/local/NodeFsLocalProjectTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
defer(p, p.addFile("thing", "1"));
Expand Down
14 changes: 0 additions & 14 deletions test/project/mem/InMemoryProjectTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
38 changes: 2 additions & 36 deletions test/project/util/projectUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit 81c8f59

Please sign in to comment.