Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ _ = require 'lodash'


platforms =
darwin: -> 'osx'
win: -> 'win'
win32: -> 'win'
win64: -> 'win'
darwin: -> 'osx' + if process.arch is 'ia32' then 32 else 64
osx: -> 'osx' + if process.arch is 'ia32' then 32 else 64
osx32: -> 'osx32'
osx64: -> 'osx64'
win: -> 'win' + if process.arch is 'ia32' then 32 else 64
win32: -> 'win32'
win64: -> 'win64'
linux: -> 'linux' + if process.arch is 'ia32' then 32 else 64

# Returns a {String}
Expand All @@ -19,13 +22,13 @@ normalizePlatform = (platform) ->

# args - {Object}
# :options - {Object} or {String}
# :platform - Optional {String}. One of the following: [osx, win, linux32, linux64]. If not passed, current
# :platform - Optional {String}. One of the following: [osx32, osx64, win32, win64, linux32, linux64]. If not passed, current
# platform is detected
# cb - {Function}. Called with Error and result arguments
# Returns an {String} or {Object}, depending on `objectMode` parameter
module.exports = (args, cb) ->
cb = (->) unless cb?
platform = if args.platform then normalizePlatform args.platform else detectPlatform()
platform = if args.platform then normalizePlatform args.platform else normalizePlatform detectPlatform()
objectMode = _.isPlainObject args.options

try
Expand Down
6 changes: 3 additions & 3 deletions test/expected/all/none.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"abc": [],
"def": {},
"platformOverrides": {
"win": {
"win32": {
"window": {
"frame": true
},
"x": ["z"],
"abc": [1],
"def": {"x":1}
},
"osx": {
"osx32": {
"main": "other.html",
"x": ["y", "z"],
"abc": 2
Expand All @@ -36,4 +36,4 @@
"x": []
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"x": ["y", "z"],
"abc": 2,
"def": {}
}
}
12 changes: 12 additions & 0 deletions test/expected/all/osx64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "nw-demo",
"version": "0.1.0",
"main": "other.html",
"window": {
"frame": false,
"toolbar": false
},
"x": ["y", "z"],
"abc": 2,
"def": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"x": ["z"],
"abc": [1],
"def": {"x":1}
}
}
12 changes: 12 additions & 0 deletions test/expected/all/win64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "nw-demo",
"version": "0.1.0",
"main": "index.html",
"window": {
"frame": true,
"toolbar": false
},
"x": ["z"],
"abc": [1],
"def": {"x":1}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"frame": true,
"toolbar": false
}
}
}
9 changes: 9 additions & 0 deletions test/expected/oneOveriddenRestNot/osx64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "nw-demo",
"version": "0.1.0",
"main": "index.html",
"window": {
"frame": true,
"toolbar": false
}
}
19 changes: 16 additions & 3 deletions test/fixtures/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@
"abc": [],
"def": {},
"platformOverrides": {
"win": {
"win32": {
"window": {
"frame": true
},
"x": ["z"],
"abc": [1],
"def": {"x":1}
},
"osx": {
"win64": {
"window": {
"frame": true
},
"x": ["z"],
"abc": [1],
"def": {"x":1}
},
"osx32": {
"main": "other.html",
"x": ["y", "z"],
"abc": 2
},
"osx64": {
"main": "other.html",
"x": ["y", "z"],
"abc": 2
Expand All @@ -36,4 +49,4 @@
"x": []
}
}
}
}
4 changes: 2 additions & 2 deletions test/fixtures/oneOveriddenRestNot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"toolbar": false
},
"platformOverrides": {
"osx": {
"osx32": {
"window": {
"frame": true
}
}
}
}
}
14 changes: 7 additions & 7 deletions test/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ getExpected = (pathSegment, basename) ->

describe 'platform-overrides', ->
it 'should apply overrides correctly for each platform', ->
for platform in ['osx', 'win', 'linux32', 'linux64']
for platform in ['osx32', 'osx64', 'win32', 'win64', 'linux32', 'linux64']
args =
options: getFixture 'all/package.json'
platform: platform
Expand All @@ -29,10 +29,10 @@ describe 'platform-overrides', ->

platformOverrides args, (err, result) ->
expect(result).to.be.a 'string'
expect(JSON.parse result).to.deep.equal JSON.parse getExpected 'all', 'win'
expect(JSON.parse result).to.deep.equal JSON.parse getExpected 'all', 'win32'

it 'should support passing an object and then return an object', ->
for platform in ['osx', 'win', 'linux32', 'linux64']
for platform in ['osx32', 'osx64', 'win32', 'win64', 'linux32', 'linux64']
args =
options: JSON.parse getFixture 'all/package.json'
platform: platform
Expand All @@ -53,19 +53,19 @@ describe 'platform-overrides', ->


it 'should apply overrides correctly for appropriate platforms and strip platformOverrides regardless', ->
for platform in ['osx', 'win', 'linux32', 'linux64']
for platform in ['osx32', 'osx64', 'win32', 'win64', 'linux32', 'linux64']
args =
options: getFixture 'oneOveriddenRestNot/package.json'
platform: platform

platformOverrides args, (err, result) ->
expect(JSON.parse result).to.deep.equal JSON.parse getExpected(
'oneOveriddenRestNot',
if platform is 'osx' then platform else 'rest'
if platform is 'osx32' then platform else 'rest'
)

it 'should leave file as is if platformOverrides does not exist', ->
for platform in ['osx', 'win', 'linux32', 'linux64']
for platform in ['osx32', 'osx64', 'win32', 'win64', 'linux32', 'linux64']
contents = getFixture 'none/package.json'
args =
options: contents
Expand All @@ -80,4 +80,4 @@ describe 'platform-overrides', ->

platformOverrides args, (err, result) ->
expect(err instanceof Error).to.equal true
expect(result).to.equal null
expect(result).to.equal null