Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit 8e6194c

Browse files
committed
feat: added debug mode
1 parent b819160 commit 8e6194c

8 files changed

Lines changed: 37 additions & 31 deletions

File tree

packages/@simpli/cli/bin/simpli.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ program
2323
.description('create a new simpli project')
2424
.option('-d, --default', 'skip prompts and use default preset')
2525
.option('-f, --force', 'overwrite target directory if it exists')
26+
.option('-D, --debug', 'run in debug mode')
2627
.action((name, cmd) => {
2728
require('../lib/cmd/newProject')(name, cleanArgs(cmd))
2829
})
2930

3031
program
3132
.command('new:seed')
3233
.description('create test data from a backend project and store it into data.sql')
33-
.action(() => {
34-
require('../lib/cmd/newSeed')()
34+
.option('-D, --debug', 'run in debug mode')
35+
.action((cmd) => {
36+
require('../lib/cmd/newSeed')(cleanArgs(cmd))
3537
})
3638

3739
program
@@ -44,8 +46,9 @@ program
4446
program
4547
.command('scaffold:sync')
4648
.description('synchronize the models of the current frontend project based on its web server swagger')
47-
.action(() => {
48-
require('../lib/cmd/scaffoldSync')()
49+
.option('-D, --debug', 'run in debug mode')
50+
.action((cmd) => {
51+
require('../lib/cmd/scaffoldSync')(cleanArgs(cmd))
4952
})
5053

5154
program
@@ -58,8 +61,9 @@ program
5861
program
5962
.command('server:sync')
6063
.description('synchronize the tables of the current backend project based on its MySQL database')
61-
.action(() => {
62-
require('../lib/cmd/serverSync')()
64+
.option('-D, --debug', 'run in debug mode')
65+
.action((cmd) => {
66+
require('../lib/cmd/serverSync')(cleanArgs(cmd))
6367
})
6468

6569
program

packages/@simpli/cli/lib/cmd/newProject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ async function createScaffold (name, targetDir, options) {
9898
} else return
9999
} else await scaffold.swaggerDefaultSetup()
100100

101-
await scaffold.create()
101+
await scaffold.create(options)
102102
}
103103

104104
async function createServer (name, targetDir, options) {
105105
const server = new Server(name, targetDir, [])
106106
await server.databaseSetup()
107-
await server.create()
107+
await server.create(options)
108108
}
109109

110110
module.exports = (...args) => {

packages/@simpli/cli/lib/cmd/newSeed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { error, stopSpinner } = require('@vue/cli-shared-utils')
55
const Server = require('../server/Server')
66
const contextConnection = require('../server/util/contextConnection')
77

8-
async function newSeed () {
8+
async function newSeed (options) {
99
const targetDir = path.resolve('./')
1010
const pom = path.resolve('./pom.xml')
1111

@@ -18,7 +18,7 @@ async function newSeed () {
1818

1919
await contextConnection(async (connection) => {
2020
const server = new Server(null, targetDir, [])
21-
await server.newSeed(connection)
21+
await server.newSeed(connection, options)
2222
})
2323
}
2424

packages/@simpli/cli/lib/cmd/scaffoldInspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const inquirer = require('inquirer')
66
const { error } = require('@vue/cli-shared-utils')
77
const clearConsole = require('../util/clearConsole')
88

9-
module.exports = async (inspectPaths = []) => {
9+
module.exports = async (inspectPaths = [], options) => {
1010
require('dotenv').config()
1111
const get = require('get-value')
1212
const stringify = require('javascript-stringify')

packages/@simpli/cli/lib/cmd/scaffoldSync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { error, stopSpinner } = require('@vue/cli-shared-utils')
66
const Scaffold = require('../scaffold/Scaffold')
77
const execa = require('execa')
88

9-
async function sync () {
9+
async function sync (options) {
1010
require('dotenv').config()
1111

1212
const appName = process.env.VUE_APP_NAME
@@ -63,7 +63,7 @@ async function sync () {
6363

6464
await clearConsole()
6565
const scaffold = new Scaffold(appName, targetDir, [])
66-
await scaffold.syncModels(swaggerUrl)
66+
await scaffold.syncModels(swaggerUrl, options)
6767
}
6868

6969
module.exports = (...args) => {

packages/@simpli/cli/lib/cmd/serverSync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { error, stopSpinner } = require('@vue/cli-shared-utils')
77
const Server = require('../server/Server')
88
const contextConnection = require('../server/util/contextConnection')
99

10-
async function sync () {
10+
async function sync (options) {
1111
const targetDir = path.resolve('./')
1212
const pom = path.resolve('./pom.xml')
1313

@@ -36,7 +36,7 @@ async function sync () {
3636

3737
await contextConnection(async (connection) => {
3838
const server = new Server(null, targetDir, [])
39-
await server.syncModels(connection)
39+
await server.syncModels(connection, options)
4040
})
4141
}
4242

packages/@simpli/cli/lib/scaffold/Scaffold.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module.exports = class Scaffold {
136136
this.scaffoldSetup.defaultCurrency = 'USD'
137137
}
138138

139-
async create () {
139+
async create (options = {}) {
140140
const { name, context, createCompleteCbs, scaffoldSetup } = this
141141

142142
const run = (command, args) => {
@@ -191,7 +191,7 @@ module.exports = class Scaffold {
191191
// run generator
192192
log()
193193
log(`🚀 Invoking generators...`)
194-
const plugins = this.resolvePlugins(preset.plugins)
194+
const plugins = this.resolvePlugins(preset.plugins, options.debug)
195195
const generator = new Generator(context, {
196196
pkg,
197197
plugins,
@@ -233,7 +233,7 @@ module.exports = class Scaffold {
233233
generator.printExitLogs()
234234
}
235235

236-
async syncModels (swaggerUrl) {
236+
async syncModels (swaggerUrl, options = {}) {
237237
await Swagger.requestSwagger(this.scaffoldSetup, swaggerUrl)
238238
const { syncModels } = await Swagger.requestSync(this.scaffoldSetup)
239239
await Swagger.confirm()
@@ -251,7 +251,7 @@ module.exports = class Scaffold {
251251

252252
log()
253253
log(`⚙️ Synchronizing models...`)
254-
const plugins = this.resolvePlugins(preset.plugins)
254+
const plugins = this.resolvePlugins(preset.plugins, options.debug)
255255
const generator = new Generator(context, {
256256
pkg: { _ignore: true },
257257
plugins,
@@ -265,12 +265,13 @@ module.exports = class Scaffold {
265265
log(`👉 Run ${chalk.cyan('git add . && git stash')} to revert the changes safely.\n\n`)
266266
}
267267

268-
resolvePlugins (rawPlugins) {
268+
resolvePlugins (rawPlugins, debug = false) {
269269
// ensure cli-service is invoked first
270270
rawPlugins = sortObject(rawPlugins, ['@simpli/cli-scaffold'])
271271
return Object.keys(rawPlugins).map(id => {
272-
const module = resolve.sync(`${id}/generator`, { basedir: this.context })
273-
// const module = resolve.sync(`../../../cli-scaffold/generator`)
272+
const module = !debug
273+
? resolve.sync(`${id}/generator`, { basedir: this.context })
274+
: resolve.sync(`../../../cli-scaffold/generator`)
274275
return {
275276
id,
276277
apply: require(module),

packages/@simpli/cli/lib/server/Server.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = class Server {
8585
this.serverSetup.seedSamples = seedSamples
8686
}
8787

88-
async create () {
88+
async create (options = {}) {
8989
const { name, context, createCompleteCbs, serverSetup } = this
9090

9191
const run = (command, args) => {
@@ -140,7 +140,7 @@ module.exports = class Server {
140140
// run generator
141141
log()
142142
log(`🚀 Invoking generators...`)
143-
const plugins = this.resolvePlugins(preset.plugins)
143+
const plugins = this.resolvePlugins(preset.plugins, options.debug)
144144
const generator = new Generator(context, {
145145
pkg,
146146
plugins,
@@ -175,7 +175,7 @@ module.exports = class Server {
175175
generator.printExitLogs()
176176
}
177177

178-
async syncModels (defaultConnection) {
178+
async syncModels (defaultConnection, options = {}) {
179179
const run = (command, args) => {
180180
if (!args) { [command, ...args] = command.split(/\s+/) }
181181
return execa(command, args, { cwd: context })
@@ -227,7 +227,7 @@ module.exports = class Server {
227227

228228
log()
229229
log(`⚙️ Synchronizing tables...`)
230-
const plugins = this.resolvePlugins(preset.plugins)
230+
const plugins = this.resolvePlugins(preset.plugins, options.debug)
231231
const generator = new Generator(context, {
232232
pkg: { _ignore: true },
233233
plugins,
@@ -245,7 +245,7 @@ module.exports = class Server {
245245
log(`👉 Run ${chalk.cyan('git add . && git stash')} to revert the changes safely.\n\n`)
246246
}
247247

248-
async newSeed (defaultConnection) {
248+
async newSeed (defaultConnection, options = {}) {
249249
const run = (command, args) => {
250250
if (!args) { [command, ...args] = command.split(/\s+/) }
251251
return execa(command, args, { cwd: context })
@@ -313,7 +313,7 @@ module.exports = class Server {
313313

314314
log()
315315
log(`⚙️ Creating data.sql...`)
316-
const plugins = this.resolvePlugins(preset.plugins)
316+
const plugins = this.resolvePlugins(preset.plugins, options.debug)
317317
const generator = new Generator(context, {
318318
pkg: { _ignore: true },
319319
plugins,
@@ -329,12 +329,13 @@ module.exports = class Server {
329329
log(`🎉 Successfully created data.sql`)
330330
}
331331

332-
resolvePlugins (rawPlugins) {
332+
resolvePlugins (rawPlugins, debug = false) {
333333
// ensure cli-service is invoked first
334334
rawPlugins = sortObject(rawPlugins, ['@simpli/cli-server'])
335335
return Object.keys(rawPlugins).map(id => {
336-
const module = resolve.sync(`${id}/generator`, { basedir: this.context })
337-
// const module = resolve.sync(`../../../cli-server/generator`)
336+
const module = !debug
337+
? resolve.sync(`${id}/generator`, { basedir: this.context })
338+
: resolve.sync(`../../../cli-server/generator`)
338339
return {
339340
id,
340341
apply: require(module),

0 commit comments

Comments
 (0)