mirror of
https://github.com/strapi/strapi.git
synced 2025-07-28 11:30:21 +00:00
fix strapi commands so they work in a Typescript project
This commit is contained in:
parent
90293b8469
commit
37971b2394
@ -3,6 +3,8 @@
|
||||
const { yup } = require('@strapi/utils');
|
||||
const _ = require('lodash');
|
||||
const inquirer = require('inquirer');
|
||||
const tsUtils = require('@strapi/typescript-utils')
|
||||
const path = require('path')
|
||||
const strapi = require('../index');
|
||||
|
||||
const emailValidator = yup
|
||||
@ -60,7 +62,7 @@ const promptQuestions = [
|
||||
* @param {string} cmdOptions.firstname - new admin's first name
|
||||
* @param {string} [cmdOptions.lastname] - new admin's last name
|
||||
*/
|
||||
module.exports = async function(cmdOptions = {}) {
|
||||
module.exports = async function (cmdOptions = {}) {
|
||||
let { email, password, firstname, lastname } = cmdOptions;
|
||||
|
||||
if (
|
||||
@ -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 });
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
const _ = require('lodash');
|
||||
const inquirer = require('inquirer');
|
||||
const tsUtils = require('@strapi/typescript-utils')
|
||||
const path = require('path')
|
||||
const strapi = require('../index');
|
||||
|
||||
const promptQuestions = [
|
||||
@ -20,7 +22,7 @@ const promptQuestions = [
|
||||
* @param {string} cmdOptions.email - user's email
|
||||
* @param {string} cmdOptions.password - user's new password
|
||||
*/
|
||||
module.exports = async function(cmdOptions = {}) {
|
||||
module.exports = async function (cmdOptions = {}) {
|
||||
const { email, password } = cmdOptions;
|
||||
|
||||
if (_.isEmpty(email) && _.isEmpty(password) && process.stdin.isTTY) {
|
||||
@ -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,19 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const REPL = require('repl');
|
||||
const tsUtils = require('@strapi/typescript-utils')
|
||||
const path = require('path')
|
||||
|
||||
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
|
||||
|
||||
repl.on('exit', function(err) {
|
||||
repl.on('exit', function (err) {
|
||||
if (err) {
|
||||
app.log.error(err);
|
||||
process.exit(1);
|
||||
|
@ -3,11 +3,18 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
const { toUpper } = require('lodash/fp');
|
||||
const tsUtils = require('@strapi/typescript-utils')
|
||||
const path = require('path')
|
||||
|
||||
const strapi = require('../../index');
|
||||
|
||||
module.exports = async function() {
|
||||
const app = await strapi().load();
|
||||
module.exports = async function () {
|
||||
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();
|
||||
|
||||
|
@ -15,7 +15,6 @@ const dbQuestions = require('./utils/db-questions');
|
||||
const createProject = require('./create-project');
|
||||
|
||||
module.exports = async scope => {
|
||||
await trackUsage({ event: 'didChooseCustomDatabase', scope });
|
||||
|
||||
if (!scope.useTypescript) {
|
||||
// check how to handle track usage here
|
||||
@ -23,6 +22,8 @@ module.exports = async scope => {
|
||||
scope.useTypescript = language === "Typescript";
|
||||
}
|
||||
|
||||
await trackUsage({ event: 'didChooseCustomDatabase', scope });
|
||||
|
||||
const configuration = await askDbInfosAndTest(scope).catch(error => {
|
||||
return trackUsage({ event: 'didNotConnectDatabase', scope, error }).then(() => {
|
||||
throw error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user