Skip to content

Commit

Permalink
Populate project.
Browse files Browse the repository at this point in the history
- Add README.md and LICENSE
- Populate package.json
- Populate updated script, linked for command line.
  • Loading branch information
bhalash committed Nov 22, 2019
1 parent 7bcb0c2 commit e29a44b
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 16 deletions.
27 changes: 13 additions & 14 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
MIT License
The MIT License

Copyright (c) 2019 D4H Technologies
Copyright (C) 2019 Dale Zak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# capacitor-res
Copy cordova-res resources for a capacitor project.
# Ionic Capacitor Resources Generator
Copy asset resources generated by [cordiva-res](https://github.com/ionic-team/cordova-res) into Android and iOS platform folders in a Capacitor project.

## Install

```shell
npm install -g @d4h/capacitor-res
```

## Description

This script derives from [this gist from dalezak](https://gist.github.com/rrlevy/16d42f94decd3b82bed4ac00da79f2f2), which in turn comes from given in [ionic-team/capacitor#229](https://github.com/ionic-team/capacitor/issues/229#issuecomment-538146260). The original script as given didn't work too well in the context of a monorepo project, as it expected platform and asset folders to lie at the project root.

## Use

```shell
cd path/to/project/
cordova-res <platform>
capacitor-res <platform>
```

## Related Links

- <https://github.com/ionic-team/cordova-res>
- <https://github.com/ionic-team/capacitor/issues/229#issuecomment-538146260>
- <https://gist.github.com/rrlevy/16d42f94decd3b82bed4ac00da79f2f2>

## License
Copyright (C) 2019 [Dale Zak](https://github.com/dalezak).
138 changes: 138 additions & 0 deletions bin/capacitor-res
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/env node
'use strict';

const fs = require('fs');
const minimist = require('minimist');
const path = require('path');

const Platform = {
Android: 'android',
Ios: 'ios'
};

process.title = 'capacitor-res';

/**
* Asset Lists
* =============================================================================
*/

const SOURCE_IOS_ICON = 'resources/ios/icon';
const SOURCE_IOS_SPLASH = 'resources/ios/splash';

const TARGET_IOS_ICON = 'ios/App/App/Assets.xcassets/AppIcon.appiconset';
const TARGET_IOS_SPLASH = 'ios/App/App/Assets.xcassets/Splash.imageset';

const SOURCE_ANDROID_ICON = 'resources/android/icon';
const SOURCE_ANDROID_SPLASH = 'resources/android/splash';

const TARGET_ANDROID_ICON = 'android/app/src/main/res';
const TARGET_ANDROID_SPLASH = 'android/app/src/main/res';

const IOS_ICONS = [
{ source: 'icon-20.png', target: 'AppIcon-20x20@1x.png' },
{ source: 'icon-20@2x.png', target: 'AppIcon-20x20@2x.png' },
{ source: 'icon-20@2x.png', target: 'AppIcon-20x20@2x-1.png' },
{ source: 'icon-20@3x.png', target: 'AppIcon-20x20@3x.png' },
{ source: 'icon-29.png', target: 'AppIcon-29x29@1x.png' },
{ source: 'icon-29@2x.png', target: 'AppIcon-29x29@2x.png' },
{ source: 'icon-29@2x.png', target: 'AppIcon-29x29@2x-1.png' },
{ source: 'icon-29@3x.png', target: 'AppIcon-29x29@3x.png' },
{ source: 'icon-40.png', target: 'AppIcon-40x40@1x.png' },
{ source: 'icon-40@2x.png', target: 'AppIcon-40x40@2x.png' },
{ source: 'icon-40@2x.png', target: 'AppIcon-40x40@2x-1.png' },
{ source: 'icon-40@3x.png', target: 'AppIcon-40x40@3x.png' },
{ source: 'icon-60@2x.png', target: 'AppIcon-60x60@2x.png' },
{ source: 'icon-60@3x.png', target: 'AppIcon-60x60@3x.png' },
{ source: 'icon-76.png', target: 'AppIcon-76x76@1x.png' },
{ source: 'icon-76@2x.png', target: 'AppIcon-76x76@2x.png' },
{ source: 'icon-83.5@2x.png', target: 'AppIcon-83.5x83.5@2x.png' },
{ source: 'icon-1024.png', target: 'AppIcon-512@2x.png' }
];

const IOS_SPLASHES = [
{ source: 'Default-Portrait@~ipadpro.png', target: 'splash-2732x2732.png' },
{ source: 'Default-Portrait@~ipadpro.png', target: 'splash-2732x2732-1.png' },
{ source: 'Default-Portrait@~ipadpro.png', target: 'splash-2732x2732-2.png' }
];

const ANDROID_ICONS = [
{ source: 'drawable-ldpi-icon.png', target: 'drawable-hdpi-icon.png' },
{ source: 'drawable-mdpi-icon.png', target: 'mipmap-mdpi/ic_launcher.png' },
{ source: 'drawable-mdpi-icon.png', target: 'mipmap-mdpi/ic_launcher_round.png' },
{ source: 'drawable-mdpi-icon.png', target: 'mipmap-mdpi/ic_launcher_foreground.png' },
{ source: 'drawable-hdpi-icon.png', target: 'mipmap-hdpi/ic_launcher.png' },
{ source: 'drawable-hdpi-icon.png', target: 'mipmap-hdpi/ic_launcher_round.png' },
{ source: 'drawable-hdpi-icon.png', target: 'mipmap-hdpi/ic_launcher_foreground.png' },
{ source: 'drawable-xhdpi-icon.png', target: 'mipmap-xhdpi/ic_launcher.png' },
{ source: 'drawable-xhdpi-icon.png', target: 'mipmap-xhdpi/ic_launcher_round.png' },
{ source: 'drawable-xhdpi-icon.png', target: 'mipmap-xhdpi/ic_launcher_foreground.png' },
{ source: 'drawable-xxhdpi-icon.png', target: 'mipmap-xxhdpi/ic_launcher.png' },
{ source: 'drawable-xxhdpi-icon.png', target: 'mipmap-xxhdpi/ic_launcher_round.png' },
{ source: 'drawable-xxhdpi-icon.png', target: 'mipmap-xxhdpi/ic_launcher_foreground.png' },
{ source: 'drawable-xxxhdpi-icon.png', target: 'mipmap-xxxhdpi/ic_launcher.png' },
{ source: 'drawable-xxxhdpi-icon.png', target: 'mipmap-xxxhdpi/ic_launcher_round.png' },
{ source: 'drawable-xxxhdpi-icon.png', target: 'mipmap-xxxhdpi/ic_launcher_foreground.png' }
];

const ANDROID_SPLASHES = [
{ source: 'drawable-land-mdpi-screen.png', target: 'drawable/splash.png' },
{ source: 'drawable-land-mdpi-screen.png', target: 'drawable-land-mdpi/splash.png' },
{ source: 'drawable-land-hdpi-screen.png', target: 'drawable-land-hdpi/splash.png' },
{ source: 'drawable-land-xhdpi-screen.png', target: 'drawable-land-xhdpi/splash.png' },
{ source: 'drawable-land-xxhdpi-screen.png', target: 'drawable-land-xxhdpi/splash.png' },
{ source: 'drawable-land-xxxhdpi-screen.png', target: 'drawable-land-xxxhdpi/splash.png' },
{ source: 'drawable-port-mdpi-screen.png', target: 'drawable-port-mdpi/splash.png' },
{ source: 'drawable-port-hdpi-screen.png', target: 'drawable-port-hdpi/splash.png' },
{ source: 'drawable-port-xhdpi-screen.png', target: 'drawable-port-xhdpi/splash.png' },
{ source: 'drawable-port-xxhdpi-screen.png', target: 'drawable-port-xxhdpi/splash.png' },
{ source: 'drawable-port-xxxhdpi-screen.png', target: 'drawable-port-xxxhdpi/splash.png' }
];

/**
* Functions
* =============================================================================
*/

function copyAssets(sourcePath, targetPath, assets, verbose = false) {
assets.forEach(asset => {
const source = path.join(sourcePath, asset.source);
const target = path.join(targetPath, asset.target);

fs.copyFile(source, target, err => {
if (err) {
console.error(err);
throw err;
}

if (verbose) {
console.log({ source, target });
}
});
});
}

/**
* Execution
* =============================================================================
*/

const argv = minimist(process.argv.slice(2));
const PLATFORM = argv._.find(val => Object.values(Platform).includes(val));
const VERBOSE = argv.verbose || argv.v;

if (VERBOSE) {
process.env.DEBUG = '*';
console.log(process.argv, argv._);
console.log({ PLATFORM, VERBOSE });
}

if (PLATFORM === Platform.Android) {
copyAssets(SOURCE_ANDROID_ICON, TARGET_ANDROID_ICON, ANDROID_ICONS, VERBOSE);
copyAssets(SOURCE_ANDROID_SPLASH, TARGET_ANDROID_SPLASH, ANDROID_SPLASHES, VERBOSE);
}

if (PLATFORM === Platform.Ios) {
copyAssets(SOURCE_IOS_ICON, TARGET_IOS_ICON, IOS_ICONS, VERBOSE);
copyAssets(SOURCE_IOS_SPLASH, TARGET_IOS_SPLASH, IOS_SPLASHES, VERBOSE);
}
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@d4h/capacitor-res",
"version": "1.0.0",
"description": "Copy assets generated by cordova-res into Ionic Capacitor platforms.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"capacitor-res": "./index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/D4H/capacitor-res.git"
},
"keywords": [
"capacitor",
"ionic",
"cordova-res",
"capacitor-res"
],
"author": {
"name": "Dale Zak",
"email": "dalezak@gmail.com",
"url": "https://github.com/dalezak"
},
"contributors": [
{
"name": "Mark Grealish",
"email": "mark.grealish@d4h.org",
"url": "https://github.com/orgs/D4H/people"
}
],
"license": "MIT",
"bugs": {
"url": "https://github.com/D4H/capacitor-res/issues"
},
"homepage": "https://github.com/D4H/capacitor-res#readme",
"dependencies": {
"minimist": "^1.2.0"
},
"devDependencies": {
"@types/node": "^12.12.11"
}
}

0 comments on commit e29a44b

Please sign in to comment.