mirror of
https://github.com/strapi/strapi.git
synced 2025-11-04 20:07:19 +00:00
Merge pull request #13187 from strapi/typescript/fix-cli
Typescript/fix cli
This commit is contained in:
commit
8c5bbefaa6
@ -95,6 +95,7 @@ program
|
||||
.option('--dbssl <dbssl>', 'Database SSL')
|
||||
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
||||
.option('--dbforce', 'Allow overwriting existing database content')
|
||||
.option('-ts, --typescript', 'Create a typescript project')
|
||||
.description('Create a new application')
|
||||
.action(require('../lib/commands/new'));
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const { yup } = require('@strapi/utils');
|
||||
const _ = require('lodash');
|
||||
const inquirer = require('inquirer');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
const strapi = require('../index');
|
||||
|
||||
const emailValidator = yup
|
||||
@ -90,7 +92,12 @@ module.exports = async function(cmdOptions = {}) {
|
||||
};
|
||||
|
||||
async function createAdmin({ email, password, firstname, lastname }) {
|
||||
const app = await strapi().load();
|
||||
const appDir = process.cwd();
|
||||
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
const user = await app.admin.services.user.exists({ email });
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const inquirer = require('inquirer');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
const strapi = require('../index');
|
||||
|
||||
const promptQuestions = [
|
||||
@ -42,7 +44,12 @@ module.exports = async function(cmdOptions = {}) {
|
||||
};
|
||||
|
||||
async function changePassword({ email, password }) {
|
||||
const app = await strapi().load();
|
||||
const appDir = process.cwd();
|
||||
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
await app.admin.services.user.resetPasswordByEmail(email, password);
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
const strapi = require('../index');
|
||||
|
||||
const CHUNK_SIZE = 100;
|
||||
@ -12,7 +14,12 @@ const CHUNK_SIZE = 100;
|
||||
module.exports = async function({ file: filePath, pretty }) {
|
||||
const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
|
||||
|
||||
const app = await strapi().load();
|
||||
const appDir = process.cwd();
|
||||
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
const count = await app.query('strapi::core-store').count();
|
||||
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
|
||||
const strapi = require('../index');
|
||||
|
||||
/**
|
||||
@ -12,7 +15,12 @@ const strapi = require('../index');
|
||||
module.exports = async function({ file: filePath, strategy = 'replace' }) {
|
||||
const input = filePath ? fs.readFileSync(filePath) : await readStdin(process.stdin);
|
||||
|
||||
const app = await strapi().load();
|
||||
const appDir = process.cwd();
|
||||
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
let dataToImport;
|
||||
try {
|
||||
|
||||
@ -1,14 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const REPL = require('repl');
|
||||
const path = require('path');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
|
||||
const strapi = require('../index');
|
||||
|
||||
/**
|
||||
* `$ strapi console`
|
||||
*/
|
||||
module.exports = () => {
|
||||
module.exports = async () => {
|
||||
// Now load up the Strapi framework for real.
|
||||
const app = strapi();
|
||||
const appDir = process.cwd();
|
||||
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
app.start().then(() => {
|
||||
const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
|
||||
|
||||
@ -1,13 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
const { toUpper } = require('lodash/fp');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
|
||||
const strapi = require('../../index');
|
||||
|
||||
module.exports = async function() {
|
||||
const app = await strapi().load();
|
||||
const appDir = process.cwd();
|
||||
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
||||
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
||||
|
||||
const app = await strapi({ appDir, distDir }).load();
|
||||
|
||||
const list = app.server.listRoutes();
|
||||
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const tsUtils = require('@strapi/typescript-utils')
|
||||
const strapi = require('../index');
|
||||
|
||||
/**
|
||||
* `$ strapi start`
|
||||
*/
|
||||
module.exports = distDir => strapi({ distDir }).start();
|
||||
module.exports = async specifiedDir => {
|
||||
const appDir = process.cwd();
|
||||
const isTSProject = await tsUtils.isUsingTypeScript(appDir)
|
||||
const distDir = isTSProject && !specifiedDir ? 'dist' : specifiedDir;
|
||||
|
||||
strapi({ distDir }).start()
|
||||
};
|
||||
|
||||
@ -15,6 +15,11 @@ const dbQuestions = require('./utils/db-questions');
|
||||
const createProject = require('./create-project');
|
||||
|
||||
module.exports = async scope => {
|
||||
if (!scope.useTypescript) {
|
||||
const language = await askAboutLanguages(scope);
|
||||
scope.useTypescript = language === 'Typescript';
|
||||
}
|
||||
|
||||
await trackUsage({ event: 'didChooseCustomDatabase', scope });
|
||||
|
||||
const configuration = await askDbInfosAndTest(scope).catch(error => {
|
||||
@ -157,3 +162,17 @@ async function installDatabaseTestingDep({ scope, configuration }) {
|
||||
|
||||
await execa(packageManager, cmd.concat(deps));
|
||||
}
|
||||
|
||||
async function askAboutLanguages() {
|
||||
const { language } = await inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'language',
|
||||
message: 'Choose your preferred language',
|
||||
choices: ['Javascript', 'Typescript'],
|
||||
default: 'Javascript',
|
||||
},
|
||||
]);
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const chalk = require('chalk');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
|
||||
const logInstructions = (pluginName, { language }) => {
|
||||
const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
|
||||
@ -38,10 +37,17 @@ module.exports = plop => {
|
||||
name: 'pluginName',
|
||||
message: 'Plugin name',
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'language',
|
||||
message: 'Choose your preferred language',
|
||||
choices: ['Javascript', 'Typescript'],
|
||||
default: 'Javascript',
|
||||
},
|
||||
],
|
||||
actions(answers) {
|
||||
const currentDir = process.cwd();
|
||||
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
||||
const isTypescript = answers.language === 'Typescript';
|
||||
const language = isTypescript ? 'ts' : 'js';
|
||||
|
||||
// TODO: Adds tsconfig & build command for TS plugins?
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user