Skip to content

Commit

Permalink
feat(scaffold): add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Jul 4, 2018
1 parent 2c69df0 commit eaf6fdf
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 125 deletions.
1 change: 1 addition & 0 deletions packages/webpack-scaffold/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
2 changes: 2 additions & 0 deletions packages/webpack-scaffold/.npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__tests__
tsconfig.json
*.ts
124 changes: 0 additions & 124 deletions packages/webpack-scaffold/index.js

This file was deleted.

121 changes: 121 additions & 0 deletions packages/webpack-scaffold/index.ts
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);
}
Loading

0 comments on commit eaf6fdf

Please sign in to comment.