Skip to content

Commit

Permalink
add assets
Browse files Browse the repository at this point in the history
  • Loading branch information
matianfu-wisnuc committed Sep 26, 2016
1 parent 43dba91 commit 82427de
Show file tree
Hide file tree
Showing 11 changed files with 491 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ public/bundle.js
# release folder
release/

# appifi.js
appifi.js
assets/
xxhash.node
xattr.node

#

family/
fruitfiles/
tmpTestFoder/
Expand Down
78 changes: 78 additions & 0 deletions assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
var fs = require('fs')

let xxhashBase64, xxhash, xattrBase64, xattr, bundlejs, indexHtml, robotoCSS, styleCSS,
robotoThinBase64, robotoThin, robotoLightBase64, robotoLight,
robotoRegularBase64, robotoRegular, robotoMediumBase64, robotoMedium,
robotoBoldBase64, robotoBold, robotoBlackBase64, robotoBlack

if (global.WEBPACK) {

xxhashBase64 = require('raw!./assets/xxhash.node.base64')
xattrBase64 = require('raw!./assets/xattr.node.base64')

robotoThinBase64 = require('raw!./assets/robotoThin.base64')
robotoLightBase64 = require('raw!./assets/robotoLight.base64')
robotoRegularBase64 = require('raw!./assets/robotoRegular.base64')
robotoMediumBase64 = require('raw!./assets/robotoMedium.base64')
robotoBoldBase64 = require('raw!./assets/robotoBold.base64')
robotoBlackBase64 = require('raw!./assets/robotoBlack.base64')

bundlejs = require('raw!./assets/bundle.js.raw')
indexHtml = require('raw!./assets/index.html.raw')

robotoCSS = require('raw!./assets/roboto.css.raw')
styleCSS = require('raw!./assets/style.css.raw')
}

if (xxhashBase64) {
let decode = Buffer.from(xxhashBase64.toString(), 'base64')
fs.writeFileSync('./xxhash.node', decode)
xxhash = require('xxhash')

console.log('hash hash')
console.log(xxhash.hash(Buffer.from('hello'), 1234))
}

if (xattrBase64) {
let decode = Buffer.from(xattrBase64.toString(), 'base64')
fs.writeFileSync('./xattr.node', decode)
}

function loadFont (base64, name) {
if (base64)
return Buffer.from(base64, 'base64')
else
return fs.readFileSync('./public/stylesheets/Roboto-' + name + '-webfont.woff')
}

robotoThin = loadFont(robotoThinBase64, 'Thin')
robotoLight = loadFont(robotoLightBase64, 'Light')
robotoRegular = loadFont(robotoRegularBase64, 'Regular')
robotoMedium = loadFont(robotoMediumBase64, 'Medium')
robotoBold = loadFont(robotoBoldBase64, 'Bold')
robotoBlack = loadFont(robotoBlackBase64, 'Black')

if (!bundlejs) {
bundlejs = fs.readFileSync('./public/bundle.js').toString()
}

if (!indexHtml) {
indexHtml = fs.readFileSync('./public/index.html').toString()
}

if (!robotoCSS) {
robotoCSS = fs.readFileSync('./public/stylesheets/roboto.css')
}

if (!styleCSS) {
styleCSS = fs.readFileSync('./public/stylesheets/style.css')
}

console.log('assets loaded')

module.exports = {
bundlejs, indexHtml, robotoCSS, styleCSS,
robotoThin, robotoLight, robotoRegular, robotoMedium, robotoBold, robotoBlack
}

setTimeout(() => require('./src/app'), 1000)
28 changes: 21 additions & 7 deletions backpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {

// base dir for resolving entry option
context: __dirname,
entry: ['./build/app'],
entry: ['./assets.js'],
node: {
__filename: false,
__dirname: false,
Expand All @@ -19,21 +19,35 @@ module.exports = {
},

externals: {
// "body-parser": "commonjs body-parser",
// "express": "commonjs express",
"fs-xattr": "commonjs fs-xattr",
"xxhash": "commonjs xxhash"
"../build/Release/hash": "commonjs ./xxhash.node",
"./build/Release/xattr": "commonjs ./xattr.node",
},

module: {
preLoaders: [
{ test: /\.json$/, loader: 'json' },
{ test: /\.node$/, loader: 'node' },
],

loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'bluebird'],
plugins: [
"transform-async-to-bluebird",
"transform-promise-to-bluebird",
"transform-runtime"
]
}
}
]
},

