-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from mcfly-io/fix-ionic2
- Loading branch information
Showing
12 changed files
with
338 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
generators/target/templates/hooks/after_platform_add/010_install_plugins.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
|
||
/** | ||
* Install all plugins listed in package.json | ||
* https://raw.githubusercontent.com/diegonetto/generator-ionic/master/templates/hooks/after_platform_add/install_plugins.js | ||
*/ | ||
var exec = require('child_process').exec; | ||
var path = require('path'); | ||
var sys = require('sys'); | ||
|
||
var packageJSON = null; | ||
|
||
try { | ||
packageJSON = require('../../package.json'); | ||
} catch(ex) { | ||
console.log('\nThere was an error fetching your package.json file.') | ||
console.log('\nPlease ensure a valid package.json is in the root of this project\n') | ||
return; | ||
} | ||
|
||
var cmd = process.platform === 'win32' ? 'cordova.cmd' : 'cordova'; | ||
// var script = path.resolve(__dirname, '../../node_modules/cordova/bin', cmd); | ||
|
||
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || []; | ||
packageJSON.cordovaPlugins.forEach(function (plugin) { | ||
exec('cordova plugin add ' + plugin, function (error, stdout, stderr) { | ||
sys.puts(stdout); | ||
}); | ||
}); | ||
/*eslint-enable */ |
60 changes: 60 additions & 0 deletions
60
generators/target/templates/hooks/after_plugin_add/010_register_plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
/** | ||
* Push plugins to cordovaPlugins array after_plugin_add | ||
*/ | ||
var fs = require('fs'), | ||
packageJSON = require('../../package.json'), | ||
path = require('path'); | ||
|
||
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || []; | ||
process.env.CORDOVA_PLUGINS.split(',').forEach(function (plugin) { | ||
var configString, | ||
idRegEx, | ||
id, | ||
pluginXmlPath, | ||
pluginToAdd; | ||
|
||
if(plugin.indexOf('https') != -1 || plugin.indexOf('git') != -1) { | ||
console.log('Installing plugin from url'); | ||
} | ||
|
||
if(plugin.indexOf('/') != -1) { | ||
try { | ||
pluginXmlPath = path.resolve(plugin, 'plugin.xml'); | ||
console.log('got pluginXmlPath:', pluginXmlPath); | ||
if (!fs.existsSync(pluginXmlPath)) { | ||
var errorMessage = ['There was no plugin.xml file found for path: ', pluginXmlPath].join(''); | ||
return; | ||
} | ||
|
||
configString = fs.readFileSync(pluginXmlPath,{encoding: 'utf8'}); | ||
idRegEx = new RegExp('<plugin[^>]*id="(.*)"', 'i'); | ||
id = idRegEx.exec(configString)[1] | ||
pluginToAdd = {id: id, locator: plugin}; | ||
} catch(ex) { | ||
console.log('There was an error retrieving the plugin.xml filr from the 010_register_plugin.js hook', ex); | ||
} | ||
} else { | ||
pluginToAdd = plugin; | ||
} | ||
|
||
if(typeof pluginToAdd == 'string' && packageJSON.cordovaPlugins.indexOf(pluginToAdd) == -1) { | ||
packageJSON.cordovaPlugins.push(pluginToAdd); | ||
} else if (typeof pluginToAdd == 'object') { | ||
var pluginExists = false; | ||
packageJSON.cordovaPlugins.forEach(function(checkPlugin) { | ||
if(typeof checkPlugin == 'object' && checkPlugin.id == pluginToAdd.id) { | ||
pluginExists = true; | ||
} | ||
}) | ||
if(!pluginExists) { | ||
packageJSON.cordovaPlugins.push(pluginToAdd); | ||
} | ||
} | ||
}); | ||
|
||
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2)); | ||
|
||
/*eslint-enable */ |
31 changes: 31 additions & 0 deletions
31
generators/target/templates/hooks/after_plugin_rm/010_deregister_plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
|
||
/** | ||
* Remove plugins from cordovaPlugins array after_plugin_rm | ||
*/ | ||
var fs = require('fs'); | ||
var packageJSON = require('../../package.json'); | ||
|
||
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || []; | ||
|
||
process.env.CORDOVA_PLUGINS.split(',').forEach(function (plugin) { | ||
var index = packageJSON.cordovaPlugins.indexOf(plugin); | ||
if (index > -1) { | ||
packageJSON.cordovaPlugins.splice(index, 1); | ||
} else { | ||
//If it didnt find a match, it may be listed as {id,locator} | ||
for(var i = 0, j = packageJSON.cordovaPlugins.length; i < j; i++) { | ||
var packagePlugin = packageJSON.cordovaPlugins[i]; | ||
if(typeof packagePlugin == 'object' && packagePlugin.id == plugin) { | ||
packageJSON.cordovaPlugins.splice(index, 1); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
fs.writeFile('package.json', JSON.stringify(packageJSON, null, 2)); | ||
|
||
/*eslint-enable */ |
98 changes: 98 additions & 0 deletions
98
generators/target/templates/hooks/after_prepare/010_add_platform_class.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
|
||
// 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); | ||
} | ||
} | ||
|
||
} | ||
|
||
/*eslint-enable */ |
32 changes: 32 additions & 0 deletions
32
generators/target/templates/hooks/after_prepare/020_remove_sass_from_platforms.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
|
||
/** | ||
* After prepare, files are copied to the platforms/ios and platforms/android folders. | ||
* Lets clean up some of those files that arent needed with this hook. | ||
*/ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var deleteFolderRecursive = function(removePath) { | ||
if( fs.existsSync(removePath) ) { | ||
fs.readdirSync(removePath).forEach(function(file,index){ | ||
var curPath = path.join(removePath, file); | ||
if(fs.lstatSync(curPath).isDirectory()) { // recurse | ||
deleteFolderRecursive(curPath); | ||
} else { // delete file | ||
fs.unlinkSync(curPath); | ||
} | ||
}); | ||
fs.rmdirSync(removePath); | ||
} | ||
}; | ||
|
||
var iosPlatformsDir = path.resolve(__dirname, '../../platforms/ios/www/lib/ionic/scss'); | ||
var androidPlatformsDir = path.resolve(__dirname, '../../platforms/android/assets/www/lib/ionic/scss'); | ||
|
||
deleteFolderRecursive(iosPlatformsDir); | ||
deleteFolderRecursive(androidPlatformsDir); | ||
|
||
/*eslint-enable */ |
27 changes: 27 additions & 0 deletions
27
generators/target/templates/hooks/before_platform_add/init_directories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
|
||
/** | ||
* On a fresh clone, the local platforms/ and plugins/ directories will be | ||
* missing, so ensure they get created before the first platform is added. | ||
*/ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var platformsDir = path.resolve(__dirname, '../../platforms'); | ||
var pluginsDir = path.resolve(__dirname, '../../plugins'); | ||
|
||
try { | ||
fs.mkdirSync(platformsDir, function (err) { | ||
if (err) { console.error(err); } | ||
}); | ||
} catch(ex) {} | ||
|
||
try { | ||
fs.mkdirSync(pluginsDir, function (err) { | ||
if (err) { console.error(err); } | ||
}); | ||
} catch(ex) {} | ||
|
||
/*eslint-enable */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
Oops, something went wrong.