@idearium/cli
Advanced tools
Comparing version 4.1.2 to 4.1.3-beta.1
@@ -5,3 +5,3 @@ #!/usr/bin/env -S node --trace-warnings | ||
const program = require('commander'); | ||
const program = require('commander-latest'); | ||
const { exec } = require('shelljs'); | ||
@@ -11,2 +11,7 @@ const { basename, resolve } = require('path'); | ||
const { loadConfig, newline, reportError } = require('./lib/c'); | ||
const { | ||
flagBuildArgs, | ||
formatBuildArgs, | ||
validateBuildArgs, | ||
} = require('./lib/c-kc'); | ||
@@ -17,9 +22,10 @@ // The basic program, which uses sub-commands. | ||
.option( | ||
'-t [tag]', | ||
'-t, --tag <tag>', | ||
'Supply a specific tag, otherwise `latest` will be used' | ||
) | ||
.option( | ||
'-n [name]', | ||
'-n, --name <name>', | ||
'Supply a name for the image, otherwise the location name will be used' | ||
) | ||
.option('--build-arg <arg...>', 'Build arguments to pass to Docker.') | ||
.description( | ||
@@ -35,40 +41,5 @@ 'Provide a Docker location and the Dockerfile will be used to build a Docker image. See https://github.com/idearium/cli#docker-configuration for configuration options.' | ||
/** | ||
* Pad a string with a left space, if the string has a length. | ||
* @param {String} str A string to pad with a left space. | ||
* @return {String} A string left-padded with a space. | ||
*/ | ||
const leftSpace = (str) => { | ||
if (str && typeof str === 'string') { | ||
return ` ${str}`; | ||
} | ||
return str; | ||
}; | ||
/** | ||
* Given a string of command seperated env variables, turn them into --build-arg arguments for `docker build`. | ||
* @param {String} args A string of comma seperated env variables. | ||
* @return {String} --build-arg arguments for `docker build`. | ||
*/ | ||
const formatBuildArgs = (args = {}) => { | ||
const keys = Object.keys(args); | ||
if (!keys.length) { | ||
return ''; | ||
} | ||
const buildArguments = keys | ||
.map( | ||
(key) => | ||
`--build-arg ${key}=${ | ||
typeof args[key] === 'function' ? args[key]() : args[key] | ||
}` | ||
) | ||
.join(' '); | ||
return `${leftSpace(buildArguments)}`; | ||
}; | ||
const [location] = program.args; | ||
const opts = program.opts(); | ||
const buildArgs = flagBuildArgs(validateBuildArgs(opts.buildArg || [])); | ||
@@ -107,8 +78,8 @@ if (!location) { | ||
const tag = program.T ? program.T : 'latest'; | ||
const name = program.N ? program.N : location; | ||
const tag = opts.tag ? opts.tag : 'latest'; | ||
const name = opts.name ? opts.name : location; | ||
let cmd = `docker build -t ${name}:${tag}${formatBuildArgs( | ||
dockerLocation.buildArgs | ||
)} -f ${file}`; | ||
)}${formatBuildArgs(buildArgs)} -f ${file}`; | ||
@@ -133,5 +104,5 @@ if (useTar) { | ||
if (program.R) { | ||
process.stdout.write(`${tag}${newline(program.N)}`); | ||
process.stdout.write(`${tag}${newline(opts.name)}`); | ||
} | ||
}); | ||
}); |
@@ -5,3 +5,3 @@ #!/usr/bin/env -S node --trace-warnings | ||
const program = require('commander'); | ||
const program = require('commander-latest'); | ||
const { exec } = require('shelljs'); | ||
@@ -15,2 +15,7 @@ const { | ||
const getPropertyPath = require('get-value'); | ||
const { | ||
flagBuildArgs, | ||
formatBuildArgs, | ||
validateBuildArgs, | ||
} = require('./lib/c-kc'); | ||
@@ -20,3 +25,4 @@ program | ||
.option('-d', 'Also deploy the location(s).') | ||
.option('-t --tag <tag>', 'A tag for the generated Docker image(s).') | ||
.option('-t, --tag <tag>', 'A tag for the generated Docker image(s).') | ||
.option('--build-arg <arg...>', 'Build arguments to pass to Docker.') | ||
.description( | ||
@@ -28,3 +34,6 @@ "Provide a Docker location and the Dockerfile will be used to build a Docker image. If you don't pass a location, all locations will be built." | ||
const [location = 'all'] = program.args; | ||
const { tag = String(Math.floor(Date.now() / 1000)) } = program; | ||
const { tag = String(Math.floor(Date.now() / 1000)) } = program.opts(); | ||
const buildArgs = flagBuildArgs( | ||
validateBuildArgs(program.opts().buildArg || []) | ||
); | ||
@@ -69,3 +78,5 @@ return ( | ||
const cmd = `c d build -n ${prefix}/${loc} -t ${tag} ${loc}`; | ||
const cmd = `c d build -n ${prefix}/${loc} -t ${tag}${formatBuildArgs( | ||
buildArgs | ||
)} ${loc}`; | ||
@@ -72,0 +83,0 @@ exec(cmd, (err, stdout, stderr) => { |
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
exec( | ||
`/usr/local/bin/c sdp ssh "docker run --name section-bootstrap --rm --net=host -v /var/lib/minikube:/var/lib/minikube:ro sectionio/section-init"` | ||
`yarn c sdp ssh "docker run --name section-bootstrap --rm --net=host -v /var/lib/minikube:/var/lib/minikube:ro sectionio/section-init"` | ||
); |
@@ -7,2 +7,2 @@ #!/usr/bin/env node | ||
exec('/usr/local/bin/c sdp service -n section-shared developer-pop'); | ||
exec('yarn c sdp service -n section-shared developer-pop'); |
@@ -44,9 +44,7 @@ #!/usr/bin/env node | ||
return execa | ||
.shell( | ||
`/usr/local/bin/c sdp gm cmd -s ${submodule} rev-parse --verify ${branch}` | ||
) | ||
.shell(`yarn c sdp gm cmd -s ${submodule} rev-parse --verify ${branch}`) | ||
.then(({ code, stderr, stdout }) => { | ||
if (!code && !stderr.length && stdout.length) { | ||
return exec( | ||
`/usr/local/bin/c sdp gm cmd -s ${submodule} checkout ${branch}` | ||
`yarn c sdp gm cmd -s ${submodule} checkout ${branch}` | ||
); | ||
@@ -57,3 +55,3 @@ } | ||
return exec( | ||
`/usr/local/bin/c sdp gm cmd -s ${submodule} checkout -b ${branch}` | ||
`yarn c sdp gm cmd -s ${submodule} checkout -b ${branch}` | ||
); | ||
@@ -60,0 +58,0 @@ } |
@@ -29,3 +29,3 @@ #!/usr/bin/env node | ||
exec(`/usr/local/bin/c sdp gm cmd -s ${submodule} push developer-pop`); | ||
exec(`yarn c sdp gm cmd -s ${submodule} push developer-pop`); | ||
}); |
@@ -21,3 +21,3 @@ #!/usr/bin/env node | ||
.shell( | ||
`/usr/local/bin/c sdp service -n section-shared git-daemon-developer-pop --url` | ||
`yarn c sdp service -n section-shared git-daemon-developer-pop --url` | ||
) | ||
@@ -24,0 +24,0 @@ .then(({ code, stderr, stdout }) => { |
@@ -5,7 +5,17 @@ #!/usr/bin/env -S node --trace-warnings | ||
const program = require('commander'); | ||
const { args } = require('commander-latest'); | ||
const program = require('commander-latest'); | ||
const { exec } = require('shelljs'); | ||
const { env, reportError } = require('./lib/c'); | ||
const { env } = require('./lib/c'); | ||
const { | ||
flagBuildArgs, | ||
formatBuildArgs, | ||
validateBuildArgs, | ||
} = require('./lib/c-kc'); | ||
program | ||
.option( | ||
'--build-arg <args...>', | ||
'A comma seperated list of environment variable names in which to retrieve values from to pass as build args' | ||
) | ||
.description( | ||
@@ -16,2 +26,6 @@ "This command should be run via Skaffold. It interprets environment variables used by the Skaffold custom build script contract and builds images accordingly using 'c kc build'." | ||
const buildArgs = flagBuildArgs( | ||
validateBuildArgs(program.opts().buildArg || []) | ||
); | ||
if (!env('IMAGE')) { | ||
@@ -27,2 +41,2 @@ return reportError( | ||
exec(`yarn c kc build ${name} -t ${tag}`); | ||
exec(`yarn c kc build ${name}${formatBuildArgs(buildArgs)} -t ${tag}`); |
@@ -59,2 +59,44 @@ 'use strict'; | ||
const flagBuildArgs = (args = []) => args.map((arg) => `--build-arg ${arg}`); | ||
const formatBuildArgs = (args) => { | ||
if (Array.isArray(args)) { | ||
return args.length > 0 ? `${leftSpace(args.join(' '))}` : ''; | ||
} | ||
if (typeof args === 'object' && args !== null) { | ||
const keys = Object.keys(args); | ||
if (keys.length) { | ||
return `${leftSpace( | ||
keys | ||
.map( | ||
(key) => | ||
`--build-arg ${key}=${ | ||
typeof args[key] === 'function' | ||
? args[key]() | ||
: args[key] | ||
}` | ||
) | ||
.join(' ') | ||
)}`; | ||
} | ||
} | ||
return ''; | ||
}; | ||
/** | ||
* Pad a string with a left space, if the string has a length. | ||
* @param {String} str A string to pad with a left space. | ||
* @return {String} A string left-padded with a space. | ||
*/ | ||
const leftSpace = (str) => { | ||
if (str && typeof str === 'string') { | ||
return ` ${str}`; | ||
} | ||
return str; | ||
}; | ||
const renderServicesTemplates = async (path = '', services = []) => { | ||
@@ -135,6 +177,12 @@ await asyncForEach(services, async (service) => { | ||
const validateBuildArgs = (args = []) => | ||
args.filter((arg) => arg.split('=').length == 2); | ||
module.exports = { | ||
ensureServiceFilesExist, | ||
flagBuildArgs, | ||
formatBuildArgs, | ||
renderServicesTemplates, | ||
setLocalsForServices, | ||
validateBuildArgs, | ||
}; |
@@ -7,2 +7,8 @@ # @idearium/cli | ||
## v4.1.3-beta.1 - 2021-09-07 | ||
### Added | ||
- `--build-arg` flag to build related commands. | ||
## v4.1.2 - 2021-08-04 | ||
@@ -9,0 +15,0 @@ |
@@ -9,4 +9,4 @@ # @idearium/cli | ||
- Node.js >v8.0.0 | ||
- NPM >v4.3.0 | ||
- Node.js >v8.0.0 | ||
- NPM >v4.3.0 | ||
@@ -21,9 +21,6 @@ ## Code | ||
When you're ready to publish a new version, there are a few scripts to help you: | ||
When you're ready to publish a new version: | ||
- `npm run prerelease-release` to version bump, prerelease, and push to NPM. | ||
- `npm run patch-release` to version bump, patch, and push to NPM. | ||
- `npm run minor-release` to version bump, minor, and push to NPM. | ||
- `npm run major-release` to version bump, major, and push to NPM. | ||
These will also create a git tag, and push to the remote repository. | ||
- Version bump the package.json version. | ||
- Update the changelog. | ||
- Create a new release via the Github UI with the tag `vX.X.X`, branch name as the current branch and the release name the same as the tag `vX.X.X`. |
{ | ||
"name": "@idearium/cli", | ||
"version": "4.1.2", | ||
"version": "4.1.3-beta.1", | ||
"description": "The Idearium cli, which makes working with our projects much easier.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
166260
3973
2