isTypeScriptProject -> isUsingTypeScript

This commit is contained in:
Convly 2022-04-05 16:30:50 +02:00
parent 831726978a
commit 54fefcf5d2
15 changed files with 26 additions and 25 deletions

View File

@ -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,
});

View File

@ -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,
});

View File

@ -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 });

View File

@ -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,

View File

@ -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({

View File

@ -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 = [
{

View File

@ -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 = [
{

View File

@ -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 [
{

View File

@ -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 [
{

View File

@ -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?

View File

@ -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 [
{

View File

@ -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 [
{

View File

@ -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,

View File

@ -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}

View File

@ -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<boolean>}