Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function handler(argv: PublishCommand) {
let manifest = resolveManifestSync()
let stream = temp.createWriteStream()
console.log('Writing an archive...')
fstream
.Reader({ path: argv.docDir, type: 'Directory' }) /* Read the source directory */
.pipe(tar.Pack()) /* Convert the directory to a .tar file */
.pipe(zlib.Gzip()) /* Compress the .tar file */
.pipe(stream)
.on('finish', () => {
console.log('Pushing the archive...')
let readStream = fs.createReadStream(stream.path)
let formData = {
archive: {
value: readStream,
options: {
filename: 'archive.tar.gz',
contentType: 'application/json charset=utf-8'
}
},
manifest: JSON.stringify(manifest)
}
exportables.tarBundle = function(opts) {
var cwd = process.cwd();
var target = opts.target || cwd;
var relative = path.relative(cwd, target);
var globRoot = relative || target;
var packer = tar.Pack({
noProprietary: true
});
var buffers = [];
var tempBundleDir = fsTemp.mkdirSync();
var includeRules = glob.rules(target, '.tesselinclude').concat(lists.includes);
var includeFiles = glob.files(globRoot, includeRules);
var includeNegateRules = includeRules.reduce((rules, pattern) => {
if (pattern.startsWith('!')) {
rules.push(pattern.slice(1));
}
return rules;
}, []);
if (fs.existsSync(path.join(target, 'setup.py'))) {
// TODO:
function next () {
if (!tarballLock || !folderLock) return
new Packer({ path: folder, type: "Directory", isDirectory: true })
.on("error", function (er) {
if (er) log.error("tar pack", "Error reading " + folder)
return cb(er)
})
// By default, npm includes some proprietary attributes in the
// package tarball. This is sane, and allowed by the spec.
// However, npm *itself* excludes these from its own package,
// so that it can be more easily bootstrapped using old and
// non-compliant tar implementations.
.pipe(tar.Pack({ noProprietary: !npm.config.get("proprietary-attribs") }))
.on("error", function (er) {
if (er) log.error("tar.pack", "tar creation error", tarball)
cb(er)
})
.pipe(zlib.Gzip())
.on("error", function (er) {
if (er) log.error("tar.pack", "gzip error "+tarball)
cb(er)
})
.pipe(fstream.Writer({ type: "File", path: tarball }))
.on("error", function (er) {
if (er) log.error("tar.pack", "Could not write "+tarball)
cb(er)
})
.on("close", cb)
}
}
return false
}
new InstancePacker({ path: folder, type: 'Directory', isDirectory: true })
.on('error', function (er) {
if (er) log.error('tar pack', 'Error reading ' + folder)
return cb(er)
})
// By default, npm includes some proprietary attributes in the
// package tarball. This is sane, and allowed by the spec.
// However, npm *itself* excludes these from its own package,
// so that it can be more easily bootstrapped using old and
// non-compliant tar implementations.
.pipe(tar.Pack({ noProprietary: !npm.config.get('proprietary-attribs') }))
.on('error', function (er) {
if (er) log.error('tar.pack', 'tar creation error', tarball)
cb(er)
})
.pipe(zlib.Gzip())
.on('error', function (er) {
if (er) log.error('tar.pack', 'gzip error ' + tarball)
cb(er)
})
.pipe(writeStreamAtomic(tarball))
.on('error', function (er) {
if (er) log.error('tar.pack', 'Could not write ' + tarball)
cb(er)
})
.on('close', cb)
}
function next () {
if (!tarballLock || !folderLock) return
new Packer({ path: folder, type: "Directory", isDirectory: true })
.on("error", function (er) {
if (er) log.error("tar pack", "Error reading " + folder)
return cb(er)
})
// By default, npm includes some proprietary attributes in the
// package tarball. This is sane, and allowed by the spec.
// However, npm *itself* excludes these from its own package,
// so that it can be more easily bootstrapped using old and
// non-compliant tar implementations.
.pipe(tar.Pack({ noProprietary: !npm.config.get("proprietary-attribs") }))
.on("error", function (er) {
if (er) log.error("tar.pack", "tar creation error", tarball)
cb(er)
})
.pipe(zlib.Gzip())
.on("error", function (er) {
if (er) log.error("tar.pack", "gzip error "+tarball)
cb(er)
})
.pipe(fstream.Writer({ type: "File", path: tarball }))
.on("error", function (er) {
if (er) log.error("tar.pack", "Could not write "+tarball)
cb(er)
})
.on("close", cb)
}
function compress (options, callback) {
var fstream = require('fstream'),
fstreamNpm = require('fstream-npm'),
zlib = require('zlib'),
tar = require('tar');
fstreamNpm({ path: options.path })
.on('error', callback)
.pipe(tar.Pack())
.on('error', callback)
.pipe(zlib.Gzip())
.on('error', callback)
.pipe(fstream.Writer({ type: "File", path: options.targetPath }))
.on('close', function () {
callback(null, options.name);
});
};
return new Promise(function(resolve, reject) {
var zlib = require('zlib'),
tar = require('tar'),
fstream = require('fstream'),
input = self.gen_dir;
var bufs = [];
var packer = tar.Pack()
.on('error', function(e) { reject(e); });
var gzipper = zlib.Gzip()
.on('error', function(e) { reject(e); })
.on('data', function(d) { bufs.push(d); })
.on('end', function() {
var buf = Buffer.concat(bufs);
var name = self.projectName + '+Documentation';
self.blobClient.putFile(name+'.tar.gz',buf)
.then(function (hash) {
self.result.addArtifact(hash);
resolve();
})
.catch(function(err) {
reject(err);
})
doc.date = (new Date).toISOString();
var data = doc.resources.filter(function(x){return 'path' in x});
var dataPaths = data.map(function(x){return x.path});
var dataNames = data.map(function(x){return x.name});
//compress everything (not ignored) but the data and the package.json
var ignore = new Ignore({
path: root,
ignoreFiles: ['.gitignore', '.npmignore', '.dpmignore'].map(function(x){return path.resolve(root, x)})
});
ignore.addIgnoreRules(dataPaths.concat(['package.json', '.git', 'data_modules', 'node_modules']), 'custom-rules');
//write tarball in a temp dir
var ws = ignore.pipe(tar.Pack()).pipe(zlib.createGzip()).pipe(temp.createWriteStream('dpm-'));
ws.on('error', callback)
ws.on('finish', function(){
dataPaths = dataPaths.map(function(p){return path.resolve(root, p);});
dataPaths.push(ws.path);
//get stats
async.map(dataPaths, fs.stat, function(err, stats){
if(err) return callback(err);
//append _attachments to datapackage
doc._attachments = {
'debug.tar.gz': {follows: true, length: (stats.pop()).size, 'content_type': 'application/x-gtar', _stream: fs.createReadStream(dataPaths.pop())}
};
dataPaths.forEach(function(p, i){
doc._attachments[dataNames[i] + path.extname(p)] = {
return callback(err);
}
if (dir.slice(-1) === '/') {
dir = dir.slice(0, -1);
}
var name = [jitsu.config.get('username'), pkg.name, version || pkg.version].join('-') + '.tgz',
tarball = path.join(jitsu.config.get('tmproot'), name);
fstreamNpm({
path: dir,
ignoreFiles: ['.jitsuignore', '.npmignore', '.gitignore', 'package.json']
})
.on('error', callback)
.pipe(tar.Pack())
.on('error', callback)
.pipe(zlib.Gzip())
.on('error', callback)
.pipe(fstream.Writer({ type: "File", path: tarball }))
.on('close', function () {
callback(null, pkg, tarball);
});
});
};