|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const parseArgs = require('minimist') |
| 4 | + |
| 5 | +const argv = parseArgs(process.argv.slice(2), { |
| 6 | + alias: { |
| 7 | + p: 'profile', // config file |
| 8 | + i: 'icon', |
| 9 | + b: 'background', |
| 10 | + m: 'mode', |
| 11 | + f: 'filter', |
| 12 | + q: 'quality', |
| 13 | + h: 'help' |
| 14 | + }, |
| 15 | + boolean: [ 'h' ], |
| 16 | + string: [ |
| 17 | + 'p', 'i', 'b', 'm', 'f', 'q', |
| 18 | + 'theme-color', |
| 19 | + 'png-color', |
| 20 | + 'splashscreen-color', |
| 21 | + 'svg-color', |
| 22 | + 'splashscreen-icon-ratio' |
| 23 | + ] |
| 24 | +}) |
| 25 | + |
| 26 | +const { green } = require('chalk') |
| 27 | + |
| 28 | +if (argv.help) { |
| 29 | + const modes = Object.keys(require('../lib/modes')).join('|') |
| 30 | + const generators = Object.keys(require('../lib/generators')).join('|') |
| 31 | + const defaultParams = require('../lib/utils/default-params') |
| 32 | + |
| 33 | + console.log(` |
| 34 | + Description |
| 35 | + Generate App icons & splashscreens |
| 36 | +
|
| 37 | + Usage |
| 38 | + $ icongenie generate [options] |
| 39 | +
|
| 40 | + # generate icons for all installed Quasar modes |
| 41 | + $ icongenie generate -i /path/to/icon.png |
| 42 | + $ icongenie g -i /path/to/icon.png |
| 43 | +
|
| 44 | + # generate for (as example) PWA mode only |
| 45 | + $ icongenie generate -m pwa --icon /path/to/icon.png |
| 46 | +
|
| 47 | + # generate for (as example) Cordova & Capacitor mode only |
| 48 | + $ icongenie g -m cordova,capacitor -i |
| 49 | + /path/to/icon.png -b /path/to/background.png |
| 50 | +
|
| 51 | + # generate by using a profile file |
| 52 | + $ icongenie generate -p ./icongenie-profile.json |
| 53 | +
|
| 54 | + # generate by using batch of profile files |
| 55 | + $ icongenie generate -p ./folder-containing-profile-files |
| 56 | +
|
| 57 | + Options |
| 58 | + --icon, -i ${green('Required')}; |
| 59 | + Path to source file for icon; must be: |
| 60 | + - a .png file |
| 61 | + - min resolution: 64x64 px (the higher the better!!) |
| 62 | + - with transparency |
| 63 | + Path can be absolute, or relative to the root of the |
| 64 | + Quasar project folder |
| 65 | + Recommended min size: 1024x1024 px |
| 66 | +
|
| 67 | + --background, -b Path to optional background source file (for splashscreens); |
| 68 | + must be: |
| 69 | + - a .png file |
| 70 | + - min resolution: 128x128 px (the higher the better!!) |
| 71 | + - transparency is optional |
| 72 | + Path can be absolute, or relative to the root of the |
| 73 | + Quasar project folder |
| 74 | + Recommended min size: 1024x1024 px |
| 75 | +
|
| 76 | + --mode, -m For which Quasar mode(s) to generate the assets; |
| 77 | + Default: all |
| 78 | + [all|${modes}] |
| 79 | + Multiple can be specified, separated by ",": |
| 80 | + spa,cordova |
| 81 | +
|
| 82 | + --filter, -f Filter the available generators; when used, it can |
| 83 | + generate only one type of asset instead of all |
| 84 | + [${generators}] |
| 85 | +
|
| 86 | + --quality Quality of the files [1 - 12] (default: ${defaultParams.quality}) |
| 87 | + - higher quality --> bigger filesize, slower |
| 88 | + - lower quality --> smaller filesize, faster |
| 89 | +
|
| 90 | + --theme-color Theme color to use for all generators requiring a color; |
| 91 | + It gets overriden if any generator color is also specified; |
| 92 | + The color must be in hex format (NOT hexa) without the leading |
| 93 | + '#' character. Transparency not allowed. |
| 94 | + Examples: 1976D2, eee |
| 95 | +
|
| 96 | + --svg-color Color to use for the generated monochrome svgs |
| 97 | + Default (if no theme-color is specified): ${defaultParams.svgColor.slice(1)} |
| 98 | + The color must be in hex format (NOT hexa) without the leading |
| 99 | + '#' character. Transparency not allowed. |
| 100 | + Examples: 1976D2, eee |
| 101 | +
|
| 102 | + --png-color Background color to use for the png generator, when |
| 103 | + "background: true" in the asset definition (like for |
| 104 | + the cordova/capacitor iOS icons); |
| 105 | + Default (if no theme-color is specified): ${defaultParams.pngColor.slice(1)} |
| 106 | + The color must be in hex format (NOT hexa) without the leading |
| 107 | + '#' character. Transparency not allowed. |
| 108 | + Examples: 1976D2, eee |
| 109 | +
|
| 110 | + --splashscreen-color Background color to use for the splashscreen generator; |
| 111 | + Default (if no theme-color is specified): ${defaultParams.splashscreenColor.slice(1)} |
| 112 | + The color must be in hex format (NOT hexa) without the leading |
| 113 | + '#' character. Transparency not allowed. |
| 114 | + Examples: 1976D2, eee |
| 115 | +
|
| 116 | + --splashscreen-icon-ratio Ratio of icon size in respect to the width or height |
| 117 | + (whichever is smaller) of the resulting splashscreen; |
| 118 | + Represents percentages; Valid values: 0 - 100 |
| 119 | + If 0 then it doesn't adds any icon of top of background |
| 120 | + Default: ${defaultParams.splashscreenIconRatio} |
| 121 | +
|
| 122 | + --profile, -p Use JSON profile file(s): |
| 123 | + - path to folder (absolute or relative to current folder) |
| 124 | + that contains JSON profile files (icongenie-*.json) |
| 125 | + - path to a single *.json profile file (absolute or relative |
| 126 | + to current folder) |
| 127 | + Structure of a JSON profile file: |
| 128 | + { |
| 129 | + "params": { |
| 130 | + "include": [ ... ], /* optional */ |
| 131 | + ... |
| 132 | + }, |
| 133 | + "assets": [ /* list of custom assets */ ] |
| 134 | + } |
| 135 | +
|
| 136 | + --help, -h Displays this message |
| 137 | + `) |
| 138 | + process.exit(0) |
| 139 | +} |
| 140 | + |
| 141 | +const parseArgv = require('../lib/utils/parse-argv') |
| 142 | +const generate = require('../lib/cmd/generate') |
| 143 | +const getProfileFiles = require('../lib/utils/get-profile-files') |
| 144 | +const filterArgvParams = require('../lib/utils/filter-argv-params') |
| 145 | +const { log } = require('../lib/utils/logger') |
| 146 | + |
| 147 | +async function runProfiles (params, profileFiles) { |
| 148 | + for (let i = 0; i < profileFiles.length; i++) { |
| 149 | + const profile = profileFiles[i] |
| 150 | + |
| 151 | + console.log(`\n`) |
| 152 | + log(`---------------------`) |
| 153 | + log(`Generating by profile: ${profile}`) |
| 154 | + log(`---------------------`) |
| 155 | + console.log(`\n`) |
| 156 | + |
| 157 | + await generate({ ...params, profile }) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +const params = filterArgvParams(argv) |
| 162 | + |
| 163 | +if (params.profile) { |
| 164 | + parseArgv(params, [ 'profile' ]) |
| 165 | + runProfiles(params, getProfileFiles(params.profile)) |
| 166 | +} |
| 167 | +else { |
| 168 | + generate(params) |
| 169 | +} |
0 commit comments