TIL, 2021-11-27, Node scripting
Hacking around scripts
- Multiple Dangerfile:
yarn danger --help
yarn
vsnpm
- am sorta preferringyarn
now due to executing.- How to store env variables in a repo? Should we store env variables in a repo?
exec
to run shell commands fromnode
.const args = require('yargs').argv
thenargs._[0]
to access the argument.-
require('fs')
to use file system. - Exit in Node: Reference is
process.exit(1)
. console.log can be in two arguments to add a color.
- Reading files in Node: Reference
- Environment variables? Reference
- Can set it manually via
process.env
.
- Can set it manually via
- Appending to a file: Reference
const { exec } = require('child_process');
const args = require('yargs').argv;
const fs = require('fs');
const tenant = args._[0];
const getTenants = function () {
return new Promise((resolve, reject) => {
exec(
`ls ./projects | xargs`,
(error, stdout, stderr) => {
console.log('haha');
resolve(stdout.trim());
},
);
});
};