refactoring app and plugin generators to handle typescript

This commit is contained in:
Bassel Kanso 2022-04-25 18:46:04 +03:00
parent c49d681b18
commit 7cf9eb81eb
2 changed files with 16 additions and 20 deletions

View File

@ -19,10 +19,8 @@ module.exports = async scope => {
if (!scope.useTypescript) {
// check how to handle track usage here
const isTypescript = await askAboutLanguages(scope).catch(error => {
console.log(error)
})
scope.useTypescript = isTypescript;
const language = await askAboutLanguages(scope);
scope.useTypescript = language === "Typescript";
}
const configuration = await askDbInfosAndTest(scope).catch(error => {
@ -167,15 +165,15 @@ async function installDatabaseTestingDep({ scope, configuration }) {
}
async function askAboutLanguages() {
const { client } = await inquirer.prompt([
const { language } = await inquirer.prompt([
{
type: 'list',
name: 'client',
message: 'Choose your language',
choices: ['Typescript', 'Javascript'],
name: 'language',
message: 'Choose your preferred language',
choices: ['Javascript', 'Typescript'],
default: 'Javascript',
},
]);
return client === 'Typescript';
return language;
}

View File

@ -27,14 +27,6 @@ ${separator}
};
module.exports = (plop) => {
const currentDir = process.cwd();
const typescriptPrompt = tsUtils.isUsingTypeScriptSync(currentDir) ? [] : [{
type: 'list',
name: 'isTypescript',
message: 'Choose your preferred language',
choices: ['Javascript', 'Typescript'],
default: 'Javascript',
}];
// Plugin generator
plop.setGenerator('plugin', {
description: 'Generate a basic plugin',
@ -44,11 +36,17 @@ module.exports = (plop) => {
name: 'pluginName',
message: 'Plugin name',
},
...typescriptPrompt
{
type: 'list',
name: 'language',
message: 'Choose your preferred language',
choices: ['Javascript', 'Typescript'],
default: 'Javascript',
}
],
actions(answers) {
const isTypescript = answers?.isTypescript === 'Typescript';
const language = tsUtils.isUsingTypeScriptSync(currentDir) || isTypescript ? 'ts' : 'js';
const isTypescript = answers?.language === 'Typescript';
const language = isTypescript ? 'ts' : 'js';
// TODO: Adds tsconfig & build command for TS plugins?