feat: Support for typescript in Strapi v4.2.0
parent
fea127f7b2
commit
c9e45c3909
|
@ -7,6 +7,7 @@ const chalk = require('chalk');
|
|||
const inquirer = require('inquirer');
|
||||
const { isEmpty } = require('lodash');
|
||||
const strapi = require('@strapi/strapi'); // eslint-disable-line
|
||||
const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line
|
||||
const gitDiff = require('git-diff');
|
||||
|
||||
const warnings = require('./warnings');
|
||||
|
@ -14,6 +15,25 @@ const packageJSON = require('../package.json');
|
|||
|
||||
const program = new Command();
|
||||
|
||||
const getStrapiApp = async () => {
|
||||
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 ? outDir : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
const initTable = (head) => {
|
||||
return new Table({
|
||||
head: [chalk.green('Name'), chalk.green(head || 'State')],
|
||||
|
@ -69,7 +89,7 @@ const getConfigState = (diff, configName, syncType) => {
|
|||
};
|
||||
|
||||
const handleAction = async (syncType, skipConfirm, configType, partials) => {
|
||||
const app = await strapi().load();
|
||||
const app = await getStrapiApp();
|
||||
const hasSyncDir = fs.existsSync(app.config.get('plugin.config-sync.syncDir'));
|
||||
|
||||
// No import with empty sync dir.
|
||||
|
@ -218,7 +238,7 @@ program
|
|||
.description('The config diff')
|
||||
.action(async (options, { args }) => {
|
||||
const single = args[0];
|
||||
const app = await strapi().load();
|
||||
const app = await getStrapiApp();
|
||||
const diff = await app.plugin('config-sync').service('main').getFormattedDiff();
|
||||
|
||||
// No changes.
|
||||
|
|
Loading…
Reference in New Issue