plugins: [
new webpack.DefinePlugin({ "global.GENTLY": false })
new webpack.DefinePlugin({ "global.GENTLY": false }),
new webpack.DefinePlugin({ "global.WEBPACK": true })
],
}

45 changes: 39 additions & 6 deletions backpack.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
var webpack = require('webpack')
var fs = require('fs')
var child = require('child_process')

var config = require('./backpack.config')
const commands = [

// clean
'rm -rf assets',

// mkdir
'mkdir assets',

// patch body-parser
'cp patch/body-parser/1.13.3/urlencoded.js node_modules/body-parser/lib/types/urlencoded.js',

// xattr bin
'base64 node_modules/fs-xattr/build/Release/xattr.node > assets/xattr.node.base64',

// xxhash bin
'base64 node_modules/xxhash/build/Release/hash.node > assets/xxhash.node.base64',

// fonts
'base64 public/stylesheets/Roboto-Thin-webfont.woff > assets/robotoThin.base64',
'base64 public/stylesheets/Roboto-Light-webfont.woff > assets/robotoLight.base64',
'base64 public/stylesheets/Roboto-Regular-webfont.woff > assets/robotoRegular.base64',
'base64 public/stylesheets/Roboto-Medium-webfont.woff > assets/robotoMedium.base64',
'base64 public/stylesheets/Roboto-Bold-webfont.woff > assets/robotoBold.base64',
'base64 public/stylesheets/Roboto-Black-webfont.woff > assets/robotoBlack.base64',

// other assets
'cp public/index.html assets/index.html.raw',
'cp public/bundle.js assets/bundle.js.raw',
'cp public/stylesheets/roboto.css assets/roboto.css.raw',
'cp public/stylesheets/style.css assets/style.css.raw',
]

child.spawnSync('node_modules/.bin/webpack', ['--config', 'webpack.config.js', '-p'], { stdio: 'inherit' })

commands.forEach(item => child.execSync(item))

child.spawnSync('node_modules/.bin/webpack', ['--config', 'backpack.config.js', '-p'], { stdio: 'inherit' })

compiler = webpack(config)
compiler.run((err, stats) => {
console.log(err || stats)
})
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "node build/app.js",
"build": "babel src --out-dir build",
"devel": "nodemon --exec babel-node --ignore web --ignore public/bundle.js src/app.js",
"devel-assets": "nodemon --exec babel-node --ignore web --ignore public/bundle.js assets.js",
"devel-appstore": "nodemon --exec babel-node --ignore web --ignore public/bundle.js src/app.js --appstore-master",
"webpack": "webpack --watch --watch-poll",
"unit": "node_modules/.bin/mocha --compilers js:babel-core/register --recursive test",
Expand Down Expand Up @@ -33,11 +34,10 @@
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-0": "^6.5.0",
"bcryptjs": "^2.3.0",
"binary-loader": "0.0.1",
"bluebird": "^3.4.1",
"body-parser": "~1.13.2",
"bonjour": "^3.5.0",
"body-parser": "1.13.3",
"canonical-json": "0.0.4",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
Expand All @@ -51,6 +51,7 @@
"eslint": "^2.10.2",
"eslint-plugin-react": "^5.1.1",
"express": "~4.13.1",
"file-loader": "^0.9.0",
"filter-object": "^2.1.0",
"fs-xattr": "^0.1.14",
"json-loader": "^0.5.4",
Expand All @@ -65,6 +66,7 @@
"passport": "^0.3.2",
"passport-http": "^0.3.0",
"passport-jwt": "^2.1.0",
"raw-loader": "^0.5.1",
"react": "^15.2.1",
"react-addons-css-transition-group": "^15.2.0",
"react-click-outside": "^2.1.0",
Expand Down
Loading

0 comments on commit 82427de

Please sign in to comment.