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