Skip to content

Commit 8e44a42

Browse files
committed
switch npm scripts with Grunt task
1 parent 7f4ccdc commit 8e44a42

5 files changed

Lines changed: 188 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/*
33
!node_modules/boost
44
dist/
55
compiled
6+
/secret

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
本製品をインストール、または使用することによって、お客様は利用規約(
2+
https://b00st.io/regulations.html)より拘束されることに承諾されたものとします。利用規約に同意されない場合、Boostnoteは、お客様に本製品のインストール、使用のいずれも許諾できません。

gruntfile.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
const path = require('path')
2+
const ChildProcess = require('child_process')
3+
const packager = require('electron-packager')
4+
const archiver = require('archiver')
5+
const fs = require('fs')
6+
7+
module.exports = function (grunt) {
8+
9+
// Project configuration.
10+
grunt.initConfig({
11+
pkg: grunt.file.readJSON('package.json'),
12+
auth_code: grunt.file.readJSON('secret/auth_code.json'),
13+
'create-windows-installer': {
14+
x64: {
15+
appDirectory: path.join(__dirname, 'dist', 'Boostnote-win32-x64'),
16+
outputDirectory: path.join(__dirname, 'dist'),
17+
authors: 'MAISIN&CO., Inc.',
18+
exe: 'Boostnote.exe',
19+
loadingGif: path.join(__dirname, 'resources/install.gif'),
20+
iconUrl: path.join(__dirname, 'resources/app.ico'),
21+
setupIcon: path.join(__dirname, 'resources/dmg.ico'),
22+
certificateFile: grunt.config.get('auth_code.win_cert_path'),
23+
certificatePassword: grunt.config.get('auth_code.win_cert_pw'),
24+
noMsi: true,
25+
remoteReleases: 'https://github.com/BoostIO/boost-releases/releases/download/v0.4.10/'
26+
}
27+
}
28+
})
29+
grunt.loadNpmTasks('grunt-electron-installer')
30+
31+
grunt.registerTask('compile', function () {
32+
var done = this.async()
33+
var execPath = path.join('node_modules', '.bin', 'webpack') + ' --config webpack.config.production.js'
34+
grunt.log.writeln(execPath)
35+
var compileProcess = ChildProcess.exec(execPath,
36+
{
37+
env: Object.assign({}, process.env, {
38+
BABEL_ENV: 'production'
39+
})
40+
}, function (err, stdout, stderr) {
41+
grunt.log.writeln(stdout)
42+
if (err) {
43+
grunt.log.writeln(err)
44+
grunt.log.writeln(stderr)
45+
done(false)
46+
return
47+
}
48+
done()
49+
})
50+
})
51+
52+
grunt.registerTask('zip', function (platform) {
53+
var done = this.async()
54+
var archive = archiver.create('zip', {})
55+
switch (platform) {
56+
case 'win':
57+
archive.file(path.join('dist/Setup.exe'), { name:'Boostnote-installer-win32-x64.exe' })
58+
default:
59+
done()
60+
return
61+
}
62+
archive.finalize()
63+
var writeStream = fs.createWriteStream(path.join('dist/Boostnote-installer-win32-x64.zip'))
64+
archive.pipe(writeStream)
65+
writeStream.on('close', function () {
66+
grunt.log.writeln('Zipped!')
67+
done()
68+
})
69+
})
70+
71+
grunt.registerTask('pack', function (platform) {
72+
grunt.log.writeln(path.join(__dirname, 'dist'))
73+
var done = this.async()
74+
var opts = {
75+
name: 'Boostnote',
76+
arch: 'x64',
77+
dir: __dirname,
78+
version: '0.35.4',
79+
'app-version': grunt.config.get('pkg.version'),
80+
'app-bundle-id': 'com.maisin.boost',
81+
asar: true,
82+
prune: true,
83+
overwrite: true,
84+
out: path.join(__dirname, 'dist'),
85+
ignore: /submodules\/ace\/(?!src-min)|submodules\/ace\/(?=src-min-noconflict)|node_modules\/devicon\/icons|dist|.env/
86+
}
87+
switch (platform) {
88+
case 'win':
89+
Object.assign(opts, {
90+
platform: 'win32',
91+
icon: path.join(__dirname, 'resources/app.ico'),
92+
'version-string': {
93+
CompanyName: 'MAISIN&CO., Inc.',
94+
LegalCopyright: '© 2015 MAISIN&CO., Inc. All rights reserved.',
95+
FileDescription: 'Boostnote',
96+
OriginalFilename: 'Boostnote',
97+
FileVersion: grunt.config.get('pkg.version'),
98+
ProductVersion: grunt.config.get('pkg.version'),
99+
ProductName: 'Boostnote',
100+
InternalName: 'Boostnote'
101+
}
102+
})
103+
packager(opts, function (err, appPath) {
104+
if (err) {
105+
grunt.log.writeln(err)
106+
done(err)
107+
return
108+
}
109+
done()
110+
})
111+
break
112+
case 'osx':
113+
Object.assign(opts, {
114+
platform: 'darwin',
115+
icon: path.join(__dirname, 'resources/app.icns'),
116+
'app-category-type': 'public.app-category.developer-tools'
117+
})
118+
packager(opts, function (err, appPath) {
119+
if (err) {
120+
grunt.log.writeln(err)
121+
done(err)
122+
return
123+
}
124+
done()
125+
})
126+
break
127+
}
128+
})
129+
130+
grunt.registerTask('build', function (platform) {
131+
if (!platform) {
132+
platform = process.platform === 'darwin' ? 'osx' : process.platform === 'win32' ? 'win' : null
133+
}
134+
switch (platform) {
135+
case 'win':
136+
grunt.task.run(['pack:win', 'create-windows-installer', 'zip:win'])
137+
}
138+
})
139+
// Default task(s).
140+
grunt.registerTask('default', ['build'])
141+
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
"name": "boost",
33
"version": "0.4.6",
4-
"description": "Boost App",
4+
"description": "Boostnote",
55
"main": "index.js",
66
"scripts": {
77
"start": "electron ./index.js",
88
"hot": "electron ./index.js --hot",
99
"webpack": "webpack-dev-server --hot --inline --config webpack.config.js",
10-
"compile": "webpack --config webpack.config.production.js",
11-
"pack:osx": "electron-packager ./ Boost --app-version=$npm_package_version $npm_package_config_platform $npm_package_config_version $npm_package_config_ignore --overwrite --out=\"dist\"",
1210
"codesign": "codesign --verbose --deep --force --sign \"MAISIN solutions Inc.\" dist/Boost-darwin-x64/Boost.app",
1311
"build:osx": "electron-builder \"dist/Boost-darwin-x64/Boost.app\" --platform=osx --out=\"dist\" --config=\"./builder-config.json\"",
1412
"release": "electron-release --app=\"dist/Boost-darwin-x64/Boost.app\" --token=$(cat .env/.github-token) --repo=\"BoostIO/boost-releases\""
@@ -55,12 +53,15 @@
5553
"superagent-promise": "^1.0.3"
5654
},
5755
"devDependencies": {
56+
"archiver": "^0.20.0",
5857
"babel-loader": "^5.3.2",
5958
"babel-plugin-react-transform": "^1.1.1",
6059
"css-loader": "^0.19.0",
6160
"electron-packager": "^5.1.0",
6261
"electron-prebuilt": "^0.35.1",
6362
"electron-release": "^2.2.0",
63+
"grunt": "^0.4.5",
64+
"grunt-electron-installer": "^1.2.0",
6465
"nib": "^1.1.0",
6566
"react": "^0.14.0",
6667
"react-dom": "^0.14.0",

webpack.config.production.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
var webpack = require('webpack')
2-
module.exports = {
3-
entry: {
4-
main: './browser/main/index.js',
5-
finder: './browser/finder/index.js'
6-
},
7-
output: {
8-
path: 'compiled',
9-
filename: '[name].js',
10-
// sourceMapFilename: '[name].map',
11-
libraryTarget: 'commonjs2'
12-
},
2+
var path = require('path')
3+
var JsonpTemplatePlugin = webpack.JsonpTemplatePlugin
4+
var FunctionModulePlugin = require('webpack/lib/FunctionModulePlugin')
5+
var NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin')
6+
7+
var opt = {
8+
path: path.join(__dirname, 'compiled'),
9+
filename: '[name].js',
10+
sourceMapFilename: '[name].map',
11+
libraryTarget: 'commonjs2',
12+
publicPath: 'http://localhost:8080/assets/'
13+
}
14+
15+
config = {
1316
module: {
1417
loaders: [
1518
{
@@ -24,11 +27,26 @@ module.exports = {
2427
}
2528
]
2629
},
30+
entry: {
31+
main: './browser/main/index.js',
32+
finder: './browser/finder/index.js'
33+
},
34+
output: opt,
35+
resolve: {
36+
extensions: ['', '.js', '.jsx'],
37+
packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main'],
38+
alias: {
39+
'boost': path.resolve(__dirname, 'lib')
40+
}
41+
},
2742
plugins: [
43+
new webpack.NoErrorsPlugin(),
44+
new NodeTargetPlugin(),
2845
new webpack.optimize.OccurenceOrderPlugin(),
2946
new webpack.DefinePlugin({
3047
'process.env': {
31-
'NODE_ENV': JSON.stringify('production')
48+
'NODE_ENV': JSON.stringify('production'),
49+
'BABEL_ENV': JSON.stringify('production')
3250
}
3351
}),
3452
new webpack.optimize.UglifyJsPlugin({
@@ -49,8 +67,14 @@ module.exports = {
4967
'highlight.js',
5068
'markdown-it-emoji',
5169
'fs-jetpack'
52-
],
53-
resolve: {
54-
extensions: ['', '.js', '.jsx', 'styl']
55-
}
70+
]
71+
}
72+
73+
config.target = function renderer (compiler) {
74+
compiler.apply(
75+
new JsonpTemplatePlugin(opt),
76+
new FunctionModulePlugin(opt)
77+
)
5678
}
79+
80+
module.exports = config

0 commit comments

Comments
 (0)