You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by bi...@apache.org on 2016/04/07 09:24:17 UTC

[2/5] git commit: [flex-utilities] [refs/heads/develop] - Add FlatUI dependency download (optional)

Add FlatUI dependency download (optional)


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/e6963007
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/e6963007
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/e6963007

Branch: refs/heads/develop
Commit: e696300772997136985f3f2a8e4b912f39a7abca
Parents: f38731f
Author: OmPrakash Muppirala <bi...@gmail.com>
Authored: Wed Apr 6 17:53:32 2016 -0700
Committer: OmPrakash Muppirala <bi...@gmail.com>
Committed: Thu Apr 7 00:21:02 2016 -0700

----------------------------------------------------------------------
 npm-flexjs/dependencies/FlatUI.js | 130 +++++++++++++++++++++++++++++++++
 1 file changed, 130 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e6963007/npm-flexjs/dependencies/FlatUI.js
----------------------------------------------------------------------
diff --git a/npm-flexjs/dependencies/FlatUI.js b/npm-flexjs/dependencies/FlatUI.js
new file mode 100644
index 0000000..983d96a
--- /dev/null
+++ b/npm-flexjs/dependencies/FlatUI.js
@@ -0,0 +1,130 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+
+var request = require('request');
+var fs = require('fs');
+var events = require('events');
+var unzip = require('unzip');
+var mkdirp = require('mkdirp');
+var pjson = require('../package');
+var prompt = require('prompt');
+
+var constants = require('../dependencies/Constants');
+
+var FlatUI = module.exports = Object.create(events.EventEmitter.prototype);
+
+//FlatUI
+var flatUIURL = pjson.org_apache_flex.flatui_url;
+var fileNameFlatUI = pjson.org_apache_flex.flatui_file_name;
+var promptText =
+"Apache FlexJS includes an optional component set\n\
+that uses fonts from designmodo.com.  The font\n\
+files are subject to and governed by the\n\
+Creative Commons Attribution-NonCommercial-NoDerivs 3.0\n\
+Unported license: http://creativecommons.org/licenses/by-nc-nd/3.0/\n\
+This license is not compatible with the Apache v2 license.\n\
+Do you want to install the designmodo fonts?\n\
+This is an optional component (y/n)";
+
+FlatUI.prompt = function()
+{
+    var schema = {
+        properties: {
+            accept: {
+                description: promptText.yellow,
+                pattern: /^[YNyn\s]{1}$/,
+                message: 'Please respond with either y or n'.red,
+                required: true
+            }
+        }
+    };
+    prompt.start();
+    prompt.get(schema, function (err, result) {
+        if(result.accept.toLowerCase() == 'y')
+        {
+            FlatUI.downloadFlatUI();
+        }
+        else
+        {
+            console.log('Skipping FlatUI installation');
+            FlatUI.emit('complete');
+        }
+    });
+};
+
+FlatUI.downloadFlatUI = function()
+{
+    console.log('Downloading FlatUI');
+    request
+        .get(flatUIURL + fileNameFlatUI)
+        .pipe(fs.createWriteStream(constants.DOWNLOADS_FOLDER + fileNameFlatUI)
+            .on('finish', function(){
+                console.log('FlatUI download complete');
+                extract();
+            })
+        );
+};
+
+function extract()
+{
+    var fontsDir = 'frameworks/fonts/';
+    try
+    {
+        mkdirp(constants.FLEXJS_FOLDER + fontsDir);
+    }
+    catch(e)
+    {
+        if ( e.code != 'EEXIST' ) throw e;
+    }
+    console.log('Extracting FlatUI');
+    fs.createReadStream(constants.DOWNLOADS_FOLDER + fileNameFlatUI)
+        .pipe(unzip.Parse())
+        .on('entry', function (entry) {
+            var fileName = entry.path;
+            if (fileName === 'Flat-UI-2.2.2/fonts/glyphicons/flat-ui-icons-regular.eot') {
+                entry.pipe(fs.createWriteStream(constants.FLEXJS_FOLDER + fontsDir + 'flat-ui-icons-regular.eot'));
+            }
+            else if (fileName === 'Flat-UI-2.2.2/fonts/glyphicons/flat-ui-icons-regular.ttf') {
+                entry.pipe(fs.createWriteStream(constants.FLEXJS_FOLDER + fontsDir + 'flat-ui-icons-regular.ttf'));
+            }
+            else if (fileName === 'Flat-UI-2.2.2/fonts/glyphicons/flat-ui-icons-regular.svg') {
+                entry.pipe(fs.createWriteStream(constants.FLEXJS_FOLDER + fontsDir + 'flat-ui-icons-regular.svg'));
+            }
+            else if (fileName === 'Flat-UI-2.2.2/fonts/glyphicons/flat-ui-icons-regular.woff') {
+                entry.pipe(fs.createWriteStream(constants.FLEXJS_FOLDER + fontsDir + 'flat-ui-icons-regular.woff'));
+            }
+            else if (fileName === 'Flat-UI-2.2.2/README.md') {
+                entry.pipe(fs.createWriteStream(constants.FLEXJS_FOLDER + fontsDir + 'README.md'));
+            }
+            else {
+                entry.autodrain();
+            }
+        })
+        .on('finish', function(){
+            console.log('FlatUI extraction complete');
+            FlatUI.emit('complete');
+        })
+
+}
+
+FlatUI.install = function()
+{
+    FlatUI.prompt();
+};
\ No newline at end of file