Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

add ability to specify output path #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
All notable changes to this project [will be documented](http://keepachangelog.com/) in this file.
This project *tries to* adhere to [Semantic Versioning](http://semver.org/).

## [0.7.0] - 2016-14-17

- uses config/res as the default folder to persist generated files (not backwards compatible)
- Add --help option
- Ability to specify output path
- Backwards-compatibility mode to use platforms path instead of new defaults (-c)

## [0.5.1] - 2016-03-11
- iOS: Get back sizes from previous version of the repo (eb65d2d)

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ Automatic splash screen generator for Cordova. Create a splash screen (2208x2208
Create a `splash.png` file in the root folder of your cordova project and run:

$ cordova-splash

You may specify the output path and directory as follows:

# output to path/to/res/screen
$ cordova-splash -p path/to/res -s screen

WARNING: If you were using a previous version of cordova-splash and expect the generated files to be in their respective ./platforms
path, use the compability mode:

$ cordova-splash -c

This will override the -p and -s settings.


### Icons

Expand Down
47 changes: 42 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var colors = require('colors');
var _ = require('underscore');
var Q = require('q');
var wrench = require('wrench');
var optparse = require('optparse');

/**
* Check which platforms are added to the project and return their splash screen names and sizes
Expand All @@ -20,7 +21,8 @@ var getPlatforms = function (projectName) {
name : 'ios',
// TODO: use async fs.exists
isAdded : fs.existsSync('platforms/ios'),
splashPath : 'platforms/ios/' + projectName + '/Images.xcassets/LaunchImage.launchimage/',
splashPath : (settings.RESOURCE_PATH + '/' + settings.SCREEN_DIR + '/ios/').replace('//', '/'),
platformSplashPath : 'platforms/ios/' + projectName + '/Images.xcassets/LaunchImage.launchimage/',
splash : [
{ name: 'Default-568h@2x~iphone.png', width: 640, height: 1136 },
{ name: 'Default-667h.png', width: 750, height: 1334 },
Expand Down Expand Up @@ -53,7 +55,8 @@ var getPlatforms = function (projectName) {
platforms.push({
name : 'android',
isAdded : fs.existsSync('platforms/android'),
splashPath : 'platforms/android/res/',
splashPath : (settings.RESOURCE_PATH + '/' + settings.SCREEN_DIR + '/android/').replace('//', '/'),
platformSplashPath: 'platforms/android/res/',
splash : [
{ name: 'drawable-land-ldpi/screen.png', width: 320, height: 200 },
{ name: 'drawable-land-mdpi/screen.png', width: 480, height: 320 },
Expand All @@ -68,7 +71,8 @@ var getPlatforms = function (projectName) {
platforms.push({
name : 'windows',
isAdded : fs.existsSync('platforms/windows'),
splashPath : 'platforms/windows/images/',
splashPath :(settings.RESOURCE_PATH + '/' + settings.SCREEN_DIR + '/windows/').replace('//', '/'),
platformSplashPath: 'platforms/windows/images/',
splash : [
{ name: 'SplashScreen.scale-100.png', width: 620, height: 300 },
{ name: 'SplashScreen.scale-125.png', width: 775, height: 375 },
Expand All @@ -89,6 +93,9 @@ var getPlatforms = function (projectName) {
var settings = {};
settings.CONFIG_FILE = 'config.xml';
settings.SPLASH_FILE = 'splash.png';
settings.RESOURCE_PATH = 'config/res'; // without trailing slash
settings.SCREEN_DIR = 'screen'; // without slashes
settings.USE_PLATFORMS_PATH = false; // true to use platforms path

/**
* @var {Object} console utils
Expand Down Expand Up @@ -145,7 +152,8 @@ var generateSplash = function (platform, splash) {
if (fs.existsSync(platformPath)) {
srcPath = platformPath;
}
var dstPath = platform.splashPath + splash.name;
var dstPath = (settings.USE_PLATFORMS_PATH ?
platform.platformSplashPath : platform.splashPath) + splash.name;
var dst = path.dirname(dstPath);
if (!fs.existsSync(dst)) {
wrench.mkdirSyncRecursive(dst);
Expand All @@ -162,7 +170,7 @@ var generateSplash = function (platform, splash) {
deferred.reject(err);
} else {
deferred.resolve();
display.success(splash.name + ' created');
display.success(splash.name + ' created [' + dstPath + ']');
}
});
return deferred.promise;
Expand Down Expand Up @@ -270,6 +278,35 @@ var configFileExists = function () {
return deferred.promise;
};

/**
* parse command line options
*/
var parseOptions = function() {
var switches = [
['-h', '--help', 'Show this help'],
['-p', '--path PATH', 'resource path, defaults to ' + settings.RESOURCE_PATH],
['-s', '--screen DIR', 'screen directory in PATH, defaults to ' + settings.SCREEN_DIR],
['-c', '--compat', 'uses default path in platforms (backwards compatibility, overrides -p and -i)'],
];
var parser = new optparse.OptionParser(switches);
parser.on('help', function() {
console.log(parser.toString());
process.exit();
});
parser.on('path', function(opt, path) {
settings.RESOURCE_PATH = path;
});
parser.on('screen', function(opt, path) {
settings.SCREEN_DIR = path;
});
parser.on('compat', function() {
settings.USE_PLATFORMS_PATH = true;
});
parser.parse(process.argv);
}

parseOptions();

display.header('Checking Project & Splash');

atLeastOnePlatformFound()
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"q": "^1.0.1",
"underscore": "^1.6.0",
"wrench": "^1.5.8",
"xml2js": "^0.4.3"
"xml2js": "^0.4.3",
"optparse": "^1.0.5"
}
}