-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Req.] Typescript support? #217
Comments
Not currently,although it wouldn't be impossible. What advantages would you say having a typed package-scripts file has? |
It makes it possible to import typed utility functions written in ts that abstract the generation of the configuration. Also it would allow to write modern javascript without the hassle of using requires, module.export etc. (using babel would do the same more or less). |
I'm also looking for this, and as a shortcut I have installed ts-node and used the following:
To run your scripts using typescript... If you use nps_utils.concurrent.nps or nps_utils.series.nps you may need to replace them by: function concurrentNPS(...scriptNames: Array<string>): string {
return npsUtils.concurrent(
scriptNames.map(mapNPSScripts).reduce(reduceNPSScripts, {}),
);
function mapNPSScripts(scriptName: boolean | string | any): any {
if (!Boolean(scriptName)) {
return undefined;
} else if (typeof scriptName === 'string') {
return { script: scriptName};
} else {
return scriptName;
}
}
function quoteScript(script: string, escaped?: string): string {
const quote = escaped ? '\\"' : '"';
const shouldQuote = script.indexOf(' ') !== -1;
return shouldQuote ? `${quote}${script}${quote}` : script;
}
function reduceNPSScripts(scripts: any, scriptObj: any): string {
if (!scriptObj) {
return scripts;
}
const { color, script } = scriptObj;
const [name] = script.split(' ');
scripts[name] = {
script: `nps --config ./package-scripts.ts --require ts-node/register ${quoteScript(script.trim())}`,
color,
};
return scripts;
}
}; For nps_utils.concurrent.nps and: function seriesNPS(...scriptNames: Array<string>): string {
function quoteScript(script: string, escaped?: string): string {
const quote = escaped ? '\\"' : '"';
const shouldQuote = script.indexOf(' ') !== -1;
return shouldQuote ? `${quote}${script}${quote}` : script;
}
return npsUtils.series(
...scriptNames
.filter(Boolean)
.map(scriptName => scriptName.trim())
.filter(Boolean)
.map(scriptName => `nps --config ./package-scripts.ts --require ts-node/register {quoteScript(scriptName)}`),
);
}; For nps_utils.series.nps. Where the functions are similarly the same, but use Also the definition for the package_script file is: interface Scripts {
[index: string]: string | {
script: string;
description?: string;
hiddenFromHelp?: boolean;
} | Scripts;
}
interface PackageScripts {
scripts: Scripts;
} |
Type safety and all other things TS has to offer |
Are there any plans to support Typescript so one can use package-scripts.ts instead of package-scripts.js?
The text was updated successfully, but these errors were encountered: