mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
236d07c90a
Added CLI commands for REPL and timetravel functionality - Added TimeTravel command for updating test data with a date offset - Added REPL command for access to models and knex in development - Added pattern for creating new CLI commands, including - User input - Output - Validation of `NODE_ENV` - TimeTravel command is in the main Ghost repo because it requires the schema
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
const Command = require('./command');
|
|
const chalk = require('chalk');
|
|
|
|
module.exports = class REPL extends Command {
|
|
setup() {
|
|
this.help('Launches a REPL environment with access to a configured db instance and models');
|
|
// this is only here to demo how to set a default value for an arg :)
|
|
this.argument('--color', {type: 'string', defaultValue: 'yellow', hidden: true});
|
|
}
|
|
|
|
initializeContext(context) {
|
|
const models = require('../server/models');
|
|
const knex = require('../server/data/db/connection');
|
|
|
|
models.init();
|
|
|
|
context.models = models;
|
|
context.m = models;
|
|
context.knex = knex;
|
|
context.k = knex;
|
|
}
|
|
|
|
async handle(argv = {}) {
|
|
this.debug(chalk[argv.color]('== Ghost development REPL =='));
|
|
this.info(`a knex database instance is available as ${chalk.magenta('knex')}`);
|
|
this.info(`bookshelf models are available as ${chalk.magenta('models')}`);
|
|
const repl = require('repl');
|
|
const cli = repl.start('> ');
|
|
this.initializeContext(cli.context);
|
|
cli.on('reset', this.initializeContext);
|
|
}
|
|
};
|