diff --git a/dependencies.list b/dependencies.list index 4e019f61..1fdb2268 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-js VERSION=1.8.3 -REALM_CORE_VERSION=3.0.0-rc2 -REALM_SYNC_VERSION=2.0.0-rc10 +REALM_CORE_VERSION=3.0.0-rc3 +REALM_SYNC_VERSION=2.0.0-rc11 REALM_OBJECT_SERVER_VERSION=2.0.0-alpha9 diff --git a/package.json b/package.json index 04d5d1b3..f5a52dd9 100644 --- a/package.json +++ b/package.json @@ -78,11 +78,12 @@ "check-environment": "node scripts/check-environment.js" }, "dependencies": { - "extract-zip": "^1.6.0", + "command-line-args": "^4.0.6", + "decompress": "^4.2.0", "ini": "^1.3.4", "nan": "^2.3.3", "node-fetch": "^1.6.3", - "node-pre-gyp": "^0.6.30", + "node-pre-gyp": "^0.6.36", "request": "^2.78.0", "sync-request": "^3.0.1", "url-parse": "^1.1.7" diff --git a/realm.gypi b/realm.gypi index cb49897d..4ee0960a 100644 --- a/realm.gypi +++ b/realm.gypi @@ -116,27 +116,13 @@ "<(module_root_dir)/vendor/realm-node/osx" ] }, - "conditions": [ - ["realm_download_binaries and OS=='win'", { - "actions": [ - { - "action_name": "download-realm", - "inputs": [ "<(module_root_dir)/scripts/download-realm.js" ], - "outputs": [ "<(module_root_dir)/vendor/realm-node" ], - "action": [ "node", "<(module_root_dir)/scripts/download-realm.js", "node", "<(use_realm_debug)" ] - } - ] - }], - ["realm_download_binaries and OS!='win'", { - "actions": [ - { - "action_name": "download-realm", - "inputs": [ ], - "outputs": [ "<(module_root_dir)/vendor/realm-node" ], - "action": [ "<(module_root_dir)/scripts/download-core.sh", "node", "<(realm_enable_sync)" ] - } - ] - }] + "actions": [ + { + "action_name": "download-realm", + "inputs": [ "<(module_root_dir)/scripts/download-realm.js" ], + "outputs": [ "<(module_root_dir)/vendor/realm-node" ], + "action": [ "node", "<(module_root_dir)/scripts/download-realm.js", "<(OS)", "--debug=<(use_realm_debug)", "--sync=<(realm_enable_sync)", "--arch=<(target_arch)" ] + } ] } ] diff --git a/scripts/download-realm.js b/scripts/download-realm.js index 5e9516a3..e128b717 100644 --- a/scripts/download-realm.js +++ b/scripts/download-realm.js @@ -22,46 +22,55 @@ const fs = require('fs'); const path = require('path'); const fetch = require('node-fetch'); const ini = require('ini').parse; -const unzip = require('extract-zip'); +const decompress = require('decompress'); function download(url, destination) { return fetch(url).then((response) => { if (response.status !== 200) { throw new Error(`Error downloading ${url} - received status ${response.status} ${response.statusText}`); - } else if (response.headers.get('content-type') !== 'application/zip') { - throw new Error(`Unexpected response content type - ${response.headers.get('content-type')}`); - } else { - return new Promise((resolve) => { - const file = fs.createWriteStream(destination); - response.body.pipe(file) - .on('finish', () => { - file.close(resolve); - }); - }); } - }); -} -function extract(archive, destination) { - return new Promise((resolve, reject) => { - unzip(archive, { dir: destination }, (error) => { - if (error) { - reject(error); - } else { - resolve(); - } + return new Promise((resolve) => { + const file = fs.createWriteStream(destination); + response.body.pipe(file) + .on('finish', () => { + file.close(resolve); + }); }); }); } +const optionDefinitions = [ + { name: 'platform', type: String, defaultOption: true }, + { name: 'arch', type: String }, + { name: 'sync', type: Boolean }, + { name: 'debug', type: Boolean }, +]; +const options = require('command-line-args')(optionDefinitions); + +console.log(options); + +let product, archive, extractedFolder; + const dependencies = ini(fs.readFileSync(path.resolve(__dirname, '../dependencies.list'), 'utf8')); -const coreArchive = `realm-core-windows-${dependencies.REALM_CORE_VERSION}.zip`; -const coreUrl = `https://static.realm.io/downloads/core/${coreArchive}`; +if (!options.sync) { + throw new Error("Downloading core is not yet supported!"); +} else { + product = 'sync'; + switch (options.platform) { + case 'mac': + archive = `realm-sync-node-cocoa-${dependencies.REALM_SYNC_VERSION}.tar.gz` + extractedFolder = `realm-sync-node-cocoa-${dependencies.REALM_SYNC_VERSION}` + } +} + +const url = `https://static.realm.io/downloads/${product}/${archive}`; const vendorDir = path.resolve(__dirname, '../vendor'); -const downloadedCoreArchive = path.resolve(vendorDir, coreArchive); +const downloadedArchive = path.resolve(vendorDir, archive); const realmDir = path.resolve(vendorDir, 'realm-node'); if (!fs.existsSync(realmDir)) { - const downloadTask = fs.existsSync(downloadedCoreArchive) ? Promise.resolve() : download(coreUrl, downloadedCoreArchive); - downloadTask.then(() => extract(downloadedCoreArchive, realmDir)); + const downloadTask = fs.existsSync(downloadedArchive) ? Promise.resolve() : download(url, downloadedArchive); + downloadTask.then(() => decompress(downloadedArchive, vendorDir)) + .then(() => fs.renameSync(path.resolve(vendorDir, extractedFolder), realmDir)); } \ No newline at end of file diff --git a/target_defaults.gypi b/target_defaults.gypi index e5477d9d..962f9f8f 100644 --- a/target_defaults.gypi +++ b/target_defaults.gypi @@ -43,16 +43,14 @@ "Debug": { "msvs_settings": { "VCCLCompilerTool": { - "RuntimeTypeInfo": "true", - "AdditionalOptions": [ "/MDd" ] + "RuntimeTypeInfo": "true" }, } }, "Release": { "msvs_settings": { "VCCLCompilerTool": { - "RuntimeTypeInfo": "true", - "AdditionalOptions": [ "/MD" ] + "RuntimeTypeInfo": "true" }, } }