mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 09:25:46 +00:00
refactor resolveOutDir in typescript/utils
This commit is contained in:
parent
3b5fd4ad79
commit
12c64a2d11
@ -94,9 +94,7 @@ async function createAdmin({ email, password, firstname, lastname }) {
|
|||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (isTSProject)
|
if (isTSProject)
|
||||||
await tsUtils.compile(appDir, {
|
await tsUtils.compile(appDir, {
|
||||||
@ -104,7 +102,7 @@ async function createAdmin({ email, password, firstname, lastname }) {
|
|||||||
configOptions: { options: { incremental: true } },
|
configOptions: { options: { incremental: true } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
|
|
||||||
const app = await strapi({ appDir, distDir }).load();
|
const app = await strapi({ appDir, distDir }).load();
|
||||||
|
|
||||||
|
@ -46,9 +46,7 @@ async function changePassword({ email, password }) {
|
|||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (isTSProject)
|
if (isTSProject)
|
||||||
await tsUtils.compile(appDir, {
|
await tsUtils.compile(appDir, {
|
||||||
@ -56,7 +54,7 @@ async function changePassword({ email, password }) {
|
|||||||
configOptions: { options: { incremental: true } },
|
configOptions: { options: { incremental: true } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
|
|
||||||
const app = await strapi({ appDir, distDir }).load();
|
const app = await strapi({ appDir, distDir }).load();
|
||||||
|
|
||||||
|
@ -11,16 +11,14 @@ module.exports = async ({ optimization, forceBuild = true }) => {
|
|||||||
const srcDir = process.cwd();
|
const srcDir = process.cwd();
|
||||||
|
|
||||||
const useTypeScriptServer = await tsUtils.isUsingTypeScript(srcDir);
|
const useTypeScriptServer = await tsUtils.isUsingTypeScript(srcDir);
|
||||||
const compiledDirectoryPath = useTypeScriptServer
|
const outDir = await tsUtils.resolveOutDir(srcDir);
|
||||||
? tsUtils.resolveConfigOptions(`${srcDir}/tsconfig.json`).options.outDir
|
|
||||||
: null;
|
|
||||||
|
|
||||||
// Typescript
|
// Typescript
|
||||||
if (useTypeScriptServer) {
|
if (useTypeScriptServer) {
|
||||||
await buildTypeScript({ srcDir, watch: false });
|
await buildTypeScript({ srcDir, watch: false });
|
||||||
|
|
||||||
// Update the dir path for the next steps
|
// Update the dir path for the next steps
|
||||||
buildDestDir = compiledDirectoryPath;
|
buildDestDir = outDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
await buildAdmin({
|
await buildAdmin({
|
||||||
|
@ -16,16 +16,14 @@ module.exports = async function({ file: filePath, pretty }) {
|
|||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
|
||||||
: null;
|
|
||||||
if (isTSProject)
|
if (isTSProject)
|
||||||
await tsUtils.compile(appDir, {
|
await tsUtils.compile(appDir, {
|
||||||
watch: false,
|
watch: false,
|
||||||
configOptions: { options: { incremental: true } },
|
configOptions: { options: { incremental: true } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
|
|
||||||
const app = await strapi({ appDir, distDir }).load();
|
const app = await strapi({ appDir, distDir }).load();
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@ module.exports = async function({ file: filePath, strategy = 'replace' }) {
|
|||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (isTSProject)
|
if (isTSProject)
|
||||||
await tsUtils.compile(appDir, {
|
await tsUtils.compile(appDir, {
|
||||||
@ -27,7 +25,7 @@ module.exports = async function({ file: filePath, strategy = 'replace' }) {
|
|||||||
configOptions: { options: { incremental: true } },
|
configOptions: { options: { incremental: true } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
|
|
||||||
const app = await strapi({ appDir, distDir }).load();
|
const app = await strapi({ appDir, distDir }).load();
|
||||||
|
|
||||||
|
@ -12,9 +12,7 @@ module.exports = async () => {
|
|||||||
// Now load up the Strapi framework for real.
|
// Now load up the Strapi framework for real.
|
||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (isTSProject)
|
if (isTSProject)
|
||||||
await tsUtils.compile(appDir, {
|
await tsUtils.compile(appDir, {
|
||||||
@ -22,7 +20,7 @@ module.exports = async () => {
|
|||||||
configOptions: { options: { incremental: true } },
|
configOptions: { options: { incremental: true } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
|
|
||||||
const app = await strapi({ appDir, distDir }).load();
|
const app = await strapi({ appDir, distDir }).load();
|
||||||
|
|
||||||
|
@ -22,10 +22,8 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
: null;
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cluster.isMaster || cluster.isPrimary) {
|
if (cluster.isMaster || cluster.isPrimary) {
|
||||||
|
@ -11,9 +11,7 @@ module.exports = async function() {
|
|||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (isTSProject)
|
if (isTSProject)
|
||||||
await tsUtils.compile(appDir, {
|
await tsUtils.compile(appDir, {
|
||||||
@ -21,7 +19,7 @@ module.exports = async function() {
|
|||||||
configOptions: { options: { incremental: true } },
|
configOptions: { options: { incremental: true } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const distDir = isTSProject ? compiledDirectoryPath : appDir;
|
const distDir = isTSProject ? outDir : appDir;
|
||||||
|
|
||||||
const app = await strapi({ appDir, distDir }).load();
|
const app = await strapi({ appDir, distDir }).load();
|
||||||
|
|
||||||
|
@ -8,10 +8,13 @@ const strapi = require('../index');
|
|||||||
module.exports = async specifiedDir => {
|
module.exports = async specifiedDir => {
|
||||||
const appDir = process.cwd();
|
const appDir = process.cwd();
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(appDir);
|
||||||
? tsUtils.resolveConfigOptions(`${appDir}/tsconfig.json`).options.outDir
|
if (isTSProject)
|
||||||
: null;
|
await tsUtils.compile(appDir, {
|
||||||
const distDir = isTSProject && !specifiedDir ? compiledDirectoryPath : specifiedDir;
|
watch: false,
|
||||||
|
configOptions: { options: { incremental: true } },
|
||||||
|
});
|
||||||
|
const distDir = isTSProject && !specifiedDir ? outDir : specifiedDir;
|
||||||
|
|
||||||
strapi({ distDir }).start();
|
strapi({ distDir }).start();
|
||||||
};
|
};
|
||||||
|
@ -12,10 +12,8 @@ module.exports = async function({ browser }) {
|
|||||||
const currentDirectory = process.cwd();
|
const currentDirectory = process.cwd();
|
||||||
|
|
||||||
const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
|
const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
|
||||||
const compiledDirectoryPath = isTSProject
|
const outDir = await tsUtils.resolveOutDir(currentDirectory);
|
||||||
? tsUtils.resolveConfigOptions(`${currentDirectory}/tsconfig.json`).options.outDir
|
const buildDestDir = isTSProject ? outDir : currentDirectory;
|
||||||
: null;
|
|
||||||
const buildDestDir = isTSProject ? compiledDirectoryPath : currentDirectory;
|
|
||||||
|
|
||||||
const strapiInstance = strapi({
|
const strapiInstance = strapi({
|
||||||
distDir: buildDestDir,
|
distDir: buildDestDir,
|
||||||
|
@ -6,6 +6,7 @@ const getConfigPath = require('./get-config-path');
|
|||||||
const reportDiagnostics = require('./report-diagnostics');
|
const reportDiagnostics = require('./report-diagnostics');
|
||||||
const resolveConfigOptions = require('./resolve-config-options');
|
const resolveConfigOptions = require('./resolve-config-options');
|
||||||
const formatHost = require('./format-host');
|
const formatHost = require('./format-host');
|
||||||
|
const resolveOutDir = require('./resolve-outdir');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isUsingTypeScript,
|
isUsingTypeScript,
|
||||||
@ -14,4 +15,5 @@ module.exports = {
|
|||||||
reportDiagnostics,
|
reportDiagnostics,
|
||||||
resolveConfigOptions,
|
resolveConfigOptions,
|
||||||
formatHost,
|
formatHost,
|
||||||
|
resolveOutDir,
|
||||||
};
|
};
|
||||||
|
16
packages/utils/typescript/lib/utils/resolve-outdir.js
Normal file
16
packages/utils/typescript/lib/utils/resolve-outdir.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
'use strict';
|
||||||
|
const resolveConfigOptions = require('./resolve-config-options');
|
||||||
|
const isUsingTypescript = require('./is-using-typescript');
|
||||||
|
|
||||||
|
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
||||||
|
/**
|
||||||
|
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
||||||
|
* @param {string} dir
|
||||||
|
* @param {string | undefined} configFilename
|
||||||
|
* @returns {string | undefined}
|
||||||
|
*/
|
||||||
|
module.exports = async (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
|
||||||
|
return (await isUsingTypescript(dir))
|
||||||
|
? resolveConfigOptions(`${dir}/${configFilename}`).options.outDir
|
||||||
|
: undefined;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user