From 0d9f7aaab0e762b8b4f69812577ccbe6353b2523 Mon Sep 17 00:00:00 2001 From: Peter Bakondy Date: Mon, 8 Feb 2016 15:36:23 +0100 Subject: [PATCH] add environment variable for resources Use IONIC_RESOURCE_SITE environment variable if it is set for downloading outer resources (templates, default-resources, cordova-crosswalk-engine). It helps to setup and run ionic in an offline internal network. Idea: https://github.com/sass/node-sass/blob/fa40bda68e18f1a59051879ca5b973f2f 8aa976a/lib/extensions.js#L88-L92 --- lib/browser.js | 10 ++++++---- lib/resources.js | 3 ++- lib/start.js | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/browser.js b/lib/browser.js index 00c09e2..feda446 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -146,7 +146,8 @@ Browser.downloadCordovaCrosswalkEngine = function downloadCordovaCrosswalkEngine return q.promise; } - var downloadUrl = ['https://github.com/driftyco/cordova-crosswalk-engine/archive/', crosswalkEngineVersion, '.zip'].join(''); + var site = process.env.IONIC_RESOURCE_SITE || 'https://github.com/driftyco/'; + var downloadUrl = [site, 'cordova-crosswalk-engine/archive/', crosswalkEngineVersion, '.zip'].join(''); var tempZipFilePath = path.join(appDirectory, 'engine', 'cordova-crosswalk-engine.zip'); var zipOutPath = path.join(appDirectory, 'engine'); @@ -267,7 +268,8 @@ Browser.downloadCordova40x = function downloadCordova40x(appDirectory) { var q = Q.defer(); var crosswalkEngineUnzipName = ['cordova-android-', cordovaAndroidVersion].join(''); - var downloadUrl = ['https://github.com/driftyco/cordova-android/archive/', cordovaAndroidVersion, '.zip'].join(''); + var site = process.env.IONIC_RESOURCE_SITE || 'https://github.com/driftyco/'; + var downloadUrl = [site, 'cordova-android/archive/', cordovaAndroidVersion, '.zip'].join(''); var tempZipFilePath = path.join(appDirectory, 'engine'); var cordovaAndroid4Path = path.join(tempZipFilePath, crosswalkEngineUnzipName, 'bin'); @@ -451,7 +453,7 @@ Browser.installCrosswalk = function installCrosswalk(appDirectory, version, save return Q(cordovaMessage); } else if (semver.satisfies(info.cordova, '>=5.0.0')) { return Browser.installCordovaCrosswalk(appDirectory); - } + } logging.logger.info(('You are running Cordova CLI ' + info.cordova + ' - installing Cordova Android and Crosswalk manually').yellow.bold); @@ -570,7 +572,7 @@ Browser.saveBrowserInstallation = function saveBrowserInstallation(platform, bro Browser.addBrowser = function addBrowser(appDirectory, browserToInstall, saveToPackageJson) { - if (!appDirectory) { + if (!appDirectory) { throw 'You must pass a directory to run this command'; } diff --git a/lib/resources.js b/lib/resources.js index a965702..7836b82 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -910,7 +910,8 @@ function copyIconFilesIntoResources(appDirectory, forceAddResources) { return Q(); } - var ionicResourcesUrl = 'https://github.com/driftyco/ionic-default-resources/archive/master.zip'; + var site = process.env.IONIC_RESOURCE_SITE || 'https://github.com/driftyco/'; + var ionicResourcesUrl = site + 'ionic-default-resources/archive/master.zip'; logging.logger.debug('uzip to: ', unzipPath) logging.logger.info('Downloading Default Ionic Resources'.yellow); return Utils.fetchArchive(unzipPath, ionicResourcesUrl) diff --git a/lib/start.js b/lib/start.js index 75901df..07beef8 100644 --- a/lib/start.js +++ b/lib/start.js @@ -135,7 +135,8 @@ Start.fetchWrapper = function fetchWrapper(options) { var q = Q.defer(); // var self = this; - var repoUrl = 'https://github.com/driftyco/' + WRAPPER_REPO_NAME + '/archive/master.zip'; + var site = process.env.IONIC_RESOURCE_SITE || 'https://github.com/driftyco/'; + var repoUrl = site + WRAPPER_REPO_NAME + '/archive/master.zip'; Utils.fetchArchive(options.targetPath, repoUrl) .then(function() { @@ -462,7 +463,8 @@ Start.fetchIonicStarter = function(options) { var repoName = ['ionic-starter-', options.template].join('') // Get the URL for the starter project repo: - var repoUrl = ['https://github.com/driftyco/', repoName].join('') + var site = process.env.IONIC_RESOURCE_SITE || 'https://github.com/driftyco/'; + var repoUrl = [site, repoName].join('') return Start.fetchGithubStarter(options, repoUrl); };