summaryrefslogtreecommitdiff
path: root/www/lib/ionic-pullup/example/hooks/after_prepare
diff options
context:
space:
mode:
authorPliable Pixels <pliablepixels@gmail.com>2017-09-27 11:39:30 -0400
committerPliable Pixels <pliablepixels@gmail.com>2017-09-27 11:39:30 -0400
commite18708f10b04455be151a5a799f0109c34f20a25 (patch)
tree9e4559ef0fff8b366474e7768308ddca1e32268a /www/lib/ionic-pullup/example/hooks/after_prepare
parent97a1cb3ae199c7b5455dcba0001efd5b4c32040a (diff)
package updates to set up bower correctly #535
Diffstat (limited to 'www/lib/ionic-pullup/example/hooks/after_prepare')
-rw-r--r--www/lib/ionic-pullup/example/hooks/after_prepare/010_add_platform_class.js94
1 files changed, 0 insertions, 94 deletions
diff --git a/www/lib/ionic-pullup/example/hooks/after_prepare/010_add_platform_class.js b/www/lib/ionic-pullup/example/hooks/after_prepare/010_add_platform_class.js
deleted file mode 100644
index bda3e415..00000000
--- a/www/lib/ionic-pullup/example/hooks/after_prepare/010_add_platform_class.js
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/env node
-
-// Add Platform Class
-// v1.0
-// Automatically adds the platform class to the body tag
-// after the `prepare` command. By placing the platform CSS classes
-// directly in the HTML built for the platform, it speeds up
-// rendering the correct layout/style for the specific platform
-// instead of waiting for the JS to figure out the correct classes.
-
-var fs = require('fs');
-var path = require('path');
-
-var rootdir = process.argv[2];
-
-function addPlatformBodyTag(indexPath, platform) {
- // add the platform class to the body tag
- try {
- var platformClass = 'platform-' + platform;
- var cordovaClass = 'platform-cordova platform-webview';
-
- var html = fs.readFileSync(indexPath, 'utf8');
-
- var bodyTag = findBodyTag(html);
- if(!bodyTag) return; // no opening body tag, something's wrong
-
- if(bodyTag.indexOf(platformClass) > -1) return; // already added
-
- var newBodyTag = bodyTag;
-
- var classAttr = findClassAttr(bodyTag);
- if(classAttr) {
- // body tag has existing class attribute, add the classname
- var endingQuote = classAttr.substring(classAttr.length-1);
- var newClassAttr = classAttr.substring(0, classAttr.length-1);
- newClassAttr += ' ' + platformClass + ' ' + cordovaClass + endingQuote;
- newBodyTag = bodyTag.replace(classAttr, newClassAttr);
-
- } else {
- // add class attribute to the body tag
- newBodyTag = bodyTag.replace('>', ' class="' + platformClass + ' ' + cordovaClass + '">');
- }
-
- html = html.replace(bodyTag, newBodyTag);
-
- fs.writeFileSync(indexPath, html, 'utf8');
-
- process.stdout.write('add to body class: ' + platformClass + '\n');
- } catch(e) {
- process.stdout.write(e);
- }
-}
-
-function findBodyTag(html) {
- // get the body tag
- try{
- return html.match(/<body(?=[\s>])(.*?)>/gi)[0];
- }catch(e){}
-}
-
-function findClassAttr(bodyTag) {
- // get the body tag's class attribute
- try{
- return bodyTag.match(/ class=["|'](.*?)["|']/gi)[0];
- }catch(e){}
-}
-
-if (rootdir) {
-
- // go through each of the platform directories that have been prepared
- var platforms = (process.env.CORDOVA_PLATFORMS ? process.env.CORDOVA_PLATFORMS.split(',') : []);
-
- for(var x=0; x<platforms.length; x++) {
- // open up the index.html file at the www root
- try {
- var platform = platforms[x].trim().toLowerCase();
- var indexPath;
-
- if(platform == 'android') {
- indexPath = path.join('platforms', platform, 'assets', 'www', 'index.html');
- } else {
- indexPath = path.join('platforms', platform, 'www', 'index.html');
- }
-
- if(fs.existsSync(indexPath)) {
- addPlatformBodyTag(indexPath, platform);
- }
-
- } catch(e) {
- process.stdout.write(e);
- }
- }
-
-}