From 5b7d6b076860512c626343dd6d80795b56dece56 Mon Sep 17 00:00:00 2001 From: Dan Wolfe Date: Tue, 25 Nov 2014 11:07:29 -0500 Subject: [PATCH] Adding normalization to osx32, osx64, win32, and win64. Work to support changes in https://github.com/mllrsohn/node-webkit-builder/pull/117 --- index.coffee | 15 +++++++++------ test/expected/all/none.json | 6 +++--- test/expected/all/{osx.json => osx32.json} | 2 +- test/expected/all/osx64.json | 12 ++++++++++++ test/expected/all/{win.json => win32.json} | 2 +- test/expected/all/win64.json | 12 ++++++++++++ .../{osx.json => osx32.json} | 2 +- test/expected/oneOveriddenRestNot/osx64.json | 9 +++++++++ test/fixtures/all/package.json | 19 ++++++++++++++++--- .../fixtures/oneOveriddenRestNot/package.json | 4 ++-- test/index.coffee | 14 +++++++------- 11 files changed, 73 insertions(+), 24 deletions(-) rename test/expected/all/{osx.json => osx32.json} (98%) create mode 100644 test/expected/all/osx64.json rename test/expected/all/{win.json => win32.json} (98%) create mode 100644 test/expected/all/win64.json rename test/expected/oneOveriddenRestNot/{osx.json => osx32.json} (98%) create mode 100644 test/expected/oneOveriddenRestNot/osx64.json diff --git a/index.coffee b/index.coffee index 02b6181..41e558a 100644 --- a/index.coffee +++ b/index.coffee @@ -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} @@ -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 diff --git a/test/expected/all/none.json b/test/expected/all/none.json index 39645f0..3e73b03 100644 --- a/test/expected/all/none.json +++ b/test/expected/all/none.json @@ -10,7 +10,7 @@ "abc": [], "def": {}, "platformOverrides": { - "win": { + "win32": { "window": { "frame": true }, @@ -18,7 +18,7 @@ "abc": [1], "def": {"x":1} }, - "osx": { + "osx32": { "main": "other.html", "x": ["y", "z"], "abc": 2 @@ -36,4 +36,4 @@ "x": [] } } -} \ No newline at end of file +} diff --git a/test/expected/all/osx.json b/test/expected/all/osx32.json similarity index 98% rename from test/expected/all/osx.json rename to test/expected/all/osx32.json index 4263712..d5540fe 100644 --- a/test/expected/all/osx.json +++ b/test/expected/all/osx32.json @@ -9,4 +9,4 @@ "x": ["y", "z"], "abc": 2, "def": {} -} \ No newline at end of file +} diff --git a/test/expected/all/osx64.json b/test/expected/all/osx64.json new file mode 100644 index 0000000..d5540fe --- /dev/null +++ b/test/expected/all/osx64.json @@ -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": {} +} diff --git a/test/expected/all/win.json b/test/expected/all/win32.json similarity index 98% rename from test/expected/all/win.json rename to test/expected/all/win32.json index 895b464..4f31af4 100644 --- a/test/expected/all/win.json +++ b/test/expected/all/win32.json @@ -9,4 +9,4 @@ "x": ["z"], "abc": [1], "def": {"x":1} -} \ No newline at end of file +} diff --git a/test/expected/all/win64.json b/test/expected/all/win64.json new file mode 100644 index 0000000..4f31af4 --- /dev/null +++ b/test/expected/all/win64.json @@ -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} +} diff --git a/test/expected/oneOveriddenRestNot/osx.json b/test/expected/oneOveriddenRestNot/osx32.json similarity index 98% rename from test/expected/oneOveriddenRestNot/osx.json rename to test/expected/oneOveriddenRestNot/osx32.json index 7c08f00..3d5d89b 100644 --- a/test/expected/oneOveriddenRestNot/osx.json +++ b/test/expected/oneOveriddenRestNot/osx32.json @@ -6,4 +6,4 @@ "frame": true, "toolbar": false } -} \ No newline at end of file +} diff --git a/test/expected/oneOveriddenRestNot/osx64.json b/test/expected/oneOveriddenRestNot/osx64.json new file mode 100644 index 0000000..3d5d89b --- /dev/null +++ b/test/expected/oneOveriddenRestNot/osx64.json @@ -0,0 +1,9 @@ +{ + "name": "nw-demo", + "version": "0.1.0", + "main": "index.html", + "window": { + "frame": true, + "toolbar": false + } +} diff --git a/test/fixtures/all/package.json b/test/fixtures/all/package.json index 39645f0..96ff5de 100644 --- a/test/fixtures/all/package.json +++ b/test/fixtures/all/package.json @@ -10,7 +10,7 @@ "abc": [], "def": {}, "platformOverrides": { - "win": { + "win32": { "window": { "frame": true }, @@ -18,7 +18,20 @@ "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 @@ -36,4 +49,4 @@ "x": [] } } -} \ No newline at end of file +} diff --git a/test/fixtures/oneOveriddenRestNot/package.json b/test/fixtures/oneOveriddenRestNot/package.json index c566430..3f5ec0e 100644 --- a/test/fixtures/oneOveriddenRestNot/package.json +++ b/test/fixtures/oneOveriddenRestNot/package.json @@ -7,10 +7,10 @@ "toolbar": false }, "platformOverrides": { - "osx": { + "osx32": { "window": { "frame": true } } } -} \ No newline at end of file +} diff --git a/test/index.coffee b/test/index.coffee index bec63a9..335f4c5 100644 --- a/test/index.coffee +++ b/test/index.coffee @@ -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 @@ -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 @@ -53,7 +53,7 @@ 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 @@ -61,11 +61,11 @@ describe 'platform-overrides', -> 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 @@ -80,4 +80,4 @@ describe 'platform-overrides', -> platformOverrides args, (err, result) -> expect(err instanceof Error).to.equal true - expect(result).to.equal null \ No newline at end of file + expect(result).to.equal null