Skip to content
Commits on Source (3)
#!/usr/bin/env node
const { generate } = require('./generate')
const fs = require('fs')
const { relative } = require('path')
const { promisify } = require('util')
async function main () {
const [,, command, root, output] = process.argv
if (command === 'generate') {
let content
try {
content = await generate(root)
} catch (error) {
console.error(error.message)
process.exit(1)
}
const json = JSON.stringify(content, null, 2)
await promisify(fs.writeFile)(output, json)
const outputPath = relative(process.cwd(), output)
console.log(`Generated the manifest file: ${outputPath}`)
} else {
console.log(`Error: command is not recognized: ${command}`)
}
}
main()
......@@ -4,8 +4,11 @@
"author": "Sebastiaan Deckers <sebdeckers83@gmail.com>",
"repository": "gitlab:commonshost/manifest",
"license": "ISC",
"version": "1.2.0",
"version": "1.3.0",
"main": "manifest.js",
"bin": {
"manifest": "./cli.js"
},
"scripts": {
"test": "npm run lint && npm run proof",
"lint": "standard --verbose | snazzy",
......@@ -22,11 +25,11 @@
"devDependencies": {
"blue-tape": "^1.0.0",
"snazzy": "^7.0.0",
"standard": "^11.0.0",
"standard": "^11.0.1",
"tape": "^4.9.0"
},
"dependencies": {
"@commonshost/sherlock": "gitlab:sebdeckers/sherlock#cleanup",
"@commonshost/sherlock": "^1.0.1",
"ajv": "^6.2.0",
"extglob": "^2.0.4",
"micromatch": "^3.1.10"
......
const test = require('blue-tape')
const { promisify } = require('util')
const fs = require('fs')
const { exec } = require('child_process')
const { join } = require('path')
const { dir } = require('tmp')
test('check the presence of manifest after running command', async (t) => {
const temp = await promisify(dir)({ unsafeCleanup: true })
const root = join(__dirname, 'fixtures/generate')
const output = join(temp, 'test.json')
const command = `node -- cli.js generate ${root} ${output}`
await promisify(exec)(command)
const actual = await promisify(fs.readFile)(output, 'utf8')
const fixture = join(__dirname, 'fixtures/cli-generate.json')
const expected = await promisify(fs.readFile)(fixture, 'utf8')
t.deepEqual(actual, expected)
})
[
{
"get": "/dummy.css",
"push": [
{
"priority": 256,
"glob": [
"/high_priority.css"
]
},
{
"priority": 128,
"glob": [
"/high_priority.woff2"
]
},
{
"priority": 1,
"glob": [
"/medium_priority.svg"
]
}
]
}
]
\ No newline at end of file