Fix sourceRoot and destinationRoot and add fs API

This commit is contained in:
Klaus Reimer
2015-12-22 09:13:14 +01:00
parent 2321f2da77
commit 1b1ee18ef9
2 changed files with 45 additions and 5 deletions
+25 -1
View File
@@ -35,6 +35,7 @@ var compose = generator.composeWith('namespace', 'any', {
});
compose.defaultFor('name');
compose.destinationRoot() === 'string';
compose.destinationRoot('rootPath') === 'string';
compose.determineAppname();
compose.getCollisionFilter()('output');
@@ -59,7 +60,8 @@ compose.run('args', () => {
compose.runHooks(() => {
return;
});
returnString = compose.sourceRoot('rootPath') === 'string';
compose.sourceRoot('rootPath') === 'string';
compose.sourceRoot() === 'string';
var assert = yeoman.assert;
@@ -176,3 +178,25 @@ generator.prompt({ name: 'Name', message: '', validate: (input) => "Error" }, (a
generator.prompt({ name: 'Name', message: '', filter: (input) => input }, (answer) => {});
generator.prompt({ name: 'Name', message: '', when: (answers) => true }, (answer) => {});
generator.prompt({ name: 'Name', message: '', when: true }, (answer) => {});
// http://yeoman.io/generator/Base.html
// https://github.com/SBoudrias/mem-fs-editor
generator.fs.read("file") === "string";
generator.fs.read("file", {}) === "string";
generator.fs.readJSON("file") === {};
generator.fs.readJSON("file", {}) === {};
generator.fs.write("file", "contents");
generator.fs.writeJSON("file", {});
generator.fs.writeJSON("file", {}, () => {});
generator.fs.writeJSON("file", {}, () => {}, 2);
generator.fs.delete("file");
generator.fs.delete("file", {});
generator.fs.copy("from", "to");
generator.fs.copy("from", "to", {});
generator.fs.copyTpl("from", "to", {});
generator.fs.copyTpl("from", "to", {}, {});
generator.fs.move("from", "to");
generator.fs.move("from", "to", {});
generator.fs.exists("file") === true;
generator.fs.commit(() => {});
generator.fs.commit([], () => {});
+20 -4
View File
@@ -9,7 +9,7 @@ declare module yo {
argument(name: string, config: IArgumentConfig): void;
composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator;
defaultFor(name: string): void;
destinationRoot(rootPath: string): string;
destinationRoot(rootPath?: string): string;
destinationPath(...path: string[]): string;
determineAppname(): void;
getCollisionFilter(): (output: any) => void;
@@ -19,7 +19,7 @@ declare module yo {
run(args?: any): void;
run(args: any, callback?: Function): void;
runHooks(callback?: Function): void;
sourceRoot(rootPath: string): string;
sourceRoot(rootPath?: string): string;
templatePath(...path: string[]): string;
prompt(opt: IPromptOptions | IPromptOptions[], callback: (answers: any) => void): void;
npmInstall(packages?: string[] | string, options?: any, cb?: Function): void;
@@ -27,13 +27,14 @@ declare module yo {
spawnCommand(name: string, args?: string[], options?: Object): void;
spawnCommandSync(name: string, args?: string[], options?: Object): void;
options: { [key: string]: any };
fs: IMemFsEditor;
}
export class YeomanGeneratorBase implements IYeomanGenerator, NodeJS.EventEmitter {
argument(name: string, config: IArgumentConfig): void;
composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator;
defaultFor(name: string): void;
destinationRoot(rootPath: string): string;
destinationRoot(rootPath?: string): string;
destinationPath(...path: string[]): string;
determineAppname(): void;
getCollisionFilter(): (output: any) => void;
@@ -43,7 +44,7 @@ declare module yo {
run(args?: any): void;
run(args: any, callback?: Function): void;
runHooks(callback?: Function): void;
sourceRoot(rootPath: string): string;
sourceRoot(rootPath?: string): string;
templatePath(...path: string[]): string;
addListener(event: string, listener: Function): NodeJS.EventEmitter;
on(event: string, listener: Function): NodeJS.EventEmitter;
@@ -65,6 +66,21 @@ declare module yo {
appname: string;
gruntfile: IGruntFileStatic;
options: { [key: string]: any };
fs: IMemFsEditor;
}
export interface IMemFsEditor {
read(filepath: string, options?: Object): string;
readJSON(filepath: string, defaults?: Object): Object;
write(filepath: string, contents: string): void;
writeJSON(filepath: string, contents: Object, replacer?: Function, space?: number): void;
delete(filepath: string, options?: Object): void;
copy(from: string, to: string, options?: Object): void;
copyTpl(from: string, to: string, context: Object, options?: Object): void;
move(from: string, to: string, options?: Object): void;
exists(filepath: string): boolean;
commit(callback: Function): void;
commit(filters: any[], callback: Function): void;
}
export interface IInstallDependencyOptions {