function createRunner(commandOptions) { const cfg = npmConf(commandOptions).snapshot; return (pkg, stage) => runLifecycle(pkg, stage, cfg); }
initialize() { const { bin, description = DEFAULT_DESCRIPTION, esModule, keywords, license, loc: pkgLocation, name: pkgName, yes, } = this.options; // npm-package-arg handles all the edge-cases with scopes const { name, scope } = npa(pkgName); // optional scope is _not_ included in the directory name this.dirName = scope ? name.split("/").pop() : name; this.pkgName = name; this.pkgsDir = this.project.packageParentDirs.find(pd => pd.indexOf(pkgLocation) > -1) || this.project.packageParentDirs[0]; this.camelName = camelCase(this.dirName); // when transpiling, src => dist; otherwise everything in lib this.outDir = esModule ? "dist" : "lib"; this.targetDir = path.resolve(this.pkgsDir, this.dirName); this.binDir = path.join(this.targetDir, "bin"); this.binFileName = bin === true ? this.dirName : bin; this.libDir = path.join(this.targetDir, esModule ? "src" : "lib"); this.libFileName = `${this.dirName}.js`; this.testDir = path.join(this.targetDir, "__tests__"); this.testFileName = `${this.dirName}.test.js`; this.conf = npmConf({ description, esModule, keywords, scope, yes, }); // consume "builtin" npm config, if it exists (matches npm cli behaviour) this.conf.addFile(builtinNpmrc(), "builtin"); // always set init-main, it's half of the whole point of this module this.conf.set("init-main", `${this.outDir}/${this.libFileName}`); if (esModule) { this.conf.set("init-es-module", `${this.outDir}/${this.dirName}.module.js`); } // allow default init-version when independent versioning enabled if (!this.project.isIndependent()) { this.conf.set("init-version", this.project.version); } // default author metadata with git config if (this.conf.get("init-author-name") === "") { this.conf.set("init-author-name", this.gitConfig("user.name")); } if (this.conf.get("init-author-email") === "") { this.conf.set("init-author-email", this.gitConfig("user.email")); } // override npm_config_init_license if --license provided if (license) { this.conf.set("init-license", license); } // pass --private into module data without aggravating eslint if (this.options.private) { this.conf.set("private", true); } // silence output if logging is silenced // istanbul ignore else if (this.options.loglevel === "silent") { this.conf.set("silent", true); } // save read-package-json the trouble if (this.binFileName) { this.conf.set("bin", { [this.binFileName]: `bin/${this.binFileName}`, }); } // setting _both_ pkg.bin and pkg.directories.bin is an error // https://docs.npmjs.com/files/package.json#directoriesbin this.conf.set("directories", { lib: this.outDir, test: "__tests__", }); this.setFiles(); this.setHomepage(); this.setPublishConfig(); this.setRepository(); return Promise.resolve(this.setDependencies()); }