-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scaffold): add typescript support
- Loading branch information
Showing
8 changed files
with
344 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
__tests__ | ||
tsconfig.json | ||
*.ts |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import * as jscodeshift from "jscodeshift"; | ||
|
||
interface IScaffoldBaseObject { | ||
type: string; | ||
name: string; | ||
message: string; | ||
} | ||
|
||
interface IInquirerList extends IScaffoldBaseObject { | ||
choices?: string[]; | ||
} | ||
|
||
interface IInquirerInput extends IScaffoldBaseObject { | ||
validate?: Function; | ||
} | ||
|
||
export function createArrowFunction(value: Function): string { | ||
return `() => '${value}'`; | ||
} | ||
|
||
export function createRegularFunction(value: Function): string { | ||
return `function () {\n return '${value}'\n}`; | ||
} | ||
|
||
export function createDynamicPromise(arrOrString: Function[] | string): string { | ||
if (Array.isArray(arrOrString)) { | ||
return ( | ||
"() => new Promise((resolve) => resolve([" + | ||
arrOrString.map((func: Function) => { | ||
return "'" + func + "'"; | ||
}) + | ||
"]))" | ||
); | ||
} else { | ||
return "() => new Promise((resolve) => resolve(" + "'" + arrOrString + "'" + "))"; | ||
} | ||
} | ||
|
||
export function createAssetFilterFunction(value: string): string { | ||
return `function (assetFilename) {\n return assetFilename.endsWith('.${value}');\n}`; | ||
} | ||
|
||
export function createExternalFunction(regexp: string): string { | ||
return ( | ||
"\n function (context, request, callback) {\n if (" + | ||
"/" + | ||
regexp + | ||
"/.test(request)){" + | ||
"\n" + | ||
" return callback(null, 'commonjs' + request);\n}\n" + | ||
"callback();\n}" | ||
); | ||
} | ||
|
||
export function parseValue(regexp: string): string { | ||
return jscodeshift(regexp); | ||
} | ||
|
||
export function createRequire(val: string): string { | ||
return `const ${val} = require('${val}');`; | ||
} | ||
|
||
export function List(name: string, message: string, choices: string[]): IInquirerList { | ||
return { | ||
choices, | ||
message, | ||
name, | ||
type: "list", | ||
}; | ||
} | ||
|
||
export function RawList(name: string, message: string, choices: string[]): IInquirerList { | ||
return { | ||
choices, | ||
message, | ||
name, | ||
type: "rawlist", | ||
}; | ||
} | ||
|
||
export function CheckList(name: string, message: string, choices: string[]): IInquirerList { | ||
return { | ||
choices, | ||
message, | ||
name, | ||
type: "checkbox", | ||
}; | ||
} | ||
|
||
export function Input(name: string, message: string): IInquirerInput { | ||
return { | ||
message, | ||
name, | ||
type: "input", | ||
}; | ||
} | ||
|
||
export function InputValidate(name: string, message: string, cb: Function): IInquirerInput { | ||
return { | ||
message, | ||
name, | ||
type: "input", | ||
validate: cb, | ||
}; | ||
} | ||
|
||
export function Confirm(name: string, message: string): IScaffoldBaseObject { | ||
return { | ||
message, | ||
name, | ||
type: "confirm", | ||
}; | ||
} | ||
|
||
export function AutoComplete(name: string, message: string, options: object = {}) { | ||
return Object.assign({ | ||
message, | ||
name, | ||
type: "autocomplete", | ||
}, options); | ||
} |
Oops, something went wrong.