Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.
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
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# cordova-splash
# cordova-splash + capacitor-splash = c2-splash

Automatic splash screen generator for Cordova. Create a splash screen once in the root folder of your Cordova project and use cordova-splash to automatically crop and copy it for all the platforms your project supports (currenty works with iOS, Android and Windows 10).
Automatic splash screen generator for *both* [Cordova](https://cordova.apache.org) and [capacitor](https://capacitor.ionicframework.com/); that's why I renamed it to *c2-splash*. :-P

The splash screen image should be 2208x2208 px with a center square of about 1200x1200 px. The image may be cropped around the center square. You can also use larger images with similar proportions.
Create a splash screen once in the root folder of your Cordova / capacitor project and use c2-splash to automatically crop and copy it for all the platforms your project supports (currently works with iOS, Android and Windows 10 (Cordova only)).

### Installation

Expand All @@ -14,29 +14,48 @@ If you are using an older version of cordova (before 7.x):

### Requirements

- ImageMagick installed (*Mac*: `brew install imagemagick`, *Debian/Ubuntu*: `sudo apt-get install imagemagick`, *Windows*: [See here, install "Legacy tools"](http://www.imagemagick.org/script/binary-releases.php#windows))
- At least one platform was added to your project ([cordova platforms docs](http://cordova.apache.org/docs/en/edge/guide_platforms_index.md.html#Platform%20Guides))
- Cordova's config.xml file must exist in the root folder ([cordova config.xml docs](http://cordova.apache.org/docs/en/edge/config_ref_index.md.html#The%20config.xml%20File))
- ImageMagick installed (*Mac*: `brew install imagemagick`, *Debian/Ubuntu*: `sudo apt-get install imagemagick`, *Windows*: [See here](https://www.imagemagick.org/script/download.php#windows), when installing choose the "Legacy tools" option!)
- At least one platform was added to your project ([cordova platforms docs](http://cordova.apache.org/docs/en/edge/guide_platforms_index.md.html#Platform%20Guides) or (`npx cap add`)[https://capacitor.ionicframework.com/docs/getting-started/])
- Cordova's config.xml file must exist in the root folder ([cordova config.xml docs](http://cordova.apache.org/docs/en/edge/config_ref_index.md.html#The%20config.xml%20File)), or, when using capacitor, it looks for `capacitor.config.json`

### Usage

Create a `splash.png` file in the root folder of your cordova project and run:
Create a `splash.png` file with in the root folder of your cordova project. The splash screen image should be **2208x2208 px** with a center square of about **1200x1200 px**. The image may be **cropped** around the center square. You can also use larger images with similar proportions. As ImageMagick is used for image generation, you can also use SVG graphics.

$ cordova-splash
Then run:

You also can specify manually a location for your `config.xml` or `splash.png`:
$ c2-splash

$ cordova-splash --config=config.xml --splash=splash.png
c2-splash automatically detects whether you have a cordova or a capacitor project by looking for the `capacitor.config.json` config file.

You also can specify manually a location for your `config.xml` / `capacitor.config.json` or `splash.png`:

$ c2-splash --config=config.xml --splash=splash.png

You can use the `--capacitor` option to manually choose "capacitor" mode and use `--config` to set the file name.

If you run a old version of Cordova for iOS and you need your files in `/Resources/icons/`, use this option:

$ cordova-splash --xcode-old
$ c2-splash --xcode-old

To change the output filename for android, use:

$ c2-splash --android_filename=screen.png

#### Notes:

- Your `config.ml` file will not be updated by the tool (because images are automatically created in the good folders)
- The error message `Error: spawn identify ENOENT` is printed, when the script cannot find the `identify` tool, i.e. the ImageMagick tools are not found in `PATH`.
- There are sample splash images to help you see which parts are visible in which resolution: sample.svg / sample.png

**Cordova:**

- Your `config.xml` file will not be updated by the tool (because images are automatically created in the good folders)
- Therefore, in your `config.xml`, be sure to remove all lines looking like `<splash src="res/screen/android/splash-land-mdpi.png" density="land-mdpi"/>`

**capacitor:**

- For android and ios the splash images are generated in the platform directory where they are expected for building the app. *However, as I don't have a Mac at hand right now, I didn't test the paths for ios.*

### Icons

Check out [cordova-icon](https://github.com/AlexDisler/cordova-icon)
Expand Down
2 changes: 2 additions & 0 deletions bin/c2-splash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./../index.js');
2 changes: 2 additions & 0 deletions bin/capacitor-splash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./../index.js');
106 changes: 78 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,37 @@ var colors = require('colors');
var _ = require('underscore');
var Q = require('q');
var argv = require('minimist')(process.argv.slice(2));
const CAPACITOR_CONFIG_FILE = 'capacitor.config.json';
const CORDOVA_CONFIG_FILE = 'config.xml';

/**
* @var {Object} settings - names of the config file and of the splash image
*/
var settings = {};
settings.CONFIG_FILE = argv.config || 'config.xml';
settings.CAPACITOR = argv.capacitor || fs.existsSync(CAPACITOR_CONFIG_FILE);
settings.CONFIG_FILE = argv.config || (settings.CAPACITOR ? CAPACITOR_CONFIG_FILE : CORDOVA_CONFIG_FILE);
settings.SPLASH_FILE = argv.splash || 'splash.png';
settings.OLD_XCODE_PATH = argv['xcode-old'] || false;
settings.ANDROID_SPLASH_FILENAME = argv.android_filename || 'splash.png';
// console.log("settings=",settings);

const platform_paths = settings.CAPACITOR ? {
ios: 'ios',
android: 'android'
} : {
ios: 'platforms/ios',
android: 'platforms/android'
};

const platform_splash_paths = settings.CAPACITOR ? {
// todo check if this path is correct for capacitor ios
ios: settings.OLD_XCODE_PATH ? '/Resources/splash/' : '/Images.xcassets/LaunchImage.launchimage/',
android: '/app/src/main/res/'
} : {
ios: settings.OLD_XCODE_PATH ? '/Resources/splash/' : '/Images.xcassets/LaunchImage.launchimage/',
android: '/res/'
};


/**
* Check which platforms are added to the project and return their splash screen names and sizes
Expand All @@ -24,17 +47,12 @@ settings.OLD_XCODE_PATH = argv['xcode-old'] || false;
var getPlatforms = function (projectName) {
var deferred = Q.defer();
var platforms = [];
var xcodeFolder = '/Images.xcassets/LaunchImage.launchimage/';

if (settings.OLD_XCODE_PATH) {
xcodeFolder = '/Resources/splash/';
}

platforms.push({
name : 'ios',
// TODO: use async fs.exists
isAdded : fs.existsSync('platforms/ios'),
splashPath : 'platforms/ios/' + projectName + xcodeFolder,
isAdded : fs.existsSync(platform_paths.ios),
splashPath : platform_paths.ios + projectName + platform_splash_paths.ios,
splash : [
// iPhone
{ name: 'Default~iphone.png', width: 320, height: 480 },
Expand All @@ -58,23 +76,23 @@ var getPlatforms = function (projectName) {
});
platforms.push({
name : 'android',
isAdded : fs.existsSync('platforms/android'),
splashPath : 'platforms/android/res/',
isAdded : fs.existsSync(platform_paths.android),
splashPath : platform_paths.android + platform_splash_paths.android,
splash : [
// Landscape
{ name: 'drawable-land-ldpi/screen.png', width: 320, height: 200 },
{ name: 'drawable-land-mdpi/screen.png', width: 480, height: 320 },
{ name: 'drawable-land-hdpi/screen.png', width: 800, height: 480 },
{ name: 'drawable-land-xhdpi/screen.png', width: 1280, height: 720 },
{ name: 'drawable-land-xxhdpi/screen.png', width: 1600, height: 960 },
{ name: 'drawable-land-xxxhdpi/screen.png', width: 1920, height: 1280 },
{ name: 'drawable-land-ldpi/' + settings.ANDROID_SPLASH_FILENAME, width: 320, height: 200 },
{ name: 'drawable-land-mdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 480, height: 320 },
{ name: 'drawable-land-hdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 800, height: 480 },
{ name: 'drawable-land-xhdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 1280, height: 720 },
{ name: 'drawable-land-xxhdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 1600, height: 960 },
{ name: 'drawable-land-xxxhdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 1920, height: 1280 },
// Portrait
{ name: 'drawable-port-ldpi/screen.png', width: 200, height: 320 },
{ name: 'drawable-port-mdpi/screen.png', width: 320, height: 480 },
{ name: 'drawable-port-hdpi/screen.png', width: 480, height: 800 },
{ name: 'drawable-port-xhdpi/screen.png', width: 720, height: 1280 },
{ name: 'drawable-port-xxhdpi/screen.png', width: 960, height: 1600 },
{ name: 'drawable-port-xxxhdpi/screen.png', width: 1280, height: 1920 }
{ name: 'drawable-port-ldpi/' + settings.ANDROID_SPLASH_FILENAME, width: 200, height: 320 },
{ name: 'drawable-port-mdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 320, height: 480 },
{ name: 'drawable-port-hdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 480, height: 800 },
{ name: 'drawable-port-xhdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 720, height: 1280 },
{ name: 'drawable-port-xxhdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 960, height: 1600 },
{ name: 'drawable-port-xxxhdpi/' + settings.ANDROID_SPLASH_FILENAME, width: 1280, height: 1920 }
]
});
platforms.push({
Expand All @@ -96,6 +114,7 @@ var getPlatforms = function (projectName) {
{ name: 'SplashScreenPhone.scale-100.png', width: 480, height: 800 }
]
});
// console.info(platforms);
deferred.resolve(platforms);
return deferred.promise;
};
Expand Down Expand Up @@ -172,7 +191,7 @@ var generateSplash = function (platform, splash) {
deferred.reject(err);
} else {
deferred.resolve();
display.success(splash.name + ' created');
display.success(dstPath + ' created');
}
});
return deferred.promise;
Expand All @@ -192,11 +211,7 @@ var generateSplashForPlatform = function (platform) {
splashes.forEach(function (splash) {
all.push(generateSplash(platform, splash));
});
Q.all(all).then(function () {
deferred.resolve();
}).catch(function (err) {
console.log(err);
});
Q.all(all).then(deferred.resolve).catch(console.log);
return deferred.promise;
};

Expand Down Expand Up @@ -284,8 +299,43 @@ var configFileExists = function () {
return deferred.promise;
};

if (settings.CAPACITOR) {
configFileExists = function () {
var deferred = Q.defer();
fs.exists(settings.CONFIG_FILE, function (exists) {
if (exists) {
display.success(settings.CONFIG_FILE + ' exists');
deferred.resolve();
} else {
display.error('capacitor\'s ' + settings.CONFIG_FILE + ' does not exist');
deferred.reject();
}
});
return deferred.promise;
};

getProjectName = function() {
var deferred = Q.defer();
fs.readFile(settings.CONFIG_FILE, function (err, data) {
if (err) {
deferred.reject(err);
}
try {
var config = JSON.parse(data);
var projectName = config.appName;
deferred.resolve(projectName);
} catch (err) {
deferred.reject(err);
}
});
return deferred.promise;
};
}

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

display.success('Mode: ' + settings.CAPACITOR ? 'capacitor' : 'cordova');

atLeastOnePlatformFound()
.then(validSplashExists)
.then(configFileExists)
Expand Down
Binary file added sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions sample.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading