├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── TODO.md ├── index.js └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | tmp 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Benjamin Winkler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-asar 2 | 3 | [![build status](http://img.shields.io/travis/bwin/gulp-asar/master.svg?style=flat-square)](https://travis-ci.org/bwin/gulp-asar) 4 | [![dependencies](http://img.shields.io/david/bwin/gulp-asar.svg?style=flat-square)](https://david-dm.org/bwin/gulp-asar) 5 | [![npm version](http://img.shields.io/npm/v/gulp-asar.svg?style=flat-square)](https://npmjs.org/package/gulp-asar) 6 | 7 | > Gulp plugin to generate atom-shell asar packages. 8 | 9 | ## Example gulpfile 10 | ```js 11 | var gulp = require('gulp'); 12 | var gulpAsar = require('gulp-asar'); 13 | 14 | gulp.task('default', function() { 15 | gulp.src('some/path/**/*', { base: 'some/path/' }) 16 | .pipe(gulpAsar('archive.asar')) 17 | .pipe(gulp.dest('dist')); 18 | }); 19 | ``` -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | 2 | # TODO 3 | 4 | - [ ] add tests 5 | - [ ] -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | var through = require('through2'); 3 | var gutil = require('gulp-util'); 4 | require('terminal-colors'); 5 | 6 | var Filesystem = require('asar/lib/filesystem'); 7 | var pickle = require('asar/node_modules/chromium-pickle-js'); 8 | 9 | const PLUGIN_NAME = 'gulp-asar'; 10 | 11 | module.exports = function(destFilename, opts) { 12 | opts = opts || {}; 13 | if (!destFilename) { 14 | throw new gutil.PluginError(PLUGIN_NAME, 'destFilename'.blue + ' required'); 15 | } 16 | 17 | var cwd = opts.base || process.cwd(); // ? 18 | var filesystem = new Filesystem(cwd); 19 | var out = []; 20 | var outLen = 0; 21 | 22 | var stream = through.obj(function(file, enc, cb) { 23 | if (file.isStream()) { 24 | return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 25 | } 26 | 27 | if(file.stat.isDirectory()) { 28 | filesystem.insertDirectory(file.relative); 29 | } 30 | else if(file.stat.isSymbolicLink()) { 31 | filesystem.insertLink(file.relative, file.stat); 32 | } 33 | else { 34 | filesystem.insertFile(file.relative, false, file.stat); 35 | outLen += file.contents.length; 36 | out.push(file.contents); 37 | } 38 | cb(); 39 | }, function(cb) { 40 | var headerPickle = pickle.createEmpty(); 41 | headerPickle.writeString(JSON.stringify(filesystem.header)); 42 | var headerBuf = headerPickle.toBuffer(); 43 | 44 | var sizePickle = pickle.createEmpty(); 45 | sizePickle.writeUInt32(headerBuf.length); 46 | var sizeBuf = sizePickle.toBuffer(); 47 | 48 | outLen += headerBuf.length; 49 | outLen += sizeBuf.length; 50 | out.unshift(headerBuf); 51 | out.unshift(sizeBuf); 52 | 53 | var archive = Buffer.concat(out, outLen); 54 | out = []; 55 | 56 | this.push(new gutil.File({ 57 | cwd: cwd, 58 | base: cwd, 59 | path: destFilename, 60 | contents: archive, 61 | enc: 'utf8' 62 | })); 63 | 64 | cb(); 65 | }); 66 | return stream; 67 | }; 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-asar", 3 | "version": "0.0.2", 4 | "description": "Gulp plugin to generate atom-shell asar archives.", 5 | "main": "index.js", 6 | "engines": { 7 | "node": ">= 0.10.0" 8 | }, 9 | "scripts": { 10 | "test": "mocha --reporter spec" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com/bwin/gulp-asar.git" 15 | }, 16 | "keywords": [ 17 | "gulpplugin", 18 | "asar", 19 | "atom-shell" 20 | ], 21 | "author": "Benjamin Winkler (bwin)", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/bwin/gulp-asar/issues" 25 | }, 26 | "homepage": "https://github.com/bwin/gulp-asar", 27 | "devDependencies": { 28 | "gulp": "^3.8.11", 29 | "mocha": "^2.1.0" 30 | }, 31 | "dependencies": { 32 | "asar": "^0.6.1", 33 | "gulp-util": "^3.0.3", 34 | "terminal-colors": "^0.1.3", 35 | "through2": "^1.1.1" 36 | } 37 | } 38 | --------------------------------------------------------------------------------