Merge pull request #13309 from strapi/typescript/fix-cli

Typescript Fix cli commands when outDir is changed
This commit is contained in:
Jean-Sébastien Herbaux 2022-05-23 16:15:47 +02:00 committed by GitHub
commit c3a10abc45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 53 additions and 24 deletions

View File

@ -1,6 +1,5 @@
'use strict';
const path = require('path');
const { yup } = require('@strapi/utils');
const _ = require('lodash');
const inquirer = require('inquirer');
@ -95,6 +94,7 @@ async function createAdmin({ email, password, firstname, lastname }) {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
if (isTSProject)
await tsUtils.compile(appDir, {
@ -102,7 +102,7 @@ async function createAdmin({ email, password, firstname, lastname }) {
configOptions: { options: { incremental: true } },
});
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const distDir = isTSProject ? outDir : appDir;
const app = await strapi({ appDir, distDir }).load();

View File

@ -1,6 +1,5 @@
'use strict';
const path = require('path');
const _ = require('lodash');
const inquirer = require('inquirer');
const tsUtils = require('@strapi/typescript-utils');
@ -47,6 +46,7 @@ async function changePassword({ email, password }) {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
if (isTSProject)
await tsUtils.compile(appDir, {
@ -54,7 +54,7 @@ async function changePassword({ email, password }) {
configOptions: { options: { incremental: true } },
});
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const distDir = isTSProject ? outDir : appDir;
const app = await strapi({ appDir, distDir }).load();

View File

@ -1,5 +1,4 @@
'use strict';
const path = require('path');
const tsUtils = require('@strapi/typescript-utils');
const { buildAdmin, buildTypeScript } = require('./builders');
@ -12,13 +11,14 @@ module.exports = async ({ optimization, forceBuild = true }) => {
const srcDir = process.cwd();
const useTypeScriptServer = await tsUtils.isUsingTypeScript(srcDir);
const outDir = await tsUtils.resolveOutDir(srcDir);
// Typescript
if (useTypeScriptServer) {
await buildTypeScript({ srcDir, watch: false });
// Update the dir path for the next steps
buildDestDir = path.join(srcDir, 'dist');
buildDestDir = outDir;
}
await buildAdmin({

View File

@ -1,7 +1,6 @@
'use strict';
const fs = require('fs');
const path = require('path');
const tsUtils = require('@strapi/typescript-utils');
const strapi = require('../index');
@ -17,14 +16,14 @@ module.exports = async function({ file: filePath, pretty }) {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
if (isTSProject)
await tsUtils.compile(appDir, {
watch: false,
configOptions: { options: { incremental: true } },
});
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const distDir = isTSProject ? outDir : appDir;
const app = await strapi({ appDir, distDir }).load();

View File

@ -1,7 +1,6 @@
'use strict';
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const tsUtils = require('@strapi/typescript-utils');
@ -18,6 +17,7 @@ module.exports = async function({ file: filePath, strategy = 'replace' }) {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
if (isTSProject)
await tsUtils.compile(appDir, {
@ -25,7 +25,7 @@ module.exports = async function({ file: filePath, strategy = 'replace' }) {
configOptions: { options: { incremental: true } },
});
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const distDir = isTSProject ? outDir : appDir;
const app = await strapi({ appDir, distDir }).load();

View File

@ -1,7 +1,6 @@
'use strict';
const REPL = require('repl');
const path = require('path');
const tsUtils = require('@strapi/typescript-utils');
const strapi = require('../index');
@ -12,8 +11,8 @@ const strapi = require('../index');
module.exports = async () => {
// Now load up the Strapi framework for real.
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
if (isTSProject)
await tsUtils.compile(appDir, {
@ -21,7 +20,7 @@ module.exports = async () => {
configOptions: { options: { incremental: true } },
});
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const distDir = isTSProject ? outDir : appDir;
const app = await strapi({ appDir, distDir }).load();

View File

@ -22,7 +22,8 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const outDir = await tsUtils.resolveOutDir(appDir);
const distDir = isTSProject ? outDir : appDir;
try {
if (cluster.isMaster || cluster.isPrimary) {

View File

@ -1,6 +1,5 @@
'use strict';
const path = require('path');
const CLITable = require('cli-table3');
const chalk = require('chalk');
const { toUpper } = require('lodash/fp');
@ -12,7 +11,15 @@ module.exports = async function() {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
const outDir = await tsUtils.resolveOutDir(appDir);
if (isTSProject)
await tsUtils.compile(appDir, {
watch: false,
configOptions: { options: { incremental: true } },
});
const distDir = isTSProject ? outDir : appDir;
const app = await strapi({ appDir, distDir }).load();

View File

@ -1,14 +1,18 @@
'use strict';
const tsUtils = require('@strapi/typescript-utils')
const fs = require('fs');
const tsUtils = require('@strapi/typescript-utils');
const strapi = require('../index');
/**
* `$ strapi start`
*/
module.exports = async specifiedDir => {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir)
const distDir = isTSProject && !specifiedDir ? 'dist' : specifiedDir;
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
const buildDirExists = fs.existsSync(outDir);
if (isTSProject && !buildDirExists) throw new Error(`${outDir} directory not found. Please run the build command before starting your application`);
const distDir = isTSProject && !specifiedDir ? outDir : specifiedDir;
strapi({ distDir }).start()
strapi({ distDir }).start();
};

View File

@ -1,6 +1,5 @@
'use strict';
const path = require('path');
const strapiAdmin = require('@strapi/admin');
const tsUtils = require('@strapi/typescript-utils');
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
@ -13,7 +12,8 @@ module.exports = async function({ browser }) {
const currentDirectory = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory;
const outDir = await tsUtils.resolveOutDir(currentDirectory);
const buildDestDir = isTSProject ? outDir : currentDirectory;
const strapiInstance = strapi({
distDir: buildDestDir,

View File

@ -6,6 +6,7 @@ const getConfigPath = require('./get-config-path');
const reportDiagnostics = require('./report-diagnostics');
const resolveConfigOptions = require('./resolve-config-options');
const formatHost = require('./format-host');
const resolveOutDir = require('./resolve-outdir');
module.exports = {
isUsingTypeScript,
@ -14,4 +15,5 @@ module.exports = {
reportDiagnostics,
resolveConfigOptions,
formatHost,
resolveOutDir,
};

View File

@ -0,0 +1,17 @@
'use strict';
const path = require('path');
const resolveConfigOptions = require('./resolve-config-options');
const isUsingTypescript = require('./is-using-typescript');
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
/**
* Gets the outDir value from config file (tsconfig)
* @param {string} dir
* @param {string | undefined} configFilename
* @returns {string | undefined}
*/
module.exports = async (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
return (await isUsingTypescript(dir))
? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
: undefined;
};