task: function () { var config = null; helpers.init.createSeedersFolder(); try { config = helpers.config.readConfig(); } catch (e) { console.log(e.message); process.exit(1); } fs.writeFileSync( helpers.path.getSeederPath(args.name), helpers.template.render('seeders/skeleton.js', {}, { beautify: false }) ); helpers.view.log( 'New seed was created at', clc.blueBright(helpers.path.getSeederPath(args.name)), '.' ); }
;(function(options) { if (options) { var margin = Math.max.apply(null, Object.keys(options).map(function(o) { return o.length })) helpers.view.log() helpers.view.log(clc.bold("OPTIONS")) Object.keys(options).forEach(function(option) { var args = [" ", option] args.push(new Array(margin - option.length + 1).join(" ")) args.push(options[option]) helpers.view.log.apply(helpers.view, args); }) } })(_.extend(self.getGlobalOptions(), task.descriptions.options))
commands.forEach(function(command) { var s = [ "sequelize", command + Array(commandMargin - command.length + 1).join(" "), "--", task.descriptions.short ].join(" ") helpers.view.log(" " + s) })
createModelsIndexFile: function(force) { var modelsPath = helpers.path.getModelsPath(); var indexPath = path.resolve( modelsPath, helpers.path.addFileExtension("index") ); if (!fs.existsSync(modelsPath)) { helpers.view.log("Models folder not available."); } else if (fs.existsSync(indexPath) && !force) { this.notifyAboutExistingFile(indexPath); } else { var relativeConfigPath = path.relative( helpers.path.getModelsPath(), helpers.config.getConfigFile() ); helpers.asset.write( indexPath, helpers.template.render("models/index.js", { configFile: "__dirname + '/" + relativeConfigPath + "'" }, { beautify: false }) ); } }
function () { helpers.view.log(clc.bold('COMMANDS')); var commands = [ taskName ].concat(task.aliases || []); var commandMargin = Math.max.apply(null, commands.map(function (c) { return c.length; })); commands.forEach(function (command) { var s = [ 'sequelize', command + (new Array(commandMargin - command.length + 1).join(' ')), '--', task.descriptions.short ].join(' '); helpers.view.log(' ' + s); }); helpers.view.log(); helpers.view.log(clc.bold('DESCRIPTION')); (task.descriptions.long || [task.descriptions.short]).forEach(function (line) { helpers.view.log(' ' + line); }); (function (options) { if (options) { var margin = Math.max.apply(null, Object.keys(options).map(function (o) { return o.length; })); helpers.view.log(); helpers.view.log(clc.bold('OPTIONS')); Object.keys(options).forEach(function (option) { var args = [' ', option]; args.push(new Array(margin - option.length + 1).join(' ')); args.push(options[option]); helpers.view.log.apply(helpers.view, args); }); } })(_.assign(self.getGlobalOptions(), task.descriptions.options)); helpers.view.log(); }
commands.forEach(function (command) { var s = [ 'sequelize', command + (new Array(commandMargin - command.length + 1).join(' ')), '--', task.descriptions.short ].join(' '); helpers.view.log(' ' + s); });
function ensureNameFlag () { if (!args.name) { helpers.view.error( 'Unspecified flag ' + clc.blueBright('"name"') + '. Check the manual for further details.' ); process.exit(1); } },
fns: function(index){ if (index === undefined) { return this._fn.length; } var fn = this._fn[index]; if ( ! fn) { return 'unceched fn['+index+']'; } if (arguments.length === 0 && typeof console !== 'undefined') { if (fn.source) { console.log('\n [template source] \n\n' + add_line_num(fn.source) + '\n '); } console.log('\n [compiled code] \n\n' + (fn.hasOwnProperty('compile_err') ? 'compile error' : fn.toString().replace(/([;{}])/g, '$1\n')) + '\n '); } return fn; },
function ensureModelsFolder () { if (!fs.existsSync(helpers.path.getModelsPath())) { helpers.view.error( 'Unable to find models path (' + helpers.path.getModelsPath() + '). Did you run ' + clc.blueBright('sequelize init') + '?' ); process.exit(1); } },
function ensureMigrationsFolder () { if (!helpers.path.existsSync(helpers.path.getPath('migration'))) { helpers.view.error( 'Unable to find migrations path (' + helpers.path.getPath('migration') + '). Did you run ' + clc.blueBright('sequelize init') + '?' ); process.exit(1); } },
(function (options) { if (options) { var margin = Math.max.apply(null, Object.keys(options).map(function (o) { return o.length; })); helpers.view.log(); helpers.view.log(clc.bold('OPTIONS')); Object.keys(options).forEach(function (option) { var args = [' ', option]; args.push(new Array(margin - option.length + 1).join(' ')); args.push(options[option]); helpers.view.log.apply(helpers.view, args); }); } })(_.assign(self.getGlobalOptions(), task.descriptions.options));
function ensureAttributesFlag () { if (!args.attributes) { helpers.view.error( 'Unspecified flag ' + clc.blueBright('"attributes"') + '. Check the manual for further details.' ); process.exit(1); } },
function() { helpers.view.log(clc.bold("COMMANDS")) var commands = [ taskName ].concat(task.aliases || []) , commandMargin = Math.max.apply(null, commands.map(function(c) { return c.length })) commands.forEach(function(command) { var s = [ "sequelize", command + Array(commandMargin - command.length + 1).join(" "), "--", task.descriptions.short ].join(" ") helpers.view.log(" " + s) }) helpers.view.log() helpers.view.log(clc.bold("DESCRIPTION")) ;(task.descriptions.long || [task.descriptions.short]).forEach(function(line) { helpers.view.log(" " + line) }) ;(function(options) { if (options) { var margin = Math.max.apply(null, Object.keys(options).map(function(o) { return o.length })) helpers.view.log() helpers.view.log(clc.bold("OPTIONS")) Object.keys(options).forEach(function(option) { var args = [" ", option] args.push(new Array(margin - option.length + 1).join(" ")) args.push(options[option]) helpers.view.log.apply(helpers.view, args); }) } })(_.extend(self.getGlobalOptions(), task.descriptions.options)) helpers.view.log() }
function ensureSeeds () { if ( !args.seed ) { helpers.view.error( 'Unspecified flag ' + clc.blueBright('"seed"') + '. Check the manual for further details.' ); process.exit(1); } if ( !_.isArray(args.seed) ) { args.seed = [args.seed]; } args.seed.forEach(function (file, ind) { args.seed[ind] = path.basename(file); }); }
(task.descriptions.long || [task.descriptions.short]).forEach(function (line) { helpers.view.log(' ' + line); });
_.each(items, function(value, key) { result.push([ clc.blueBright(helpers.view.pad(key, items)), value ].join(" ")) })
function ensureMigrationsFolder() { if (!fs.existsSync(helpers.path.getMigrationsPath())) { helpers.view.error("Unable to find migrations path (" + helpers.path.getMigrationsPath() + "). Did you run " + clc.blueBright("sequelize init") + "?") process.exit(1) } },
_.forEach(items, function (value, key) { result.push([ clc.blueBright(helpers.view.pad(key, items)), value ].join(' ')); });
notifyAboutExistingFile: function (file) { helpers.view.error( 'The file ' + clc.blueBright(file) + ' already exists. ' + 'Run "sequelize model:create --force" to overwrite it.' ); },
function logMigrator (s) { if (s.indexOf('Executing') !== 0) { helpers.view.log(s); } }
notifyAboutExistingFile: function(file) { helpers.view.log( "The file " + clc.blueBright(file) + " already exists. Run " + "'sequelize init --force'to overwrite it." ); },