diff --git a/packages/core/strapi/lib/commands/admin-create.js b/packages/core/strapi/lib/commands/admin-create.js index 304d3c9a4f..9cb1ebe9e1 100644 --- a/packages/core/strapi/lib/commands/admin-create.js +++ b/packages/core/strapi/lib/commands/admin-create.js @@ -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 }); diff --git a/packages/core/strapi/lib/commands/admin-reset.js b/packages/core/strapi/lib/commands/admin-reset.js index 0446c6f4f1..1a25b3eb10 100644 --- a/packages/core/strapi/lib/commands/admin-reset.js +++ b/packages/core/strapi/lib/commands/admin-reset.js @@ -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); diff --git a/packages/core/strapi/lib/commands/console.js b/packages/core/strapi/lib/commands/console.js index 0c24521318..7402158935 100644 --- a/packages/core/strapi/lib/commands/console.js +++ b/packages/core/strapi/lib/commands/console.js @@ -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); diff --git a/packages/core/strapi/lib/commands/routes/list.js b/packages/core/strapi/lib/commands/routes/list.js index 83e51ece2c..729791dfb0 100644 --- a/packages/core/strapi/lib/commands/routes/list.js +++ b/packages/core/strapi/lib/commands/routes/list.js @@ -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(); diff --git a/packages/generators/app/lib/create-customized-project.js b/packages/generators/app/lib/create-customized-project.js index 4c990d2394..4da864aa96 100644 --- a/packages/generators/app/lib/create-customized-project.js +++ b/packages/generators/app/lib/create-customized-project.js @@ -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;