src/index.js
function (opts) {
    opts = opts || {}
    opts = defaults(opts, {
      nodeModulesDir: path.resolve(process.cwd(), 'node_modules'),
      package: rpkg.gen(opts.package)
    })
    fs.mkdirpSync(path.resolve(opts.nodeModulesDir, opts.package.name))
    fs.writeFileSync(
      path.resolve(opts.nodeModulesDir, opts.package.name, 'package.json'),
      JSON.stringify(opts.package, null, 2)
    )
    if (opts.targetPackage) {
      var key = opts.isDev ? 'devDependencies' : 'dependencies'
      var targetPackage = JSON.parse(fs.readFileSync(opts.targetPackage))
      targetPackage[key] = targetPackage[key] || {}
      targetPackage[key][opts.package.name] = opts.package.version
      fs.writeFileSync(opts.targetPackage, JSON.stringify(targetPackage, null, 2))
    }
    return opts.package
  }
function (opts) {
    opts = opts || {}
    opts = defaults(opts, {
      nodeModulesDir: path.resolve(process.cwd(), 'node_modules'),
      package: rpkg.gen(opts.package)
    })
    fs.mkdirpSync(path.resolve(opts.nodeModulesDir, opts.package.name))
    fs.writeFileSync(
      path.resolve(opts.nodeModulesDir, opts.package.name, 'package.json'),
      JSON.stringify(opts.package, null, 2)
    )
    if (opts.targetPackage) {
      var key = opts.isDev ? 'devDependencies' : 'dependencies'
      var targetPackage = JSON.parse(fs.readFileSync(opts.targetPackage))
      targetPackage[key] = targetPackage[key] || {}
      targetPackage[key][opts.package.name] = opts.package.version
      fs.writeFileSync(opts.targetPackage, JSON.stringify(targetPackage, null, 2))
    }
    return opts.package
  }
function ( opts ) { opts = opts || { } opts = defaults ( opts , { nodeModulesDir : path . resolve ( process . cwd ( ) , 'node_modules' ) , package : rpkg . gen ( opts . package ) } ) fs . mkdirpSync ( path . resolve ( opts . nodeModulesDir , opts . package . name ) ) fs . writeFileSync ( path . resolve ( opts . nodeModulesDir , opts . package . name , 'package.json' ) , JSON . stringify ( opts . package , null , 2 ) ) if ( opts . targetPackage ) { var key = opts . isDev ? 'devDependencies' : 'dependencies' var targetPackage = JSON . parse ( fs . readFileSync ( opts . targetPackage ) ) targetPackage [ key ] = targetPackage [ key ] || { } targetPackage [ key ] [ opts . package . name ] = opts . package . version fs . writeFileSync ( opts . targetPackage , JSON . stringify ( targetPackage , null , 2 ) ) } return opts . package }
Installs mock package into node_modules & updates the corresponding package.json file
@param {object} opts
@param {object} [opts.package] JS object package.json. random package used if none provided
@param {string} [opts.nodeModulesDir] path to node_modules dir to install mock package into. looks for cwd/node_modules by default
@param {string} [opts.targetPackage] path to package.json file to update with the newly installed dependency's metadata
@param {boolean} [opts.isDev] put into devDependencies vs dependencies. used only with targetPackage
@example
mock.install({
package: { name: 'TEST_NAME', version: 'TEST_VERSION' },
nodeModulesDir: '/path/to/target/node_modules',
targetPackage: '/path/to/target/package.json',
isDev: true
})
@return {object} JS object package.json
Installs mock package into node_modules & updates the corresponding package . json file