@architect/hydrate
Advanced tools
Comparing version 1.2.6 to 1.3.0-RC.1
42
cli.js
#!/usr/bin/env node | ||
let hydrate = require('.') | ||
async function cmd(/*opts*/) { | ||
// TODO parse opts here.. | ||
return hydrate() | ||
/** | ||
* `arc hydrate` | ||
* | ||
* Hydrates functions' dependencies, respecting runtime | ||
* | ||
* options | ||
* (default) .............. hydrates all functions, shared, copies files | ||
* -s|--shared|shared ..... hydrates and copies shared files only | ||
* -u|--update|update ..... updates each function's dependencies | ||
* -v|--verbose|verbose ... prints additional output to console | ||
*/ | ||
let isShared = opt => opt === 'shared' || opt === '--shared' || opt === '-s' | ||
let isUpdate = opt => opt === 'update' || opt === '--update' || opt === '-u' | ||
let isVerbose = opt => opt === 'verbose' || opt === '--verbose' || opt === '-v' | ||
async function cmd(opts=[]) { | ||
let args = { | ||
verbose: opts.some(isVerbose) | ||
} | ||
if (opts.some(isShared)) { | ||
return hydrate(args) | ||
} | ||
if (opts.some(isUpdate)) { | ||
args.update = true | ||
return hydrate(args) | ||
} | ||
args.install = true | ||
return hydrate(args) | ||
} | ||
@@ -14,4 +43,9 @@ | ||
(async function() { | ||
await cmd(process.argv) | ||
try { | ||
await cmd(process.argv) | ||
} | ||
catch (err) { | ||
console.log(err) | ||
} | ||
})(); | ||
} |
@@ -22,10 +22,11 @@ let series = require('run-series') | ||
} | ||
let {verbose=false, basepath=''} = params | ||
let tasks = [] | ||
if (params.install) | ||
tasks.push(function install(callback) { | ||
module.exports.install(params.basepath, callback) // `install` includes `shared` | ||
module.exports.install({verbose, basepath}, callback) // `install` includes `shared` | ||
}) | ||
else if (params.update) | ||
tasks.push(function update(callback) { | ||
module.exports.update(params.basepath, callback) // `update` includes `shared` | ||
module.exports.update({verbose, basepath}, callback) // `update` includes `shared` | ||
}) | ||
@@ -32,0 +33,0 @@ else |
{ | ||
"name": "@architect/hydrate", | ||
"version": "1.2.6", | ||
"version": "1.3.0-RC.1", | ||
"description": "Architect dependency hydrator and shared file manager", | ||
@@ -26,3 +26,3 @@ "main": "index.js", | ||
"@architect/parser": "^1.1.7", | ||
"@architect/utils": "^1.2.3", | ||
"@architect/utils": "^1.3.1", | ||
"chalk": "^2.4.2", | ||
@@ -29,0 +29,0 @@ "cpr": "^3.0.1", |
let chalk = require('chalk') | ||
let chars = require('@architect/utils').chars | ||
let denoise = require('./_denoise') | ||
function start (params) { | ||
let {cwd, cmd, quiet} = params | ||
let status = chalk.grey('Hydrating dependencies:') | ||
let path = chalk.cyan(cwd.replace(process.cwd(), '')) | ||
let command = chalk.cyan.dim(`[${cmd}]`) | ||
let info = `${chars.start} ${status} ${path} ${command}` | ||
let {cwd, action, quiet} = params | ||
let status = chalk.grey('Hydrate') | ||
let path = chalk.cyan(action, cwd.replace(process.cwd(), '')) | ||
let info = `${chars.start} ${status} ${path}` | ||
if (!quiet) console.log(info) | ||
@@ -16,10 +16,12 @@ return info | ||
function done (params, callback) { | ||
let {err, stdout, stderr, start, quiet} = params | ||
let {err, stdout, stderr, cmd, start, quiet, verbose} = params | ||
let result = { | ||
raw: {}, | ||
term: { | ||
stdout: start | ||
start, | ||
stdout: '' | ||
} | ||
} | ||
let format = input => input.split('\n').map(l => ` ${chalk.grey('|')} ${l}`).join('\n') | ||
let command = chalk.cyan.dim(`${cmd}:`) | ||
let format = input => input.split('\n').map(l => ` ${chalk.grey('|')} ${command} ${l}`).join('\n') | ||
@@ -32,10 +34,20 @@ if (err) { | ||
if (stdout && stdout.length > 0) { | ||
stdout = verbose | ||
? stdout | ||
: denoise(stdout) | ||
result.raw.stdout = stdout | ||
result.term.stdout += `\n${format(chalk.grey(stdout.trim()))}` | ||
if (!quiet) console.log(stdout) | ||
result.term.stdout += stdout | ||
? format(chalk.grey(stdout.trim())) | ||
: '' // Necessary, or de-noised lines result in empty lines | ||
if (!quiet && result.term.stdout) console.log(result.term.stdout) | ||
} | ||
if (stderr && stderr.length > 0) { | ||
stderr = verbose | ||
? stderr | ||
: denoise(stderr) | ||
result.raw.stderr = stderr | ||
result.term.stderr = format(chalk.yellow.dim(stderr.trim())) | ||
if (!quiet) console.log(stderr) | ||
result.term.stderr = stderr | ||
? format(chalk.yellow.dim(stderr.trim())) | ||
: '' // Necessary, or de-noised lines result in empty lines | ||
if (!quiet && result.term.stderr) console.log(result.term.stderr) | ||
} | ||
@@ -42,0 +54,0 @@ |
@@ -0,1 +1,2 @@ | ||
let chalk = require('chalk') | ||
let glob = require('glob') | ||
@@ -8,2 +9,3 @@ let series = require('run-series') | ||
let shared = require('./shared') | ||
let {inventory, updater} = require('@architect/utils') | ||
@@ -17,5 +19,8 @@ /** | ||
module.exports = function install(params={}, callback) { | ||
let {basepath, env, quiet, shell, timeout} = params | ||
let {basepath, env, quiet, shell, timeout, verbose} = params | ||
basepath = basepath || 'src' | ||
let update = updater('Hydrate') | ||
let p = basepath.substr(-1) === '/' ? `${basepath}/` : basepath | ||
// eslint-disable-next-line | ||
@@ -32,2 +37,20 @@ let pattern = `${basepath}/**/@(package\.json|requirements\.txt|Gemfile)` | ||
let inv = inventory() | ||
files = files.filter(file => { | ||
let cwd = path.dirname(file) | ||
let isShared = path.join('src', 'shared') | ||
let isViews = path.join('src', 'views') | ||
if (cwd === isShared || cwd === isViews) | ||
return true | ||
return inv.localPaths.some(p => p === cwd) | ||
}) | ||
let deps = files.length | ||
if (deps && deps > 0) | ||
update.status(`Hydrating dependencies in ${deps} function${deps > 1 ? 's' : ''}`) | ||
if (!deps && verbose) | ||
update.status(`No dependencies found in: ${p}${path.sep}**`) | ||
let ops = files.map(file=> { | ||
@@ -38,6 +61,10 @@ let cwd = path.dirname(file) | ||
let start | ||
let cmd | ||
let now = Date.now() | ||
// Prints and executes the command | ||
function exec(cmd, opts, callback) { | ||
start = print.start({cwd, cmd, quiet}) | ||
function exec(command, opts, callback) { | ||
cmd = command | ||
let action = 'Hydrating' | ||
start = print.start({cwd, action, quiet, verbose}) | ||
child.exec(cmd, opts, callback) | ||
@@ -48,3 +75,5 @@ } | ||
function done(err, stdout, stderr) { | ||
print.done({err, stdout, stderr, start, quiet}, callback) | ||
// If zero output, acknowledge *something* happened | ||
if (!err && !stdout && !stderr) stdout = `done in ${(Date.now() - now) / 1000}s` | ||
print.done({err, stdout, stderr, cmd, start, quiet, verbose}, callback) | ||
} | ||
@@ -75,3 +104,13 @@ | ||
series(ops, callback) | ||
series(ops, (err, result) => { | ||
if (err) callback(err) | ||
else { | ||
if (deps && deps > 0) | ||
updater('Success!').done(chalk.green('Finished hydrating dependencies')) | ||
if (!deps) | ||
updater('Hydrate').done('Finished checks, nothing to hydrate') | ||
callback(null, result) | ||
} | ||
}) | ||
} |
@@ -20,14 +20,17 @@ let parse = require('@architect/parser') | ||
module.exports = function copyArc(callback) { | ||
getBasePaths('arcfile', function gotBasePaths(err, paths) { | ||
if (err) throw err | ||
series(paths.map(dest=> { | ||
return function copier(callback) { | ||
copy(path.join(dest, 'shared'), callback) | ||
} | ||
}), | ||
function done(err) { | ||
if (err) callback(err) | ||
else callback() | ||
if (process.env.DEPRECATED) { | ||
getBasePaths('arcfile', function gotBasePaths(err, paths) { | ||
if (err) throw err | ||
series(paths.map(dest=> { | ||
return function copier(callback) { | ||
copy(path.join(dest, 'shared'), callback) | ||
} | ||
}), | ||
function done(err) { | ||
if (err) callback(err) | ||
else callback() | ||
}) | ||
}) | ||
}) | ||
} | ||
else callback() | ||
} | ||
@@ -34,0 +37,0 @@ |
@@ -7,2 +7,3 @@ let cp = require('./copy') | ||
let getBasePaths = require('./get-base-paths') | ||
let {updater} = require('@architect/utils') | ||
@@ -23,10 +24,16 @@ /** | ||
if (err) throw err | ||
let update | ||
let shared = path.join(process.cwd(), 'src', 'shared') | ||
let hasShared = fs.existsSync(shared) | ||
if (hasShared) { | ||
update = updater('Hydrate') | ||
update.start(`Hydrating app with src${path.sep}shared`) | ||
} | ||
series(paths.map(dest=> { | ||
return function copier(callback) { | ||
let src = path.join(process.cwd(), 'src', 'shared') | ||
if (fs.existsSync(src)) { | ||
if (hasShared) { | ||
let finalDest = path.join(dest, 'shared') | ||
rmrf(finalDest, {glob:false}, function(err) { | ||
if (err) callback(err) | ||
else cp(src, finalDest, callback) | ||
else cp(shared, finalDest, callback) | ||
}) | ||
@@ -41,5 +48,9 @@ } | ||
if (err) callback(err) | ||
else callback() | ||
else { | ||
if (update) | ||
update.done(`Hydrated app with src${path.sep}shared`) | ||
callback() | ||
} | ||
}) | ||
}) | ||
} |
@@ -6,5 +6,6 @@ let cp = require('./copy') | ||
let getBasePaths = require('./get-base-paths') | ||
let {readArc} = require('@architect/utils') | ||
/** | ||
* copies src/views | ||
* copies public/static.json | ||
* into function runtime discoverable directory | ||
@@ -22,7 +23,13 @@ * | ||
if (err) throw err | ||
let {arc} = readArc() | ||
let staticDir = 'public' | ||
if (arc.static && arc.static.some(i => i[0] === 'folder')) { | ||
staticDir = arc.static[arc.static.findIndex(i => i[0] === 'folder')][1] || 'public' | ||
} | ||
let static = path.join(process.cwd(), staticDir, 'static.json') | ||
let hasStatic = fs.existsSync(static) | ||
series(paths.map(dest=> { | ||
return function copier(callback) { | ||
let src = path.join(process.cwd(), 'public', 'static.json') | ||
if (fs.existsSync(src)) { | ||
cp(src, path.join(dest, 'shared', 'static.json'), callback) | ||
if (hasStatic) { | ||
cp(static, path.join(dest, 'shared', 'static.json'), callback) | ||
} | ||
@@ -29,0 +36,0 @@ else { |
@@ -7,2 +7,3 @@ let cp = require('./copy') | ||
let getBasePaths = require('./get-base-paths') | ||
let {inventory, updater} = require('@architect/utils') | ||
@@ -21,12 +22,21 @@ /** | ||
module.exports = function copyArc(callback) { | ||
let inv | ||
getBasePaths('views', function gotBasePaths(err, paths) { | ||
if (err) throw err | ||
let update | ||
let views = path.join(process.cwd(), 'src', 'views') | ||
let hasViews = fs.existsSync(views) | ||
if (hasViews) { | ||
update = updater('Hydrate') | ||
update.start(`Hydrating app with src${path.sep}views`) | ||
if (!inv) | ||
inv = inventory() | ||
} | ||
series(paths.map(dest=> { | ||
return function copier(callback) { | ||
let src = path.join(process.cwd(), 'src', 'views') | ||
if (fs.existsSync(src) && dest.includes('get-')) { | ||
if (hasViews && isView(dest)) { | ||
let finalDest = path.join(dest, 'views') | ||
rmrf(finalDest, {glob:false}, function(err) { | ||
if (err) callback(err) | ||
else cp(src, finalDest, callback) | ||
else cp(views, finalDest, callback) | ||
}) | ||
@@ -41,5 +51,17 @@ } | ||
if (err) callback(err) | ||
else callback() | ||
else { | ||
if (update) | ||
update.done(`Hydrated app with src${path.sep}views`) | ||
callback() | ||
} | ||
}) | ||
}) | ||
function isView (dest) { | ||
let viewsConfig = inv && inv.views | ||
let viewsPaths = viewsConfig && viewsConfig.map(v => path.join('src', 'http', v, path.sep)) | ||
if (viewsPaths) | ||
return viewsPaths.some(p => dest.startsWith(p)) | ||
else return dest.startsWith(path.join('src', 'http', 'get-')) | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
let fs = require('fs') | ||
let path = require('path') | ||
let series = require('run-series') | ||
@@ -6,6 +8,10 @@ let copyArc = require('./copy-arc') | ||
let copyStaticJSON = require('./copy-static-json') | ||
let {updater} = require('@architect/utils') | ||
/** | ||
*/ | ||
module.exports = function shared(callback) { | ||
let shared = path.join(process.cwd(), 'src', 'shared') | ||
let views = path.join(process.cwd(), 'src', 'views') | ||
let hasShared = fs.existsSync(shared) || fs.existsSync(views) | ||
if (hasShared) | ||
updater('Hydrate').status('Hydrating app with shared files') | ||
series([ | ||
@@ -12,0 +18,0 @@ copyShared, |
@@ -7,2 +7,3 @@ let glob = require('glob') | ||
let shared = require('./shared') | ||
let {updater} = require('@architect/utils') | ||
@@ -13,5 +14,8 @@ /** | ||
module.exports = function update(params={}, callback) { | ||
let {basepath, env, quiet, shell, timeout} = params | ||
let {basepath, env, quiet, shell, timeout, verbose} = params | ||
basepath = basepath || 'src' | ||
let update = updater('Hydrate') | ||
let p = basepath.substr(-1) === '/' ? basepath : `${basepath}/` | ||
// eslint-disable-next-line | ||
@@ -28,2 +32,10 @@ let pattern = `${basepath}/**/@(package\.json|requirements\.txt|Gemfile)` | ||
let deps = files.length | ||
if (deps && deps > 0) | ||
update.status(`Updating dependencies in ${deps} function${deps > 1 ? 's' : ''}`) | ||
if (!deps && verbose) | ||
update.status(`No dependencies found to update in: ${p}`) | ||
let ops = files.map(file=> { | ||
@@ -33,6 +45,11 @@ let cwd = path.dirname(file) | ||
return function updation(callback) { | ||
let start | ||
let cmd | ||
let now = Date.now() | ||
// printer function | ||
function exec(cmd, opts, callback) { | ||
print.start({cwd, cmd, quiet}) | ||
function exec(command, opts, callback) { | ||
cmd = command | ||
let action = 'Updating' | ||
start = print.start({cwd, action, quiet, verbose}) | ||
child.exec(cmd, opts, callback) | ||
@@ -43,3 +60,5 @@ } | ||
function done(err, stdout, stderr) { | ||
print.done({err, stdout, stderr, quiet}, callback) | ||
// If zero output, acknowledge *something* happened | ||
if (!err && !stdout && !stderr) stdout = `done in ${(Date.now() - now) / 1000}s` | ||
print.done({err, stdout, stderr, cmd, start, quiet, verbose}, callback) | ||
} | ||
@@ -46,0 +65,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35699
16
621
1
8
Updated@architect/utils@^1.3.1