Last active
November 16, 2018 15:34
-
-
Save apaleslimghost/91f1b63cd12d37c1709099bde9c1b4bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const {f = 'Makefile', _} = require('minimist')(process.argv.slice(2)) | |
const fs = require('fs') | |
const parseMakefileRules = require('@quarterto/parse-makefile-rules') | |
const formatBody = body => body.replace(/^/mg, '\t') | |
const formatRule = (rule, body) => body && `${rule}: | |
${formatBody(body)} | |
`; | |
const formatRules = (names, rules) => | |
names.length === 1? rules[names[0]] | |
: /* otherwise */ names.map( | |
name => formatRule(name, rules[name]) | |
).filter(Boolean).join('\n') | |
const makefile = fs.readFileSync(f, 'utf8') | |
const parsedRules = parseMakefileRules(makefile) | |
const rules = _.length? _ | |
: /* otherwise */ Object.keys(parsedRules) | |
console.log( | |
formatRules( | |
rules, | |
parsedRules | |
) || process.exit(1) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment