UNPKG

mongoose-data-seed

Version:

Seed mongodb with data using mongoose models

1,259 lines (1,258 loc) 432 kB
[ { "__docId__": 1, "kind": "external", "name": "Infinity", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Infinity", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 2, "kind": "external", "name": "NaN", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~NaN", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 3, "kind": "external", "name": "undefined", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~undefined", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 4, "kind": "external", "name": "null", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~null", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 5, "kind": "external", "name": "Object", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Object", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 6, "kind": "external", "name": "object", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~object", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 7, "kind": "external", "name": "Function", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Function", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 8, "kind": "external", "name": "function", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~function", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 9, "kind": "external", "name": "Boolean", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Boolean", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 10, "kind": "external", "name": "boolean", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~boolean", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 11, "kind": "external", "name": "Symbol", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Symbol", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 12, "kind": "external", "name": "Error", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Error", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 13, "kind": "external", "name": "EvalError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~EvalError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 14, "kind": "external", "name": "InternalError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~InternalError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 15, "kind": "external", "name": "RangeError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~RangeError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 16, "kind": "external", "name": "ReferenceError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~ReferenceError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 17, "kind": "external", "name": "SyntaxError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~SyntaxError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 18, "kind": "external", "name": "TypeError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~TypeError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 19, "kind": "external", "name": "URIError", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~URIError", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 20, "kind": "external", "name": "Number", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Number", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 21, "kind": "external", "name": "number", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~number", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 22, "kind": "external", "name": "Date", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Date", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 23, "kind": "external", "name": "String", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~String", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 24, "kind": "external", "name": "string", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~string", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 25, "kind": "external", "name": "RegExp", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~RegExp", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 26, "kind": "external", "name": "Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 27, "kind": "external", "name": "Int8Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Int8Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 28, "kind": "external", "name": "Uint8Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Uint8Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 29, "kind": "external", "name": "Uint8ClampedArray", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Uint8ClampedArray", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 30, "kind": "external", "name": "Int16Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Int16Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 31, "kind": "external", "name": "Uint16Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Uint16Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 32, "kind": "external", "name": "Int32Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Int32Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 33, "kind": "external", "name": "Uint32Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Uint32Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 34, "kind": "external", "name": "Float32Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Float32Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 35, "kind": "external", "name": "Float64Array", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Float64Array", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 36, "kind": "external", "name": "Map", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Map", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 37, "kind": "external", "name": "Set", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Set", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 38, "kind": "external", "name": "WeakMap", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~WeakMap", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 39, "kind": "external", "name": "WeakSet", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~WeakSet", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 40, "kind": "external", "name": "ArrayBuffer", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~ArrayBuffer", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 41, "kind": "external", "name": "DataView", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~DataView", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 42, "kind": "external", "name": "JSON", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~JSON", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 43, "kind": "external", "name": "Promise", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Promise", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 44, "kind": "external", "name": "Generator", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Generator", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 45, "kind": "external", "name": "GeneratorFunction", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~GeneratorFunction", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 46, "kind": "external", "name": "Reflect", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Reflect", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 47, "kind": "external", "name": "Proxy", "externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy", "memberof": "src/.external-ecmascript.js", "static": true, "longname": "src/.external-ecmascript.js~Proxy", "access": "public", "description": "", "builtinExternal": true }, { "__docId__": 48, "kind": "file", "name": "src/bin/index.js", "content": "import '@babel/register';\nimport 'core-js/stable';\nimport 'regenerator-runtime/runtime';\n\nimport { runCommand, getCommandAndArgvFromCli } from '../lib/commands/helpers';\nimport { exit } from '../lib/utils/helpers';\n\n/**\n * Main entry point, run md-seed cli\n * @return {Promise}\n */\nconst run = async () => {\n try {\n // recive the command and the arguments input from the cli\n const { command, argv } = getCommandAndArgvFromCli();\n\n // run the cli command\n await runCommand(command, argv);\n\n exit();\n } catch (error) {\n exit(error);\n }\n};\n\nrun();\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/bin/index.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 49, "kind": "function", "name": "run", "memberof": "src/bin/index.js", "generator": false, "async": true, "static": true, "longname": "src/bin/index.js~run", "access": "public", "export": false, "importPath": "mongoose-data-seed/src/bin/index.js", "importStyle": null, "description": "Main entry point, run md-seed cli", "lineNumber": 12, "return": { "nullable": null, "types": [ "Promise" ], "spread": false, "description": "" }, "params": [], "ignore": true }, { "__docId__": 50, "kind": "file", "name": "src/lib/commands/constants.js", "content": "import generate from './generate';\nimport help from './help';\nimport init from './init';\nimport run from './run';\n\n/**\n * Available command names\n *\n * Map command key to command name\n * @type {Map<string, string>}\n */\nexport const commands = {\n GENERATE: 'generate',\n HELP: 'help',\n INIT: 'init',\n RUN: 'run',\n};\n\n/**\n * Available command aliases\n *\n * Map alias to command name\n * @type {Map<string, string>}\n */\nexport const aliases = {\n g: commands.GENERATE,\n h: commands.HELP,\n};\n\n/**\n * All available command names as list (includes aliases)\n * @type {string[]}\n */\nexport const availableCommandsList = [\n null, // no command should run help\n ...Object.values(commands),\n ...Object.keys(aliases),\n];\n\n/**\n * Commands map\n *\n * Map command name to the actuall command function\n * @type {Map<string, Function>}\n */\nexport const commandsMap = {\n [commands.GENERATE]: generate,\n [commands.HELP]: help,\n [commands.INIT]: init,\n [commands.RUN]: run,\n};\n\n/**\n * The fefault command name\n * @type {string}\n */\nexport const defaultCommand = commands.HELP;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/constants.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 51, "kind": "variable", "name": "commands", "memberof": "src/lib/commands/constants.js", "static": true, "longname": "src/lib/commands/constants.js~commands", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/constants.js", "importStyle": "{commands}", "description": "Available command names\n\nMap command key to command name", "lineNumber": 12, "type": { "nullable": null, "types": [ "Map<string, string>" ], "spread": false, "description": null } }, { "__docId__": 52, "kind": "variable", "name": "aliases", "memberof": "src/lib/commands/constants.js", "static": true, "longname": "src/lib/commands/constants.js~aliases", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/constants.js", "importStyle": "{aliases}", "description": "Available command aliases\n\nMap alias to command name", "lineNumber": 25, "type": { "nullable": null, "types": [ "Map<string, string>" ], "spread": false, "description": null } }, { "__docId__": 53, "kind": "variable", "name": "availableCommandsList", "memberof": "src/lib/commands/constants.js", "static": true, "longname": "src/lib/commands/constants.js~availableCommandsList", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/constants.js", "importStyle": "{availableCommandsList}", "description": "All available command names as list (includes aliases)", "lineNumber": 34, "type": { "nullable": null, "types": [ "string[]" ], "spread": false, "description": null } }, { "__docId__": 54, "kind": "variable", "name": "commandsMap", "memberof": "src/lib/commands/constants.js", "static": true, "longname": "src/lib/commands/constants.js~commandsMap", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/constants.js", "importStyle": "{commandsMap}", "description": "Commands map\n\nMap command name to the actuall command function", "lineNumber": 46, "type": { "nullable": null, "types": [ "Map<string, Function>" ], "spread": false, "description": null } }, { "__docId__": 55, "kind": "variable", "name": "defaultCommand", "memberof": "src/lib/commands/constants.js", "static": true, "longname": "src/lib/commands/constants.js~defaultCommand", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/constants.js", "importStyle": "{defaultCommand}", "description": "The fefault command name", "lineNumber": 57, "type": { "nullable": null, "types": [ "string" ], "spread": false, "description": null } }, { "__docId__": 56, "kind": "file", "name": "src/lib/commands/generate/generate-seeder.js", "content": "import chalk from 'chalk';\n\nimport { SeederGenerator } from '../../core';\nimport { validateUserConfig } from '../../utils/helpers';\nimport config from '../../config';\n\n/**\n * Generate a new seeder.\n * @param {string} name seeder name\n * @return {Promise}\n */\nconst generateSeeder = async name => {\n validateUserConfig();\n\n const { seederTemplate, userSeedersFolderPath } = config;\n\n const generator = new SeederGenerator({\n name,\n seederTemplate,\n userSeedersFolderPath,\n });\n\n const generatedSeederFile = await generator.generate();\n\n console.log(`${chalk.green('CREATED')} ${generatedSeederFile}`);\n};\n\nexport default generateSeeder;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/generate-seeder.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 57, "kind": "function", "name": "generateSeeder", "memberof": "src/lib/commands/generate/generate-seeder.js", "generator": false, "async": true, "static": true, "longname": "src/lib/commands/generate/generate-seeder.js~generateSeeder", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/generate-seeder.js", "importStyle": "generateSeeder", "description": "Generate a new seeder.", "lineNumber": 12, "params": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "name", "description": "seeder name" } ], "return": { "nullable": null, "types": [ "Promise" ], "spread": false, "description": "" } }, { "__docId__": 58, "kind": "file", "name": "src/lib/commands/generate/generate-seeder.test.js", "content": "import test from 'ava';\nimport sinon from 'sinon';\n\nimport { mockImports, resetImports } from '../../utils/test-helpers';\n\nimport generateSeeder, {\n __RewireAPI__ as moduleRewireAPI,\n} from './generate-seeder';\n\nconst helpData = {\n name: 'name',\n seederTemplate: 'template',\n userSeedersFolderPath: 'path/to/seeders',\n};\n\ntest.beforeEach('mock imports', t => {\n const { seederTemplate, userSeedersFolderPath } = helpData;\n\n const mocks = {\n validateUserConfig: sinon.stub(),\n SeederGenerator: sinon.stub(),\n config: { seederTemplate, userSeedersFolderPath },\n };\n\n mocks.SeederGenerator.prototype.generate = sinon\n .stub()\n .resolves('some.seeder.js');\n\n t.context = { mocks };\n\n mockImports({ moduleRewireAPI, mocks });\n\n sinon.stub(console, 'log');\n});\n\ntest.afterEach.always('unmock imports', t => {\n const imports = Object.keys(t.context.mocks);\n\n resetImports({ moduleRewireAPI, imports });\n\n console.log.restore();\n});\n\ntest('should generate a seeder', async t => {\n const { validateUserConfig, SeederGenerator } = t.context.mocks;\n await generateSeeder(helpData.name);\n\n t.true(validateUserConfig.called);\n t.true(SeederGenerator.calledWith(helpData));\n t.true(SeederGenerator.prototype.generate.called);\n t.true(console.log.called);\n});\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/generate-seeder.test.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 59, "kind": "variable", "name": "helpData", "memberof": "src/lib/commands/generate/generate-seeder.test.js", "static": true, "longname": "src/lib/commands/generate/generate-seeder.test.js~helpData", "access": "public", "export": false, "importPath": "mongoose-data-seed/src/lib/commands/generate/generate-seeder.test.js", "importStyle": null, "description": null, "lineNumber": 10, "undocument": true, "type": { "types": [ "{\"name\": string, \"seederTemplate\": string, \"userSeedersFolderPath\": string}" ] }, "ignore": true }, { "__docId__": 60, "kind": "file", "name": "src/lib/commands/generate/help.js", "content": "import usageGuide from './usage-guide';\n\n/**\n * Prints the generate command user-guide\n */\nconst help = () => console.log(usageGuide);\n\nexport default help;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/help.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 61, "kind": "function", "name": "help", "memberof": "src/lib/commands/generate/help.js", "generator": false, "async": false, "static": true, "longname": "src/lib/commands/generate/help.js~help", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/help.js", "importStyle": "help", "description": "Prints the generate command user-guide", "lineNumber": 6, "params": [], "return": null }, { "__docId__": 62, "kind": "file", "name": "src/lib/commands/generate/help.test.js", "content": "import test from 'ava';\nimport sinon from 'sinon';\n\nimport help, { __RewireAPI__ as moduleRewireAPI } from './help';\n\ntest('show show help', t => {\n const createStubs = ({ usageGuide }) => {\n moduleRewireAPI.__Rewire__('usageGuide', usageGuide);\n sinon.stub(console, 'log');\n };\n const restoreStubs = () => {\n moduleRewireAPI.__ResetDependency__('usageGuide');\n console.log.restore();\n };\n\n const usageGuide = 'some usage guide';\n\n createStubs({ usageGuide });\n\n help();\n\n t.true(console.log.calledWith(usageGuide));\n\n restoreStubs();\n});\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/help.test.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 63, "kind": "file", "name": "src/lib/commands/generate/index.js", "content": "import { getOptions } from './options';\nimport help from './help';\nimport generateSeeder from './generate-seeder';\n\n/**\n * mongoose-data-seed generate command\n * @param {stringp[]} argv cli arguments\n * @return {Promise}\n */\nexport default async argv => {\n const { seederName, helpWanted } = getOptions(argv);\n\n if (helpWanted) return help();\n\n await generateSeeder(seederName);\n};\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/index.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 64, "kind": "function", "name": "index", "memberof": "src/lib/commands/generate/index.js", "generator": false, "async": true, "static": true, "longname": "src/lib/commands/generate/index.js~index", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/index.js", "importStyle": "index", "description": "mongoose-data-seed generate command", "lineNumber": 10, "params": [ { "nullable": null, "types": [ "stringp[]" ], "spread": false, "optional": false, "name": "argv", "description": "cli arguments" } ], "return": { "nullable": null, "types": [ "Promise" ], "spread": false, "description": "" } }, { "__docId__": 65, "kind": "file", "name": "src/lib/commands/generate/index.test.js", "content": "import test from 'ava';\nimport sinon from 'sinon';\n\nimport generate, { __RewireAPI__ as moduleRewireAPI } from './index';\n\nconst helpData = { argv: 'some argv', seederName: 'some-seeder-name' };\n\ntest.beforeEach('create stubs', t => {\n const stubs = {\n getOptions: sinon.stub(),\n help: sinon.stub(),\n generateSeeder: sinon.stub(),\n };\n\n Object.keys(stubs).forEach(methodName =>\n moduleRewireAPI.__Rewire__(methodName, stubs[methodName])\n );\n\n t.context = { stubs };\n});\n\ntest.afterEach.always('restore stubs', t => {\n const { stubs } = t.context;\n\n Object.keys(stubs).forEach(methodName =>\n moduleRewireAPI.__ResetDependency__(methodName)\n );\n});\n\ntest.serial('should show help when asking for help', async t => {\n const { argv } = helpData;\n const { getOptions, help, generateSeeder } = t.context.stubs;\n\n getOptions.withArgs(argv).returns({ helpWanted: true });\n\n await generate(argv);\n\n t.true(getOptions.calledWith(argv));\n t.true(help.called);\n t.false(generateSeeder.called);\n});\n\ntest.serial('should generate seeder when asking with seeder-name', async t => {\n const { argv, seederName } = helpData;\n const { getOptions, help, generateSeeder } = t.context.stubs;\n\n getOptions.withArgs(argv).returns({ seederName });\n\n await generate(argv);\n\n t.true(getOptions.calledWith(argv));\n t.false(help.called);\n t.true(generateSeeder.calledWith(seederName));\n});\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/index.test.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 66, "kind": "variable", "name": "helpData", "memberof": "src/lib/commands/generate/index.test.js", "static": true, "longname": "src/lib/commands/generate/index.test.js~helpData", "access": "public", "export": false, "importPath": "mongoose-data-seed/src/lib/commands/generate/index.test.js", "importStyle": null, "description": null, "lineNumber": 6, "undocument": true, "type": { "types": [ "{\"argv\": string, \"seederName\": string}" ] }, "ignore": true }, { "__docId__": 67, "kind": "file", "name": "src/lib/commands/generate/option-definitions.js", "content": "/**\n * Generate command option defenitions\n * @type {Object[]}\n */\nconst optionDefinitions = [\n {\n name: 'name',\n alias: 'n',\n type: String,\n defaultOption: true,\n typeLabel: 'name',\n description: 'Seeder name to generate',\n },\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n defaultValue: false,\n description: 'Show usage guide',\n },\n];\n\nexport default optionDefinitions;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/option-definitions.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 68, "kind": "variable", "name": "optionDefinitions", "memberof": "src/lib/commands/generate/option-definitions.js", "static": true, "longname": "src/lib/commands/generate/option-definitions.js~optionDefinitions", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/option-definitions.js", "importStyle": "optionDefinitions", "description": "Generate command option defenitions", "lineNumber": 5, "type": { "nullable": null, "types": [ "Object[]" ], "spread": false, "description": null } }, { "__docId__": 69, "kind": "file", "name": "src/lib/commands/generate/options.js", "content": "import commandLineArgs from 'command-line-args';\nimport chalk from 'chalk';\nimport { trim } from 'lodash';\n\nimport help from './help';\nimport optionDefinitions from './option-definitions';\n\n/**\n * Get generate options from argv\n * @param {string[]} argv cli argv\n * @return {Object} run options\n * @property {string} seederName\n * @property {boolean} helpWanted\n */\nexport const getOptions = argv => {\n const { name: seederName, help: helpWanted } = commandLineArgs(\n optionDefinitions,\n { argv }\n );\n\n const options = { seederName, helpWanted };\n\n validateOptions(options);\n\n return options;\n};\n\n/**\n * Validate generate command options\n * @param {Object} [options={}] Options\n * @param {string} options.seederName seeder name to generate\n * @param {boolean} options.helpWanted help wanted?\n * @throws {Error} throw error when options are not valid.\n */\nexport const validateOptions = ({ seederName, helpWanted } = {}) => {\n if (\n !helpWanted &&\n (typeof seederName !== 'string' || trim(seederName).length < 3)\n ) {\n console.log(`${chalk.red('ERROR')} Please choose a seeder name`);\n console.log();\n help();\n\n throw new Error('exit');\n }\n};\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/options.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 70, "kind": "function", "name": "getOptions", "memberof": "src/lib/commands/generate/options.js", "generator": false, "async": false, "static": true, "longname": "src/lib/commands/generate/options.js~getOptions", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/options.js", "importStyle": "{getOptions}", "description": "Get generate options from argv", "lineNumber": 15, "params": [ { "nullable": null, "types": [ "string[]" ], "spread": false, "optional": false, "name": "argv", "description": "cli argv" } ], "properties": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "seederName", "description": "" }, { "nullable": null, "types": [ "boolean" ], "spread": false, "optional": false, "name": "helpWanted", "description": "" } ], "return": { "nullable": null, "types": [ "Object" ], "spread": false, "description": "run options" } }, { "__docId__": 71, "kind": "function", "name": "validateOptions", "memberof": "src/lib/commands/generate/options.js", "generator": false, "async": false, "static": true, "longname": "src/lib/commands/generate/options.js~validateOptions", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/options.js", "importStyle": "{validateOptions}", "description": "Validate generate command options", "lineNumber": 35, "params": [ { "nullable": null, "types": [ "Object" ], "spread": false, "optional": true, "defaultValue": "{}", "defaultRaw": {}, "name": "options", "description": "Options" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "options.seederName", "description": "seeder name to generate" }, { "nullable": null, "types": [ "boolean" ], "spread": false, "optional": false, "name": "options.helpWanted", "description": "help wanted?" } ], "throws": [ { "types": [ "Error" ], "description": "throw error when options are not valid." } ], "return": null }, { "__docId__": 72, "kind": "file", "name": "src/lib/commands/generate/options.test.js", "content": "import test from 'ava';\nimport sinon from 'sinon';\n\nimport {\n getOptions,\n validateOptions,\n __RewireAPI__ as moduleRewireAPI,\n} from './options';\n\nconst helpData = {\n argv: 'some argv',\n seederName: 'some-seeder-name',\n optionDefinitions: 'some option definitions',\n};\n\ntest('should get user options from the cli', t => {\n const createStubs = ({ commandLineArgs, optionDefinitions }) => {\n moduleRewireAPI.__Rewire__('commandLineArgs', commandLineArgs);\n moduleRewireAPI.__Rewire__('optionDefinitions', optionDefinitions);\n };\n const restoreStubs = () => {\n moduleRewireAPI.__ResetDependency__('commandLineArgs');\n moduleRewireAPI.__ResetDependency__('optionDefinitions');\n };\n\n const { argv, optionDefinitions, seederName } = helpData;\n\n const commandLineArgs = sinon\n .stub()\n .withArgs(optionDefinitions, { argv })\n .returns({ name: seederName, help: false });\n\n createStubs({ commandLineArgs, optionDefinitions });\n\n const expectedOptions = { seederName, helpWanted: false };\n const recivedOptions = getOptions(argv);\n\n t.true(commandLineArgs.calledWith(optionDefinitions, { argv }));\n t.deepEqual(recivedOptions, expectedOptions);\n\n restoreStubs();\n});\n\ntest('should validate given options', t => {\n const createStubs = ({ help }) => {\n moduleRewireAPI.__Rewire__('help', help);\n sinon.stub(console, 'log');\n };\n const restoreStubs = () => {\n moduleRewireAPI.__ResetDependency__('help');\n console.log.restore();\n };\n\n const help = sinon.stub();\n\n createStubs({ help });\n\n t.throws(() => validateOptions());\n t.true(help.called);\n t.true(console.log.called);\n t.throws(() => validateOptions({ helpWanted: false }));\n t.throws(() => validateOptions({ seederName: 'ab' }));\n t.notThrows(() => validateOptions({ seederName: 'abc' }));\n t.notThrows(() => validateOptions({ seederName: 'ab', helpWanted: true }));\n t.notThrows(() => validateOptions({ helpWanted: true }));\n\n restoreStubs();\n});\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/options.test.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 73, "kind": "variable", "name": "helpData", "memberof": "src/lib/commands/generate/options.test.js", "static": true, "longname": "src/lib/commands/generate/options.test.js~helpData", "access": "public", "export": false, "importPath": "mongoose-data-seed/src/lib/commands/generate/options.test.js", "importStyle": null, "description": null, "lineNumber": 10, "undocument": true, "type": { "types": [ "{\"argv\": string, \"seederName\": string, \"optionDefinitions\": string}" ] }, "ignore": true }, { "__docId__": 74, "kind": "file", "name": "src/lib/commands/generate/usage-guide.js", "content": "import generateUsageGuide from 'command-line-usage';\nimport optionDefinitions from './option-definitions';\n\n/**\n * @private\n */\nconst usageGuide = generateUsageGuide([\n {\n header: 'Generate Seeder',\n content: 'Generate new seeder file into the seeder folder.',\n },\n {\n header: 'Synopsis',\n content: [\n '$ md-seed generate {underline seeder-name}',\n '$ md-seed g {underline seeder-name}',\n '$ md-seed g {bold --help}',\n ],\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n]);\n\nexport default usageGuide;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/generate/usage-guide.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 75, "kind": "variable", "name": "usageGuide", "memberof": "src/lib/commands/generate/usage-guide.js", "static": true, "longname": "src/lib/commands/generate/usage-guide.js~usageGuide", "access": "private", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/generate/usage-guide.js", "importStyle": "usageGuide", "description": "", "lineNumber": 7, "ignore": true, "type": { "types": [ "*" ] } }, { "__docId__": 76, "kind": "file", "name": "src/lib/commands/help/help.test.js", "content": "import test from 'ava';\nimport sinon from 'sinon';\n\nimport usageGuide from './usage-guide';\nimport help from './index';\n\ntest('help command should print the usage guide', async t => {\n sinon.stub(console, 'log');\n\n await help();\n\n t.true(console.log.calledWith(usageGuide));\n\n console.log.restore();\n});\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/help/help.test.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 77, "kind": "file", "name": "src/lib/commands/help/index.js", "content": "import usageGuide from './usage-guide';\n\n/**\n * Prints the help\n */\nconst help = async () => {\n console.log(usageGuide);\n};\n\nexport default help;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/help/index.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 78, "kind": "function", "name": "help", "memberof": "src/lib/commands/help/index.js", "generator": false, "async": true, "static": true, "longname": "src/lib/commands/help/index.js~help", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/help/index.js", "importStyle": "help", "description": "Prints the help", "lineNumber": 6, "params": [], "return": null }, { "__docId__": 79, "kind": "file", "name": "src/lib/commands/help/usage-guide.js", "content": "import generateUsageGuide from 'command-line-usage';\n\n/**\n * Help command user guide\n * @type {string}\n */\nconst usageGuide = generateUsageGuide([\n {\n header: 'Mongoose Data Seeder',\n content: 'Seed data into the database',\n },\n {\n header: 'Synopsis',\n content: ['$ md-seed <command> <options>'],\n },\n {\n header: 'Command List',\n content: [\n {\n command: 'init',\n description: 'Install mongoose-data-seed into your project.',\n },\n {\n command: 'g, generate',\n description: 'Generate new seeder file into the seeder folder.',\n },\n {\n command: 'run',\n description: 'Run seeders.',\n },\n {\n command: 'h, help',\n description: 'Show help',\n },\n ],\n },\n]);\n\nexport default usageGuide;\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/help/usage-guide.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 80, "kind": "variable", "name": "usageGuide", "memberof": "src/lib/commands/help/usage-guide.js", "static": true, "longname": "src/lib/commands/help/usage-guide.js~usageGuide", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/help/usage-guide.js", "importStyle": "usageGuide", "description": "Help command user guide", "lineNumber": 7, "type": { "nullable": null, "types": [ "string" ], "spread": false, "description": null } }, { "__docId__": 81, "kind": "file", "name": "src/lib/commands/helpers.js", "content": "import commandLineCommands from 'command-line-commands';\nimport {\n commandsMap,\n aliases,\n defaultCommand,\n availableCommandsList,\n} from './constants';\n\n/**\n * Whether a given command is an alias\n * @param {string} command\n * @return {Boolean}\n */\nexport const isAlias = command => Object.keys(aliases).includes(command);\n\n/**\n * Get the command name of a given alias\n * @param {string} alias\n * @return {string}\n */\nexport const aliasToCommand = alias => aliases[alias];\n\n/**\n * Get the function of a given command\n * @param {string} command command name\n * @return {Function} command function\n */\nexport const commandToFunction = command => {\n command = command || defaultCommand;\n\n if (isAlias(command)) {\n command = aliasToCommand(command);\n }\n\n return commandsMap[command];\n};\n\n/**\n * Get the command and the arguments from the cli\n * @return {Object}\n * @property {string} command command name\n * @property {string[]} argv command arguments\n */\nexport const getCommandAndArgvFromCli = () => {\n const { command, argv } = commandLineCommands(availableCommandsList);\n\n return { command, argv };\n};\n\n/**\n * Run command\n * @param {string} command command name\n * @param {string} argv command arguments\n */\nexport const runCommand = (command, argv) => {\n const commandFunction = commandToFunction(command);\n\n return commandFunction(argv);\n};\n", "static": true, "longname": "/home/travis/build/sharvit/mongoose-data-seed/src/lib/commands/helpers.js", "access": "public", "description": null, "lineNumber": 1 }, { "__docId__": 82, "kind": "function", "name": "isAlias", "memberof": "src/lib/commands/helpers.js", "generator": false, "async": false, "static": true, "longname": "src/lib/commands/helpers.js~isAlias", "access": "public", "export": true, "importPath": "mongoose-data-seed/src/lib/commands/helpers.js", "importStyle": "{isAlias}", "description": "Whether a given command is an alias", "lineNumber": 14, "params": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "command", "description": "" } ], "return": { "nullable": null,