-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Varache
committed
Aug 7, 2018
1 parent
e74e2c7
commit 765e37d
Showing
13 changed files
with
1,936 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
|
||
function createZipWithDitto(basedir, file, target) { | ||
target = target + '.zip'; | ||
return new Promise((resolve, reject) => { | ||
let cmd = 'ditto', | ||
args = ['-ck', '--rsrc', '--sequesterRsrc', '--keepParent', file, target], | ||
p; | ||
console.log(`[ZIP] ${cmd} ${args.join(' ')}`); | ||
p = cp.spawn(cmd, args, { cwd: basedir }); | ||
p.on('error', (e) => reject(e)); | ||
p.stdout.on('data', (d) => { | ||
console.log(`[ZIP] ${d.toString()}`); | ||
}); | ||
p.on('exit', (code) => { | ||
if (code != 0) { | ||
throw new Error(`ditto exited with a non-zero code: ${code}`); | ||
} | ||
resolve(target); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
archive(buildDir) { | ||
const baseDir = path.dirname(buildDir); | ||
const name = buildDir.split('/').pop(); | ||
const target = path.join(os.tmpdir(), 'kart-ditto-tmp'); | ||
return createZipWithDitto(baseDir, name, target) | ||
.then(() => { | ||
return fs.createReadStream(`${target}.zip`); | ||
}); | ||
}, | ||
extension() { | ||
return 'zip'; | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
archive(buildDir) { | ||
return fs.createReadStream(buildDir); | ||
}, | ||
extension(buildDir) { | ||
return path.extname(buildDir).replace(/^\./, ''); | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const tarFs = require('tar-fs'), | ||
zlib = require('zlib'); | ||
|
||
module.exports = { | ||
archive(buildDir) { | ||
let gzip = zlib.createGzip(), | ||
stream = tarFs.pack(buildDir); | ||
return stream.pipe(gzip); | ||
}, | ||
extension() { | ||
return 'tar.gz'; | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const archiver = require('archiver'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
archive(buildDir) { | ||
const archive = archiver('zip'); | ||
archive | ||
.glob(path.normalize(`**/*`), { | ||
cwd: path.normalize(buildDir), | ||
root: path.normalize(buildDir), | ||
}) | ||
.finalize(); | ||
return archive; | ||
}, | ||
extension() { | ||
return 'zip'; | ||
}, | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const kart = require('../lib'), | ||
should = require('should'), | ||
testUtil = require('./test-util'), | ||
path = require('path'); | ||
|
||
describe('kart.archive', function () { | ||
this.timeout(30000); | ||
|
||
beforeEach(() => { | ||
return testUtil.setupS3(); | ||
}); | ||
afterEach(() => { | ||
testUtil.cleanupBuildDirectories(); | ||
return testUtil.teardownS3(); | ||
}); | ||
describe('.store()', () => { | ||
it('with zip type', () => { | ||
let buildDir; | ||
|
||
return testUtil.generateBuildDirectory({ | ||
fileCount: [10, 20], | ||
}).then((dir) => { | ||
buildDir = dir; | ||
return kart.archive.store(buildDir.path, 'testing', 'sync', '0.5.6', null, 'armv7', null, 'zip'); | ||
}).then((archive) => { | ||
archive.should.containEql({ | ||
project: 'testing', | ||
channel: 'sync', | ||
version: '0.5.6', | ||
number: 1, | ||
arch: 'armv7', | ||
ext: 'zip', | ||
}); | ||
}); | ||
}); | ||
it('with no type', () => { | ||
let buildDir; | ||
|
||
return testUtil.generateBuildDirectory({ | ||
fileCount: 1, | ||
}).then((dir) => { | ||
buildDir = dir; | ||
return kart.archive.store(path.join(buildDir.path, buildDir.files[0]), 'testing', 'sync', '0.5.6', null, 'armv7', null, 'none'); | ||
}).then((archive) => { | ||
archive.should.containEql({ | ||
project: 'testing', | ||
channel: 'sync', | ||
version: '0.5.6', | ||
number: 1, | ||
arch: 'armv7', | ||
ext: 'txt', | ||
}); | ||
}); | ||
}); | ||
if (process.platform !== 'darwin') { | ||
return; | ||
} | ||
it('with ditto', () => { | ||
let buildDir; | ||
|
||
return testUtil.generateBuildDirectory({ | ||
fileCount: [10, 20], | ||
}).then((dir) => { | ||
buildDir = dir; | ||
return kart.archive.store(buildDir.path, 'testing', 'sync', '0.5.6', null, 'armv7', null, 'ditto'); | ||
}).then((archive) => { | ||
archive.should.containEql({ | ||
project: 'testing', | ||
channel: 'sync', | ||
version: '0.5.6', | ||
number: 1, | ||
arch: 'armv7', | ||
ext: 'zip', | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
setTimeout(() => { | ||
|
||
}, 4000000000000000000000000); |
Oops, something went wrong.