mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-07-16 00:00:04 +08:00
chore(build): add auto install scripts (#1059)
* feat(core): auto install scripts * minor fixes * minor fixes * remove prompt message
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
"lint": "gulp lint",
|
||||
"build": "npm run lint && npm run build:core && npm run build:modules",
|
||||
"build:core": "tsc -p scripts/build/tsconfig-core.json",
|
||||
"build:utils": "tsc -p scripts/build/tsconfig-utils.json",
|
||||
"build:modules": "node scripts/build/build.js",
|
||||
"shipit": "npm run build && npm run npmpub",
|
||||
"npmpub": "sh scripts/build/publish.sh",
|
||||
|
||||
+37
-19
@@ -9,12 +9,15 @@ const ROOT = path.resolve(path.join(__dirname, '../../')), // root ionic-native
|
||||
VERSION = require(path.resolve(ROOT, 'package.json')).version, // current ionic-native version
|
||||
PLUGINS_PATH = path.resolve(ROOT, 'src/@ionic-native/plugins'), // path to plugins source files
|
||||
CORE_PACKAGE_JSON = require(path.resolve(__dirname, 'core-package.json')), // core package.json
|
||||
UTILS_PACKAGE_JSON = require(path.resolve(__dirname, 'utils-package.json')), // utils package.json
|
||||
PLUGIN_PACKAGE_JSON = require(path.resolve(__dirname, 'plugin-package.json')), // plugin package.json template
|
||||
PLUGIN_TS_CONFIG = require(path.resolve(__dirname, 'tsconfig-plugin.json')), // plugin tsconfig template
|
||||
PLUGIN_CONFIG = require(path.resolve(__dirname, 'plugin-config.json')), // plugin config for @ionic-native/utils
|
||||
BUILD_TMP = path.resolve(ROOT, '.tmp'), // tmp directory path
|
||||
BUILD_DIST_ROOT = path.resolve(ROOT, 'dist/packages-dist/@ionic-native'), // dist directory root path
|
||||
BUILD_PLUGINS_DIST = path.resolve(BUILD_DIST_ROOT, 'plugins'), // plugins dist directory path
|
||||
BUILD_CORE_DIST = path.resolve(BUILD_DIST_ROOT, 'core'); // core dist directory path
|
||||
BUILD_CORE_DIST = path.resolve(BUILD_DIST_ROOT, 'core'), // core dist directory path
|
||||
BUILD_UTILS_DIST = path.resolve(BUILD_DIST_ROOT, 'utils');
|
||||
|
||||
|
||||
// Delete dist directory and any temporary files
|
||||
@@ -33,6 +36,14 @@ console.log('Preparing core module package.json');
|
||||
CORE_PACKAGE_JSON.version = VERSION;
|
||||
fs.writeJsonSync(path.resolve(BUILD_CORE_DIST, 'package.json'), CORE_PACKAGE_JSON);
|
||||
|
||||
console.log('Preparing utils module package.json');
|
||||
UTILS_PACKAGE_JSON.version = VERSION;
|
||||
fs.mkdirpSync(BUILD_UTILS_DIST);
|
||||
fs.writeJsonSync(path.resolve(BUILD_UTILS_DIST, 'package.json'), UTILS_PACKAGE_JSON);
|
||||
|
||||
console.log('Copying utils module');
|
||||
fs.copySync(path.resolve(__dirname, 'utils.js'), path.resolve(BUILD_UTILS_DIST, 'index.js'));
|
||||
|
||||
|
||||
// Fetch a list of the plugins
|
||||
const PLUGINS = fs.readdirSync(PLUGINS_PATH);
|
||||
@@ -72,31 +83,38 @@ const addPluginToQueue = pluginName => {
|
||||
.then(() => fs.readFileAsync(PLUGIN_SRC_PATH, 'utf-8')) // read the plugin definition
|
||||
.then((pluginFile) => {
|
||||
|
||||
let postinstall,
|
||||
regexInstall = /install:\s'(.*)',?\s/g.exec(pluginFile),
|
||||
regexPlugin = /plugin:\s'(.*)',?\s/g.exec(pluginFile);
|
||||
let packageLocator,
|
||||
installVariables,
|
||||
regexPlugin = /plugin:\s'(.*)',?\s/g.exec(pluginFile),
|
||||
regexPluginName = /pluginName:\s'(.*)',?\s/g.exec(pluginFile),
|
||||
regexVars = /installVariables:\s(\[.*]),?\s/g.exec(pluginFile);
|
||||
|
||||
if (regexInstall) {
|
||||
// console.log('install command exists');
|
||||
// postinstall = regexInstall[1];
|
||||
|
||||
} else if (regexPlugin) {
|
||||
postinstall = `ionic plugin add ${ regexPlugin[1] }`;
|
||||
} else {
|
||||
console.log('nothing was found');
|
||||
if (regexPlugin) {
|
||||
packageLocator = regexPlugin[1];
|
||||
}
|
||||
|
||||
if (regexVars) {
|
||||
installVariables = JSON.parse(regexVars[1].replace(/'/g, '"'));
|
||||
}
|
||||
|
||||
if (packageLocator) console.log(packageLocator);
|
||||
if (installVariables) console.log(installVariables);
|
||||
|
||||
// clone plugin-config.json
|
||||
const pluginConfig = JSON.parse(JSON.stringify(PLUGIN_CONFIG));
|
||||
|
||||
pluginConfig.name = regexPluginName[1];
|
||||
pluginConfig.variables = installVariables;
|
||||
pluginConfig.locator = packageLocator;
|
||||
|
||||
return fs.writeJsonAsync(path.resolve(BUILD_PLUGINS_DIST, pluginName, 'plugin-config.json'), pluginConfig);
|
||||
})
|
||||
.then(() => {
|
||||
// clone package.json
|
||||
const packageJson = JSON.parse(JSON.stringify(PLUGIN_PACKAGE_JSON));
|
||||
|
||||
packageJson.name = `@ionic-native/${pluginName}`;
|
||||
packageJson.version = packageJson.peerDependencies['@ionic-native/core'] = VERSION;
|
||||
|
||||
if (postinstall) {
|
||||
// add postinstall script
|
||||
packageJson.scripts = { postinstall };
|
||||
}
|
||||
packageJson.version = packageJson.peerDependencies['@ionic-native/core'] = packageJson.peerDependencies['@ionic-native/utils'] = VERSION;
|
||||
|
||||
return fs.writeJsonAsync(path.resolve(BUILD_PLUGINS_DIST, pluginName, 'package.json'), packageJson);
|
||||
})
|
||||
@@ -107,7 +125,7 @@ const addPluginToQueue = pluginName => {
|
||||
|
||||
if (err) {
|
||||
// oops! something went wrong.
|
||||
callback(`Building ${pluginName} failed.`);
|
||||
callback(`\n\nBuilding ${pluginName} failed.`);
|
||||
console.log(stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "Facebook",
|
||||
"variables": [
|
||||
"APP_ID",
|
||||
"SOME_OTHER_VAR",
|
||||
"AND_ANOTHER_ONE"
|
||||
],
|
||||
"locator": "cordova-plugin-facebook4"
|
||||
}
|
||||
@@ -9,10 +9,14 @@
|
||||
"peerDependencies": {
|
||||
"@angular/core": "2.2.1",
|
||||
"@ionic-native/core": "{{VERSION}}",
|
||||
"@ionic-native/utils": "{{VERSION}}",
|
||||
"rxjs": "5.0.0-beta.12"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/driftyco/ionic-native.git"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node -e \"require('@ionic-native/utils').install(require('./plugin-config.json'))\""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
CORE="./dist/packages-dist/@ionic-native/core/"
|
||||
PLUGINS="./src/@ionic-native/plugins/*"
|
||||
UTILS="./dist/packages-dist/@ionic-native/utils/"
|
||||
|
||||
BUILD_PLUGINS_DIST='dist/packages-dist/@ionic-native/plugins'
|
||||
|
||||
echo "Publishing @ionic-native/core"
|
||||
npm publish "$CORE" --access public
|
||||
|
||||
echo "Publishing @ionic-native/utils"
|
||||
npm publish "$UTILS" --access public
|
||||
|
||||
# For each plugin, replace the values in tsconfig w/ the appropriate ones for this plugin
|
||||
for d in $PLUGINS ; do
|
||||
BASE=`basename $d`
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@ionic-native/utils",
|
||||
"version": "{{VERSION}}",
|
||||
"description": "Ionic Native - Native plugins for ionic apps",
|
||||
"main": "index.js",
|
||||
"author": "ionic",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"prompt": "^1.0.0",
|
||||
"colors": "^1.1.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/driftyco/ionic-native.git"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
var prompt = require('prompt'),
|
||||
colors = require('colors'),
|
||||
exec = require('child_process').exec;
|
||||
|
||||
module.exports = (function(){
|
||||
|
||||
var _self = this;
|
||||
this.varValues = null;
|
||||
|
||||
this.install = function(pluginConfig) {
|
||||
this.pluginConfig = pluginConfig;
|
||||
console.log('\n\n-- Initializing Ionic Native plugin installer --'.gray);
|
||||
console.log('\nInstalling plugin: '.green + pluginConfig.name);
|
||||
|
||||
if (!pluginConfig || !pluginConfig.name || !pluginConfig.locator) {
|
||||
console.log('\nInvalid configuration file. Exiting Ionic Native installer.'.red);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pluginConfig.variables) {
|
||||
this.processVariables();
|
||||
} else {
|
||||
this.execInstall();
|
||||
}
|
||||
};
|
||||
|
||||
this.processVariables = function() {
|
||||
console.log('\nThis plugin requires variables to install. Please specify values for these variables to complete the process.'.green);
|
||||
|
||||
prompt.message = null;
|
||||
prompt.delimiter = ': ';
|
||||
prompt.colors = false;
|
||||
|
||||
prompt.get(this.pluginConfig.variables, function(err, result) {
|
||||
if (err) {
|
||||
console.log('\n\nAn error occurred while processing your input. Please try again.'.red);
|
||||
} else {
|
||||
_self.confirmValues(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.confirmValues = function(values) {
|
||||
prompt.message = '';
|
||||
prompt.getInput('\nAre you sure you want to continue with the values you provided? (Y/n)'.green, function(err, result) {
|
||||
if (!result || result.toLowerCase() == 'y') {
|
||||
_self.varValues = values;
|
||||
_self.execInstall();
|
||||
} else {
|
||||
_self.processVariables();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.parseValues = function() {
|
||||
if (!this.varValues) return '';
|
||||
var args = '';
|
||||
for (var prop in this.varValues) {
|
||||
args += ' --variable ';
|
||||
args += prop;
|
||||
args += '=';
|
||||
|
||||
if (typeof this.varValues[prop] === 'string') {
|
||||
this.varValues[prop] = this.varValues[prop].trim();
|
||||
}
|
||||
|
||||
if (/\s/g.test(this.varValues[prop]) && this.varValues[prop].substr(0,1).indexOf(['\'', '"']) === -1) {
|
||||
// has whitespace, and not quoted
|
||||
this.varValues[prop] = '"' + this.varValues[prop] + '"';
|
||||
}
|
||||
|
||||
args += this.varValues[prop];
|
||||
}
|
||||
return args;
|
||||
};
|
||||
|
||||
this.execInstall = function() {
|
||||
var installCommand = 'ionic plugin add ' + this.pluginConfig.locator;
|
||||
if (this.varValues) {
|
||||
installCommand += this.parseValues();
|
||||
}
|
||||
exec(installCommand, function(err, stdout, stderr) {
|
||||
if (err || stderr) {
|
||||
console.log('\nAn error occurred while trying to install the plugin. Please install the plugin manually or re-install this package to try again.'.red);
|
||||
} else {
|
||||
var message = '\n\n' + _self.pluginConfig.name + ' plugin was successfully installed! Happy coding!';
|
||||
console.log(message.green);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
})();
|
||||
@@ -34,6 +34,10 @@ export interface PluginConfig {
|
||||
* Custom install command
|
||||
*/
|
||||
install?: string;
|
||||
/**
|
||||
* Available installation variables
|
||||
*/
|
||||
installVariables?: string[];
|
||||
/**
|
||||
* Supported platforms
|
||||
*/
|
||||
|
||||
@@ -77,7 +77,8 @@ export interface DeeplinkMatch {
|
||||
pluginRef: 'IonicDeeplink',
|
||||
repo: 'https://github.com/driftyco/ionic-plugin-deeplinks',
|
||||
platforms: ['iOS', 'Android'],
|
||||
install: 'ionic plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/'
|
||||
install: 'ionic plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/',
|
||||
installVariables: ['URL_SCHEME', 'DEEPLINK_SCHEME', 'DEEPLINK_HOST', 'ANDROID_PATH_PREFIX']
|
||||
})
|
||||
@Injectable()
|
||||
export class Deeplinks {
|
||||
|
||||
@@ -105,7 +105,8 @@ export interface FacebookLoginResponse {
|
||||
plugin: 'cordova-plugin-facebook4',
|
||||
pluginRef: 'facebookConnectPlugin',
|
||||
repo: 'https://github.com/jeduan/cordova-plugin-facebook4',
|
||||
install: 'ionic plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"'
|
||||
install: 'ionic plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"',
|
||||
installVariables: ['APP_ID', 'APP_NAME']
|
||||
})
|
||||
@Injectable()
|
||||
export class Facebook {
|
||||
|
||||
@@ -20,7 +20,8 @@ import { Cordova, Plugin } from '@ionic-native/core';
|
||||
pluginRef: 'window.plugins.googleplus',
|
||||
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-googleplus',
|
||||
platforms: ['Web', 'Android', 'iOS'],
|
||||
install: 'ionic plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID=myreversedclientid'
|
||||
install: 'ionic plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID=myreversedclientid',
|
||||
installVariables: ['REVERSED_CLIENT_ID']
|
||||
})
|
||||
@Injectable()
|
||||
export class GooglePlus {
|
||||
|
||||
@@ -481,7 +481,8 @@ export class MapPage {
|
||||
pluginRef: 'plugin.google.maps.Map',
|
||||
plugin: 'cordova-plugin-googlemaps',
|
||||
repo: 'https://github.com/mapsplugin/cordova-plugin-googlemaps',
|
||||
install: 'ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"'
|
||||
install: 'ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"',
|
||||
installVariables: ['API_KEY_FOR_ANDROID', 'API_KEY_FOR_IOS']
|
||||
})
|
||||
@Injectable()
|
||||
export class GoogleMap {
|
||||
|
||||
@@ -169,6 +169,7 @@ export interface PinterestPin {
|
||||
pluginRef: 'cordova.plugins.Pinterest',
|
||||
repo: 'https://github.com/zyramedia/cordova-plugin-pinterest',
|
||||
install: 'ionic plugin add cordova-plugin-pinterest --variable APP_ID=YOUR_APP_ID',
|
||||
installVariables: ['APP_ID'],
|
||||
platforms: ['Android', 'iOS']
|
||||
})
|
||||
@Injectable()
|
||||
|
||||
@@ -323,7 +323,8 @@ declare var PushNotification: {
|
||||
plugin: 'phonegap-plugin-push',
|
||||
pluginRef: 'PushNotification',
|
||||
repo: 'https://github.com/phonegap/phonegap-plugin-push',
|
||||
install: 'ionic plugin add phonegap-plugin-push --variable SENDER_ID=XXXXXXXXX'
|
||||
install: 'ionic plugin add phonegap-plugin-push --variable SENDER_ID=XXXXXXXXX',
|
||||
installVariables: ['SENDER_ID']
|
||||
})
|
||||
@Injectable()
|
||||
export class Push {
|
||||
|
||||
@@ -21,7 +21,8 @@ import { Plugin, Cordova } from '@ionic-native/core';
|
||||
pluginRef: 'Rollbar',
|
||||
repo: 'https://github.com/Resgrid/cordova-plugins-rollbar',
|
||||
platforms: ['Android', 'iOS'],
|
||||
install: 'ionic plugin add resgrid-cordova-plugins-rollbar --variable ROLLBAR_ACCESS_TOKEN="YOUR_ROLLBAR_ACCEESS_TOKEN" --variable ROLLBAR_ENVIRONMENT="ROLLBAR_ENVIRONMENT"'
|
||||
install: 'ionic plugin add resgrid-cordova-plugins-rollbar --variable ROLLBAR_ACCESS_TOKEN="YOUR_ROLLBAR_ACCEESS_TOKEN" --variable ROLLBAR_ENVIRONMENT="ROLLBAR_ENVIRONMENT"',
|
||||
installVariables: ['ROLLBAR_ACCESS_TOKEN', 'ROLLBAR_ENVIRONMENT']
|
||||
})
|
||||
@Injectable()
|
||||
export class Rollbar {
|
||||
|
||||
@@ -52,7 +52,8 @@ export interface TwitterConnectResponse {
|
||||
plugin: 'twitter-connect-plugin',
|
||||
pluginRef: 'TwitterConnect',
|
||||
repo: 'https://github.com/ManifestWebDesign/twitter-connect-plugin',
|
||||
install: 'ionic plugin add twitter-connect-plugin --variable FABRIC_KEY=fabric_API_key'
|
||||
install: 'ionic plugin add twitter-connect-plugin --variable FABRIC_KEY=fabric_API_key',
|
||||
installVariables: ['FABRIC_KEY']
|
||||
})
|
||||
@Injectable()
|
||||
export class TwitterConnect {
|
||||
|
||||
Reference in New Issue
Block a user