Skip to content

Commit d686fa8

Browse files
committed
initial commit
0 parents  commit d686fa8

36 files changed

+1331
-0
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
releases/

.eslintrc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
env:
2+
browser: true
3+
es6: true
4+
node: true
5+
6+
ecmaFeatures:
7+
jsx: true
8+
9+
globals:
10+
log: true
11+
12+
plugins:
13+
- react
14+
15+
rules:
16+
comma-dangle: always
17+
no-unused-expressions: false
18+
no-unused-vars:
19+
- 2
20+
- vars: all
21+
args: none
22+
quotes:
23+
- 2
24+
- single
25+
- avoid-escape
26+
strict: false
27+
28+
# vim:ft=yaml:

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# node.js
2+
npm-debug.log
3+
node_modules/
4+
5+
# main process
6+
main/*.js
7+
8+
# renderer process
9+
renderer/*.css
10+
renderer/*.html
11+
renderer/*.js
12+
13+
# release files
14+
releases/

.travis.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: node_js
2+
node_js:
3+
- "iojs"
4+
sudo: false
5+
cache:
6+
directories:
7+
- node_modules
8+
notifications:
9+
email: false
10+
before_deploy:
11+
- npm run release-travis
12+
deploy:
13+
provider: releases
14+
all_braches: true
15+
skip_cleanup: true
16+
api_key:
17+
secure: OfUZkFsmeZzgIV+L3/B787TnhW+Wqxf8Sk/hsZ1oU4MGfE1M/RZWHLWJuRRJESwshivCaMbCJ7iqtE6MQEBZmjHX95HWm3TLeEqf5TL1uOEkH6tonlFhvblYPthfCJIOJ/E19dCjX8ePfpuL7AqtzVzY4pgtbT8yOe7BM+SpW7OMKuESFsHjJcIR21kbBADvR/prwqqMjCwhldlyKDyqxV1I2/3fURt61tL9RPJH83T6BkkETMa72SLvDTwLoM12EaUWUEnmUA8c9a8O6yOLSRNjbyVZfD9E/p9EZMpIwDq14hsS9fbn5KdsmOBS7mjBQzNcDdKUwc7GGhmLfwSgOiz/4BRFYNMwPZPGuWLRUjc+8O75Ell52n5HHHcyF4Q1qHvgPFPhgCXKKbK9/ocgOjeSgtW/Um3kJGbjD79NkS+yOSq95U5BBNd5B53SWtfp7zBpMJVVETBg1c/8nfwGwqxcD3lSlCwdI7leDeNMfEskJhj1JnwiUpIiWqW+47uAjKJjrtQp9D1omBStiu/DQnrd51X5p/Zw91xQRZVSWwEnHfY7kJKi64zQpUYhJSrFexHy5zPRhqwyqLYv2hXASbN+UOEcg0u0/Y8KeNmYrLwplqK4MNwlsSVAnaaOqjO/hZKfEEaIBJB/BQ8GTA8Q4qyJ6ldlNLS1cgiCD93Brd0=
18+
file:
19+
- releases/minify-image-win-x86_64.zip
20+
- releases/minify-image-osx-x86_64.zip
21+
- releases/minify-image-linux-x86_64.zip
22+
on:
23+
repo: tsukurite/minify-image
24+
tags: true

HISTORY.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.0.0 / 2015-06-24
2+
3+
- initial release

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(The MIT license)
2+
3+
Copyright (c) 2015 tsukurite
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
7+
deal in the Software without restriction, including without limitation the
8+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9+
sell 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
13+
all 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
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
IN THE SOFTWARE.

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# minify-image
2+
3+
application for minifying image, based on [Electron](http://electron.atom.io/)
4+
5+
## License
6+
7+
The MIT license.

electron-packager.js

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#!/usr/bin/env node --harmony_arrow_functions
2+
3+
'use strict';
4+
5+
var fs = require('fs'),
6+
path = require('path'),
7+
co = require('co'),
8+
electronPackager = require('electron-packager'),
9+
glob = require('glob'),
10+
objectAssign = require('object-assign'),
11+
rimraf = require('rimraf'),
12+
thunkify = require('thunkify'),
13+
packageData = require('./package');
14+
15+
/**
16+
* wrpping with Electron
17+
*
18+
* @param {Object} baseOptions
19+
* @param {Object} overwriteOptions
20+
* @return {Promise}
21+
*/
22+
function packaging(baseOptions, overwriteOptions) {
23+
var options = objectAssign({}, baseOptions, overwriteOptions);
24+
25+
return co(function*() {
26+
return yield thunkify(electronPackager).call(electronPackager, options);
27+
});
28+
}
29+
30+
/**
31+
* download for imagemin moudule
32+
*
33+
* @param {String} vendorDirPath
34+
* @return {Promise}
35+
*/
36+
function download(vendorDirPath) {
37+
var pluginModule = require(`${vendorDirPath}/../lib`),
38+
fetch = thunkify(pluginModule.download.bind(pluginModule));
39+
40+
return co(function*() {
41+
return yield fetch();
42+
});
43+
}
44+
45+
/**
46+
* parallel download for imagemin modules
47+
*
48+
* @param {String[]} vendorDirPaths
49+
* @return {Function[]}
50+
*/
51+
function parallelDownload(vendorDirPaths) {
52+
return vendorDirPaths.map(
53+
(vendorDirPath) => download(vendorDirPath)
54+
);
55+
}
56+
57+
/**
58+
* remove downloaded binaries and download binaries for target platform
59+
*
60+
* @param {String} platform
61+
* @param {String} releasesDir
62+
* @param {Promise}
63+
*/
64+
function setupBinaries(platform, releasesDir) {
65+
return co(function*() {
66+
var vendorDirGlob = `${releasesDir}/${platform}/**/vendor`,
67+
vendorDirs = yield thunkify(glob).call(glob, vendorDirGlob);
68+
69+
// remove installed module's binaries
70+
yield vendorDirs.map(
71+
(vendorDir) => thunkify(rimraf).call(rimraf, vendorDir)
72+
);
73+
74+
// download to binaries for target platform
75+
return yield parallelDownload(vendorDirs);
76+
});
77+
}
78+
79+
/**
80+
* process faker
81+
*
82+
* @class
83+
*/
84+
function ProcessFaker() {
85+
this._originalProcess = process;
86+
this._originalDescripters = {};
87+
}
88+
89+
/**
90+
* fake property
91+
*
92+
* @param {String} propertyName
93+
* @param {*} fakeValue
94+
*/
95+
ProcessFaker.prototype.fake = function fake(propertyName, fakeValue) {
96+
var originalDescripter =
97+
Object.getOwnPropertyDescriptor(this._originalProcess, propertyName);
98+
99+
this._originalDescripters[propertyName] = originalDescripter;
100+
Object.defineProperty(process, propertyName, fakeValue);
101+
};
102+
103+
/**
104+
* revert faked property.
105+
*
106+
* @param {String} propertyName
107+
*/
108+
ProcessFaker.prototype.unfake = function unfake(propertyName) {
109+
var originalDescripter =
110+
this._originalDescripters[propertyName];
111+
112+
Object.defineProperty(process, propertyName, originalDescripter);
113+
this._originalDescripters[propertyName] = null;
114+
};
115+
116+
co(function*() {
117+
const RELEASES_DIR = path.join(__dirname, '/releases');
118+
119+
var options = {
120+
dir: __dirname,
121+
name: 'minify-image',
122+
arch: 'x64',
123+
version: '0.28.1',
124+
prune: true,
125+
ignore: [
126+
// common
127+
'\.(?:coffee|jade|jsx|scss)$',
128+
129+
// development files
130+
'webpack.config.js$',
131+
132+
// MEMO: fail when prune option is true
133+
// 'package.json$',
134+
135+
// empty dirs
136+
'renderer/actions',
137+
'renderer/components',
138+
'renderer/constants',
139+
'renderer/dispatcher',
140+
'renderer/stores',
141+
142+
// this file
143+
path.basename(__filename),
144+
145+
// releases dir
146+
RELEASES_DIR,
147+
],
148+
'app-version': packageData.version,
149+
};
150+
151+
// packaging
152+
// TODO: parallel execution
153+
console.log('packaged to', yield packaging(options, {
154+
platform: 'win32',
155+
out: RELEASES_DIR,
156+
}));
157+
console.log('packaged to', yield packaging(options, {
158+
platform: 'linux',
159+
out: path.normalize(`${RELEASES_DIR}/minify-image-linux-x86_64`),
160+
}));
161+
console.log('packaged to', yield packaging(options, {
162+
platform: 'darwin',
163+
out: path.normalize(`${RELEASES_DIR}/minify-image-osx-x86_64`),
164+
}));
165+
166+
// rename directory
167+
yield thunkify(fs.rename).call(
168+
fs,
169+
path.normalize(`${RELEASES_DIR}/minify-image-win32`),
170+
path.normalize(`${RELEASES_DIR}/minify-image-win-x86_64`)
171+
);
172+
173+
//----------------------------------------------------------------------------
174+
175+
var processFaker = new ProcessFaker();
176+
177+
try {
178+
let platforms = ['win32', 'linux', 'darwin'];
179+
180+
// fake process.arch
181+
processFaker.fake('arch', { value: options.arch });
182+
183+
for (let i = 0, len = platforms.length; i < len; ++i) {
184+
// fake process.platform
185+
processFaker.fake('platform', { value: platforms[i] });
186+
187+
console.log(`downloading ${platforms[i]} imagemin binaries`);
188+
189+
// remove downloaded binaries,
190+
// and download to binaries for target platform
191+
yield setupBinaries(platforms[i], RELEASES_DIR);
192+
193+
console.log(`downloaded ${platforms[i]} imagemin binaries`);
194+
}
195+
} finally {
196+
// revert faked properties
197+
processFaker.unfake('arch');
198+
processFaker.unfake('platform');
199+
}
200+
}).then(function() {
201+
console.log('done');
202+
}).catch(function(err) {
203+
console.error('error:');
204+
console.error(err.stack);
205+
});

0 commit comments

Comments
 (0)