Skip to content

Commit 8bb9436

Browse files
committed
Optionally write output to file
1 parent 0f743be commit 8bb9436

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

cli.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const escapeStringRe = require('escape-string-regexp')
1111
const os = require('os')
1212
const fs = require('fs')
1313
const path = require('path')
14+
const crypto = require('crypto')
1415
const hasOwnProperty = Object.prototype.hasOwnProperty
1516

1617
const data = {
@@ -85,7 +86,20 @@ const data = {
8586
}
8687
}
8788

88-
console.log(JSON.stringify(data, replacer(), 2))
89+
const json = JSON.stringify(data, replacer(), 2)
90+
console.log(json)
91+
92+
if (process.env.SCRIPT_CONTEXT_OUTPUT_DIR) {
93+
const root = process.env.TRAVIS_BUILD_DIR || '.'
94+
const dir = path.resolve(root, process.env.SCRIPT_CONTEXT_OUTPUT_DIR)
95+
const random = crypto.randomBytes(3).toString('hex')
96+
const ids = [Date.now(), path.basename(process.cwd()), data.pkg.pkg && data.pkg.pkg.name, random]
97+
const id = ids.map(s => s && String(s).replace(/[^a-z0-9-]/gi, '')).filter(Boolean).join('_')
98+
const filename = path.join(dir, id + '.json')
99+
100+
fs.mkdirSync(dir, { recursive: true })
101+
fs.writeFileSync(filename, json)
102+
}
89103

90104
function filter (input, include) {
91105
const output = {}

fixture/self-as-tarball-dependency/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"install": "echo from-app && npm-script-context"
88
},
99
"dependencies": {
10-
"npm-script-context": "file:../../npm-script-context-0.0.1.tgz"
10+
"npm-script-context": "file:../../npm-script-context-0.0.2.tgz"
1111
}
1212
}

0 commit comments

Comments
 (0)