Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Forked from kentcdodds/package.json
Last active October 13, 2020 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazy4groovy/d23b1383191fa74081b398d9ddbef18d to your computer and use it in GitHub Desktop.
Save crazy4groovy/d23b1383191fa74081b398d9ddbef18d to your computer and use it in GitHub Desktop.
setup script for my workshops
{
"name": "workshop-setup",
"version": "1.0.0",
"description": "This is the common setup script for most of my workshops",
"bin": "./setup.js"
}
#!/usr/bin/env node
var spawnSync = require('child_process').spawnSync
var FAILURE = 'failure'
var SUCCESS = 'success'
// disable https://scarf.sh/
// which is used by some projects dependencies
process.env.SCARF_ANALYTICS = false
var styles = {
// got these from playing around with what I found from:
// https://github.com/istanbuljs/istanbuljs/blob/0f328fd0896417ccb2085f4b7888dd8e167ba3fa/packages/istanbul-lib-report/lib/file-writer.js#L84-L96
// they're the best I could find that works well for light or dark terminals
success: {open: '\u001b[32;1m', close: '\u001b[0m'},
danger: {open: '\u001b[31;1m', close: '\u001b[0m'},
info: {open: '\u001b[36;1m', close: '\u001b[0m'},
subtitle: {open: '\u001b[2;1m', close: '\u001b[0m'},
}
function color(modifier, string) {
return styles[modifier].open + string + styles[modifier].close
}
function run(title, subtitle, command, options) {
options = options || {}
console.log(color('info', ' ▶️ Starting: ' + title))
console.log(color('subtitle', ' ' + subtitle))
console.log(color('subtitle', ' Running the following command: ' + command))
var result = spawnSync(command, {stdio: 'inherit', shell: true})
if (result.status !== 0 && !options.ignoreFailure) {
console.error(
color(
'danger',
' 🚨 Failure: ' +
title +
'. Please review the messages above for information on how to troubleshoot and resolve this issue.',
),
)
process.exit(result.status)
return FAILURE
}
console.log(color('success', ' ✅ Success: ' + title + '\n\n'))
return SUCCESS
}
function main() {
var result
result = run(
'System Validation',
'Ensuring the correct versions of tools are installed on this computer.',
'npx "https://gist.github.com/kentcdodds/abbc32701f78fa70298d444c2303b6d9"',
)
if (result === FAILURE) return
result = run(
'Dependency Installation',
'Installing third party code dependencies so the workshop works properly on this computer.',
'npm install',
)
if (result === FAILURE) return
result = run(
'Project Validation',
'Running validation checks to ensure dependencies were installed properly',
'npm run validate -s',
)
if (result === FAILURE) return
if (!process.argv.includes('--no-autofill')) {
result = run(
'Autofilling Email',
"Each exercise comes with a elaboration form to help your retention. Providing your email now will mean you don't have to provide it each time you fill out the form.",
'npx "https://gist.github.com/kentcdodds/2d44448a8997b9964b1be44cd294d1f5"',
{ignoreFailure: true},
)
if (result === FAILURE) return
}
}
main()
@crazy4groovy
Copy link
Author

eg. npx "https://gist.github.com/crazy4groovy/d23b1383191fa74081b398d9ddbef18d" -q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment