Chore(medusa,utils,types,inventory,stock-location): remove core dependency modules (#3531)

This commit is contained in:
Carlos R. L. Rodrigues
2023-03-23 08:07:32 -03:00
committed by GitHub
parent bfef22b33e
commit 4e9d257d3b
159 changed files with 1769 additions and 693 deletions

View File

@@ -13,12 +13,14 @@ const { whoami } = require("./commands/whoami")
const { login } = require("./commands/login")
const { link } = require("./commands/link")
const handlerP = fn => (...args) => {
Promise.resolve(fn(...args)).then(
() => process.exit(0),
err => console.log(err)
)
}
const handlerP =
(fn) =>
(...args) => {
Promise.resolve(fn(...args)).then(
() => process.exit(0),
(err) => console.log(err)
)
}
function buildLocalCommands(cli, isLocalProject) {
const defaultHost = `localhost`
@@ -54,12 +56,17 @@ function buildLocalCommands(cli, isLocalProject) {
)
return require(cmdPath).default
} catch (err) {
if (process.env.NODE_ENV !== "production") {
console.log("--------------- ERROR ---------------------")
console.log(err)
console.log("-------------------------------------------")
}
cli.showHelp()
}
}
function getCommandHandler(command, handler) {
return argv => {
return (argv) => {
const localCmd = resolveLocalCommand(command)
const args = { ...argv, ...projectInfo, useYarn }
@@ -70,7 +77,7 @@ function buildLocalCommands(cli, isLocalProject) {
cli
.command({
command: `new [root] [starter]`,
builder: _ =>
builder: (_) =>
_.option(`seed`, {
type: `boolean`,
describe: `If flag is set the command will attempt to seed the database after setup.`,
@@ -123,7 +130,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `telemetry`,
describe: `Enable or disable collection of anonymous usage data.`,
builder: yargs =>
builder: (yargs) =>
yargs
.option(`enable`, {
type: `boolean`,
@@ -145,7 +152,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `seed`,
desc: `Migrates and populates the database with the provided file.`,
builder: _ =>
builder: (_) =>
_.option(`f`, {
alias: `seed-file`,
type: `string`,
@@ -188,7 +195,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `link`,
desc: `Creates your Medusa Cloud user in your local database for local testing.`,
builder: _ =>
builder: (_) =>
_.option(`su`, {
alias: `skip-local-user`,
type: `boolean`,
@@ -199,7 +206,7 @@ function buildLocalCommands(cli, isLocalProject) {
default: false,
describe: `If set medusa develop will be run after successful linking.`,
}),
handler: handlerP(argv => {
handler: handlerP((argv) => {
if (!isLocalProject) {
console.log("must be a local project")
cli.showHelp()
@@ -218,7 +225,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `develop`,
desc: `Start development server. Watches file and rebuilds when something changes`,
builder: _ =>
builder: (_) =>
_.option(`H`, {
alias: `host`,
type: `string`,
@@ -239,14 +246,14 @@ function buildLocalCommands(cli, isLocalProject) {
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
// kills it so this is fine.
return new Promise(resolve => {})
return new Promise((resolve) => {})
})
),
})
.command({
command: `start`,
desc: `Start development server.`,
builder: _ =>
builder: (_) =>
_.option(`H`, {
alias: `host`,
type: `string`,
@@ -267,14 +274,14 @@ function buildLocalCommands(cli, isLocalProject) {
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
// kills it so this is fine.
return new Promise(resolve => {})
return new Promise((resolve) => {})
})
),
})
.command({
command: `user`,
desc: `Create a user`,
builder: _ =>
builder: (_) =>
_.option(`e`, {
alias: `email`,
type: `string`,
@@ -296,7 +303,7 @@ function buildLocalCommands(cli, isLocalProject) {
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
// kills it so this is fine.
return new Promise(resolve => {})
return new Promise((resolve) => {})
})
),
})
@@ -335,7 +342,7 @@ Medusa version: ${medusaVersion}
}
}
module.exports = argv => {
module.exports = (argv) => {
const cli = yargs()
const isLocalProject = isLocalMedusaProject()
@@ -381,13 +388,21 @@ module.exports = argv => {
.demandCommand(1, `Pass --help to see all available commands and options.`)
.strict()
.fail((msg, err, yargs) => {
const availableCommands = yargs.getCommands().map(commandDescription => {
const [command] = commandDescription
return command.split(` `)[0]
})
const availableCommands = yargs
.getCommands()
.map((commandDescription) => {
const [command] = commandDescription
return command.split(` `)[0]
})
const arg = argv.slice(2)[0]
const suggestion = arg ? didYouMean(arg, availableCommands) : ``
if (process.env.NODE_ENV !== "production") {
console.log("--------------- ERROR ---------------------")
console.log(err)
console.log("-------------------------------------------")
}
cli.showHelp()
reporter.info(suggestion)
reporter.info(msg)