From 54fefcf5d250bbadf154c7cc027b74932f510bbc Mon Sep 17 00:00:00 2001 From: Convly Date: Tue, 5 Apr 2022 16:30:50 +0200 Subject: [PATCH] isTypeScriptProject -> isUsingTypeScript --- packages/core/strapi/lib/commands/build.js | 7 ++++--- packages/core/strapi/lib/commands/builders/admin.js | 4 +++- packages/core/strapi/lib/commands/builders/typescript.js | 9 +++------ packages/core/strapi/lib/commands/develop.js | 3 ++- packages/core/strapi/lib/commands/watchAdmin.js | 2 +- packages/generators/generators/lib/plops/api.js | 2 +- packages/generators/generators/lib/plops/content-type.js | 2 +- packages/generators/generators/lib/plops/controller.js | 2 +- packages/generators/generators/lib/plops/middleware.js | 2 +- packages/generators/generators/lib/plops/plugin.js | 2 +- packages/generators/generators/lib/plops/policy.js | 2 +- packages/generators/generators/lib/plops/service.js | 2 +- packages/utils/typescript/lib/utils/index.js | 8 ++++---- ...cript-project-sync.js => is-using-typescript-sync.js} | 2 +- .../{is-typescript-project.js => is-using-typescript.js} | 2 +- 15 files changed, 26 insertions(+), 25 deletions(-) rename packages/utils/typescript/lib/utils/{is-typescript-project-sync.js => is-using-typescript-sync.js} (79%) rename packages/utils/typescript/lib/utils/{is-typescript-project.js => is-using-typescript.js} (79%) diff --git a/packages/core/strapi/lib/commands/build.js b/packages/core/strapi/lib/commands/build.js index 56b0d969e5..d2c5e9e907 100644 --- a/packages/core/strapi/lib/commands/build.js +++ b/packages/core/strapi/lib/commands/build.js @@ -11,10 +11,10 @@ module.exports = async ({ optimization, forceBuild = true }) => { let buildDestDir = process.cwd(); const srcDir = process.cwd(); - const isTSProject = await tsUtils.isTypeScriptProject(srcDir); + const useTypeScriptServer = await tsUtils.isUsingTypeScript(srcDir); // Typescript - if (isTSProject) { + if (useTypeScriptServer) { await buildTypeScript({ srcDir, watch: false }); // Update the dir path for the next steps @@ -24,7 +24,8 @@ module.exports = async ({ optimization, forceBuild = true }) => { await buildAdmin({ buildDestDir, forceBuild, - isTSProject, + // TODO: Delegate the is-ts-project check to the admin + isTSProject: useTypeScriptServer, optimization, srcDir, }); diff --git a/packages/core/strapi/lib/commands/builders/admin.js b/packages/core/strapi/lib/commands/builders/admin.js index bb7cdefa0e..ff9705c493 100644 --- a/packages/core/strapi/lib/commands/builders/admin.js +++ b/packages/core/strapi/lib/commands/builders/admin.js @@ -12,8 +12,10 @@ const getEnabledPlugins = require('../../core/loaders/plugins/get-enabled-plugin module.exports = async ({ buildDestDir, forceBuild = true, isTSProject, optimization, srcDir }) => { const strapiInstance = strapi({ - // TODO check if this is working @convly + // Directories + appDir: srcDir, distDir: buildDestDir, + // Options autoReload: true, serveAdminPanel: false, }); diff --git a/packages/core/strapi/lib/commands/builders/typescript.js b/packages/core/strapi/lib/commands/builders/typescript.js index d9a63cace5..13e3b9a65b 100644 --- a/packages/core/strapi/lib/commands/builders/typescript.js +++ b/packages/core/strapi/lib/commands/builders/typescript.js @@ -5,8 +5,8 @@ const fs = require('fs-extra'); const tsUtils = require('@strapi/typescript-utils'); const cleanupDistDirectory = async distDir => { - if (!await fs.pathExists(distDir)){ - return + if (!(await fs.pathExists(distDir))) { + return; } const dirContent = await fs.readdir(distDir); @@ -14,21 +14,18 @@ const cleanupDistDirectory = async distDir => { // Ignore the admin build folder .filter(filename => filename !== 'build'); - for (const filename of validFilenames) { await fs.remove(path.resolve(distDir, filename)); } }; module.exports = async ({ srcDir, distDir, watch = false }) => { - const isTSProject = await tsUtils.isTypeScriptProject(srcDir); + const isTSProject = await tsUtils.isUsingTypeScript(srcDir); if (!isTSProject) { throw new Error(`tsconfig file not found in ${srcDir}`); } - - await cleanupDistDirectory(distDir); return tsUtils.compile(srcDir, { watch }); diff --git a/packages/core/strapi/lib/commands/develop.js b/packages/core/strapi/lib/commands/develop.js index 86606d9ca7..dec0dbdac6 100644 --- a/packages/core/strapi/lib/commands/develop.js +++ b/packages/core/strapi/lib/commands/develop.js @@ -21,7 +21,7 @@ const { buildTypeScript, buildAdmin } = require('./builders'); module.exports = async function({ build, watchAdmin, polling, browser }) { const appDir = process.cwd(); - const isTSProject = await tsUtils.isTypeScriptProject(appDir); + const isTSProject = await tsUtils.isUsingTypeScript(appDir); const distDir = isTSProject ? path.join(appDir, 'dist') : appDir; try { @@ -61,6 +61,7 @@ const primaryProcess = async ({ distDir, appDir, build, isTSProject, watchAdmin, await buildAdmin({ buildDestDir: distDir, forceBuild: false, + // TODO: delegates the is-ts-project check to the admin isTSProject, optimization: false, srcDir: appDir, diff --git a/packages/core/strapi/lib/commands/watchAdmin.js b/packages/core/strapi/lib/commands/watchAdmin.js index d10e63889d..309129b7fc 100644 --- a/packages/core/strapi/lib/commands/watchAdmin.js +++ b/packages/core/strapi/lib/commands/watchAdmin.js @@ -12,7 +12,7 @@ const strapi = require('../index'); module.exports = async function({ browser }) { const currentDirectory = process.cwd(); - const isTSProject = await tsUtils.isTypeScriptProject(currentDirectory); + const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory); const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory; const strapiInstance = strapi({ diff --git a/packages/generators/generators/lib/plops/api.js b/packages/generators/generators/lib/plops/api.js index 5f2cc7c7be..ec6126531b 100644 --- a/packages/generators/generators/lib/plops/api.js +++ b/packages/generators/generators/lib/plops/api.js @@ -49,7 +49,7 @@ module.exports = plop => { actions(answers) { const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{plugin}}' : 'api/{{id}}'; const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; const baseActions = [ { diff --git a/packages/generators/generators/lib/plops/content-type.js b/packages/generators/generators/lib/plops/content-type.js index b117b4919c..08dcf5bb7f 100644 --- a/packages/generators/generators/lib/plops/content-type.js +++ b/packages/generators/generators/lib/plops/content-type.js @@ -83,7 +83,7 @@ module.exports = plop => { const filePath = getFilePath(answers.destination); const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; const baseActions = [ { diff --git a/packages/generators/generators/lib/plops/controller.js b/packages/generators/generators/lib/plops/controller.js index 30534908d5..f048d133aa 100644 --- a/packages/generators/generators/lib/plops/controller.js +++ b/packages/generators/generators/lib/plops/controller.js @@ -22,7 +22,7 @@ module.exports = plop => { actions(answers) { const filePath = getFilePath(answers.destination); const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; return [ { diff --git a/packages/generators/generators/lib/plops/middleware.js b/packages/generators/generators/lib/plops/middleware.js index 9e7c2e0d35..2f0bd55e35 100644 --- a/packages/generators/generators/lib/plops/middleware.js +++ b/packages/generators/generators/lib/plops/middleware.js @@ -20,7 +20,7 @@ module.exports = plop => { actions(answers) { const filePath = getFilePath(answers.destination); const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; return [ { diff --git a/packages/generators/generators/lib/plops/plugin.js b/packages/generators/generators/lib/plops/plugin.js index 513ef6ba03..70a08dc763 100644 --- a/packages/generators/generators/lib/plops/plugin.js +++ b/packages/generators/generators/lib/plops/plugin.js @@ -39,7 +39,7 @@ module.exports = plop => { ], actions(answers) { const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; // TODO: Adds tsconfig & build command for TS plugins? diff --git a/packages/generators/generators/lib/plops/policy.js b/packages/generators/generators/lib/plops/policy.js index 08d76084a3..d13f40f96d 100644 --- a/packages/generators/generators/lib/plops/policy.js +++ b/packages/generators/generators/lib/plops/policy.js @@ -20,7 +20,7 @@ module.exports = plop => { actions(answers) { const filePath = getFilePath(answers.destination); const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; return [ { diff --git a/packages/generators/generators/lib/plops/service.js b/packages/generators/generators/lib/plops/service.js index 3d8e747731..d2604279b0 100644 --- a/packages/generators/generators/lib/plops/service.js +++ b/packages/generators/generators/lib/plops/service.js @@ -20,7 +20,7 @@ module.exports = plop => { actions(answers) { const filePath = getFilePath(answers.destination); const currentDir = process.cwd(); - const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js'; + const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js'; return [ { diff --git a/packages/utils/typescript/lib/utils/index.js b/packages/utils/typescript/lib/utils/index.js index 034eaf8565..c655a8b4a4 100644 --- a/packages/utils/typescript/lib/utils/index.js +++ b/packages/utils/typescript/lib/utils/index.js @@ -1,15 +1,15 @@ 'use strict'; -const isTypeScriptProject = require('./is-typescript-project'); -const isTypeScriptProjectSync = require('./is-typescript-project-sync'); +const isUsingTypeScript = require('./is-using-typescript'); +const isUsingTypeScriptSync = require('./is-using-typescript-sync'); const getConfigPath = require('./get-config-path'); const reportDiagnostics = require('./report-diagnostics'); const resolveConfigOptions = require('./resolve-config-options'); const formatHost = require('./format-host'); module.exports = { - isTypeScriptProject, - isTypeScriptProjectSync, + isUsingTypeScript, + isUsingTypeScriptSync, getConfigPath, reportDiagnostics, resolveConfigOptions, diff --git a/packages/utils/typescript/lib/utils/is-typescript-project-sync.js b/packages/utils/typescript/lib/utils/is-using-typescript-sync.js similarity index 79% rename from packages/utils/typescript/lib/utils/is-typescript-project-sync.js rename to packages/utils/typescript/lib/utils/is-using-typescript-sync.js index cece7366ba..31b1b49d1e 100644 --- a/packages/utils/typescript/lib/utils/is-typescript-project-sync.js +++ b/packages/utils/typescript/lib/utils/is-using-typescript-sync.js @@ -5,7 +5,7 @@ const fse = require('fs-extra'); const getConfigPath = require('./get-config-path'); /** - * Checks if `dir` is a TypeScript directory (whether there is a tsconfig file or not) + * Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not) * @param {string} dir * @param {string | undefined} filename * @returns {boolean} diff --git a/packages/utils/typescript/lib/utils/is-typescript-project.js b/packages/utils/typescript/lib/utils/is-using-typescript.js similarity index 79% rename from packages/utils/typescript/lib/utils/is-typescript-project.js rename to packages/utils/typescript/lib/utils/is-using-typescript.js index 920840d2c9..cbabb6b374 100644 --- a/packages/utils/typescript/lib/utils/is-typescript-project.js +++ b/packages/utils/typescript/lib/utils/is-using-typescript.js @@ -5,7 +5,7 @@ const fse = require('fs-extra'); const getConfigPath = require('./get-config-path'); /** - * Checks if `dir` is a TypeScript directory (whether there is a tsconfig file or not) + * Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not) * @param {string} dir * @param {string | undefined} filename * @returns {Promise}