Skip to content

Commit

Permalink
feat(cli): dev project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau authored and Akryum committed Dec 21, 2018
1 parent 8ae2b19 commit cfd9c77
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/@nodepack/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@nodepack/generator": "^0.0.1",
"@nodepack/utils": "^0.0.1",
"chalk": "^2.4.1",
"cmd-shim": "^2.0.2",
"commander": "^2.19.0",
"execa": "^1.0.0",
"fs-extra": "^7.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/@nodepack/cli/src/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = class Creator {
log()
if (isTestOrDebug) {
// in development, avoid installation process
// await require('./util/setupDevProject')(context)
await require('../util/setupDevProject')(this.cwd)
} else {
await installDeps(cwd, packageManager, cliOptions.registry)
}
Expand Down Expand Up @@ -230,10 +230,10 @@ module.exports = class Creator {
rawPlugins = sortObject(rawPlugins, ['@nodepack/service'], true)
const plugins = []
for (const id of Object.keys(rawPlugins)) {
const apply = loadModule(`${id}/generator`, this.cwd) || (() => {})
const apply = loadModule(`${id}/src/generator`, this.cwd) || (() => {})
let options = rawPlugins[id] || {}
if (options.prompts) {
const prompts = loadModule(`${id}/prompts`, this.cwd)
const prompts = loadModule(`${id}/src/prompts`, this.cwd)
if (prompts) {
log()
log(`${chalk.cyan(options._isPreset ? `Preset options:` : id)}`)
Expand Down
21 changes: 21 additions & 0 deletions packages/@nodepack/cli/src/util/linkBin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// cross-platform executable link, mostly for Windows
// this file is dev-only.

const fs = require('fs-extra')
const path = require('path')
const cmdShim = require('util').promisify(require('cmd-shim'))

exports.linkBin = async (src, dest) => {
if (!process.env.NODEPACK_TEST && !process.env.NODEPACK_DEBUG) {
throw new Error(`linkBin should only be used during tests or debugging.`)
}
if (process.platform === 'win32' && !process.env.CI) {
// not doing mutex lock because this is only used in dev and the
// src will not be modified
await cmdShim(src, dest)
} else {
await fs.ensureDir(path.dirname(dest))
await fs.symlink(src, dest)
await fs.chmod(dest, '755')
}
}
14 changes: 14 additions & 0 deletions packages/@nodepack/cli/src/util/setupDevProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// dev only

const path = require('path')
const { linkBin } = require('./linkBin')

/**
* @param {string} targetDir
*/
module.exports = function setupDevProject (targetDir) {
return linkBin(
require.resolve('@nodepack/service/src/bin/nodepack-service'),
path.join(targetDir, 'node_modules', '.bin', 'nodepack-service')
)
}

0 comments on commit cfd9c77

Please sign in to comment.