First Commit
This commit is contained in:
commit
feb864dc47
170 changed files with 4671 additions and 0 deletions
83
hackatonApp/hooks/README.md
Normal file
83
hackatonApp/hooks/README.md
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<!--
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
-->
|
||||
# Cordova Hooks
|
||||
|
||||
This directory may contain scripts used to customize cordova commands. This
|
||||
directory used to exist at `.cordova/hooks`, but has now been moved to the
|
||||
project root. Any scripts you add to these directories will be executed before
|
||||
and after the commands corresponding to the directory name. Useful for
|
||||
integrating your own build systems or integrating with version control systems.
|
||||
|
||||
__Remember__: Make your scripts executable.
|
||||
|
||||
## Hook Directories
|
||||
The following subdirectories will be used for hooks:
|
||||
|
||||
after_build/
|
||||
after_compile/
|
||||
after_docs/
|
||||
after_emulate/
|
||||
after_platform_add/
|
||||
after_platform_rm/
|
||||
after_platform_ls/
|
||||
after_plugin_add/
|
||||
after_plugin_ls/
|
||||
after_plugin_rm/
|
||||
after_plugin_search/
|
||||
after_prepare/
|
||||
after_run/
|
||||
after_serve/
|
||||
before_build/
|
||||
before_compile/
|
||||
before_docs/
|
||||
before_emulate/
|
||||
before_platform_add/
|
||||
before_platform_rm/
|
||||
before_platform_ls/
|
||||
before_plugin_add/
|
||||
before_plugin_ls/
|
||||
before_plugin_rm/
|
||||
before_plugin_search/
|
||||
before_prepare/
|
||||
before_run/
|
||||
before_serve/
|
||||
pre_package/ <-- Windows 8 and Windows Phone only.
|
||||
|
||||
## Script Interface
|
||||
|
||||
All scripts are run from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
|
||||
|
||||
* CORDOVA_VERSION - The version of the Cordova-CLI.
|
||||
* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
|
||||
* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
|
||||
* CORDOVA_HOOK - Path to the hook that is being executed.
|
||||
* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
|
||||
|
||||
If a script returns a non-zero exit code, then the parent cordova command will be aborted.
|
||||
|
||||
|
||||
## Writing hooks
|
||||
|
||||
We highly recommend writting your hooks using Node.js so that they are
|
||||
cross-platform. Some good examples are shown here:
|
||||
|
||||
[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
|
||||
|
||||
94
hackatonApp/hooks/after_prepare/010_add_platform_class.js
Normal file
94
hackatonApp/hooks/after_prepare/010_add_platform_class.js
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#!/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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 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);
|
||||
23
hackatonApp/hooks/before_platform_add/init_directories.js
Normal file
23
hackatonApp/hooks/before_platform_add/init_directories.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 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) {}
|
||||
72
hackatonApp/hooks/before_prepare/01_jshint.js
Normal file
72
hackatonApp/hooks/before_prepare/01_jshint.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var jshint = require('jshint').JSHINT;
|
||||
var async = require('async');
|
||||
|
||||
var foldersToProcess = [
|
||||
'js'
|
||||
];
|
||||
|
||||
foldersToProcess.forEach(function(folder) {
|
||||
processFiles("www/" + folder);
|
||||
});
|
||||
|
||||
function processFiles(dir, callback) {
|
||||
var errorCount = 0;
|
||||
fs.readdir(dir, function(err, list) {
|
||||
if (err) {
|
||||
console.log('processFiles err: ' + err);
|
||||
return;
|
||||
}
|
||||
async.eachSeries(list, function(file, innercallback) {
|
||||
file = dir + '/' + file;
|
||||
fs.stat(file, function(err, stat) {
|
||||
if(!stat.isDirectory()) {
|
||||
if(path.extname(file) === ".js") {
|
||||
lintFile(file, function(hasError) {
|
||||
if(hasError) {
|
||||
errorCount++;
|
||||
}
|
||||
innercallback();
|
||||
});
|
||||
} else {
|
||||
innercallback();
|
||||
}
|
||||
} else {
|
||||
innercallback();
|
||||
}
|
||||
});
|
||||
}, function(error) {
|
||||
if(errorCount > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function lintFile(file, callback) {
|
||||
console.log("Linting " + file);
|
||||
fs.readFile(file, function(err, data) {
|
||||
if(err) {
|
||||
console.log('Error: ' + err);
|
||||
return;
|
||||
}
|
||||
if(jshint(data.toString())) {
|
||||
console.log('File ' + file + ' has no errors.');
|
||||
console.log('-----------------------------------------');
|
||||
callback(false);
|
||||
} else {
|
||||
console.log('Errors in file ' + file);
|
||||
var out = jshint.data(),
|
||||
errors = out.errors;
|
||||
for(var j = 0; j < errors.length; j++) {
|
||||
console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' +
|
||||
errors[j].evidence);
|
||||
}
|
||||
console.log('-----------------------------------------');
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue