@quasar/icongenie 2.5.0 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/icongenie CHANGED
@@ -58,4 +58,4 @@ else {
58
58
  }
59
59
 
60
60
  console.log()
61
- require(`./icongenie-${cmd}`)
61
+ require(`../lib/cmd/${cmd}`)
@@ -1,171 +1,188 @@
1
- const { existsSync } = require('fs')
2
- const { ensureFileSync } = require('fs-extra')
3
- const { green, gray } = require('kolorist')
4
1
 
5
- const { appDir, resolveDir } = require('../utils/app-paths')
6
- const { log, warn } = require('../utils/logger')
7
-
8
- const modes = require('../modes')
9
- const generators = require('../generators')
10
- const { mount } = require('../mount')
11
-
12
- const getAssetsFiles = require('../utils/get-assets-files')
13
- const getFilesOptions = require('../utils/get-files-options')
14
- const parseArgv = require('../utils/parse-argv')
15
- const mergeObjects = require('../utils/merge-objects')
16
- const getProfileContent = require('../utils/get-profile-content')
17
- const getFileSize = require('../utils/get-file-size')
18
- const validateProfileObject = require('../utils/validate-profile-object')
19
-
20
- function printBanner (assetsOf, params) {
21
- console.log(` Generating files with the following options:
22
- ==========================
23
- Quasar project folder..... ${green(appDir)}
24
- ${green(`Quality level............. ${params.quality}/12`)}
25
- Icon source file.......... ${green(params.icon)}
26
- Icon trimming............. ${params.skipTrim ? 'no' : green('yes')}
27
- Icon padding.............. ${green(`horizontal: ${params.padding[0]}; vertical: ${params.padding[1]}`)}
28
- Background source file.... ${params.background ? green(params.background) : 'none'}
29
- Assets of................. ${green(assetsOf)}
30
- Generator filter.......... ${params.filter ? green(params.filter) : 'none'}
31
- Svg color................. ${green(params.svgColor)}
32
- Png color................. ${green(params.pngColor)}
33
- Splashscreen color........ ${green(params.splashscreenColor)}
34
- Splashscreen icon ratio... ${green(params.splashscreenIconRatio)}%
35
- ==========================
36
- `)
37
- }
38
-
39
- function parseAssets (assets, include) {
40
- let files = []
41
- let assetsOf = []
42
-
43
- if (include) {
44
- const embeddedModes = include.filter(
45
- mode => existsSync(resolveDir(modes[mode].folder))
46
- )
47
-
48
- embeddedModes.forEach(mode => {
49
- files = files.concat(
50
- getAssetsFiles(modes[mode].assets)
51
- )
52
- })
53
-
54
- assetsOf = assetsOf.concat(embeddedModes)
55
- }
56
-
57
- if (assets && assets.length > 0) {
58
- files = files.concat(getAssetsFiles(assets))
59
- assetsOf.push('profile')
60
- }
61
-
62
- return {
63
- files,
64
- assetsOf: assetsOf.join(' | ')
65
- }
66
- }
67
-
68
- function getUniqueFiles (files) {
69
- const filePaths = {}
70
- const uniqueFiles = []
71
-
72
- files.forEach(file => {
73
- if (filePaths[file.absoluteName] === void 0) {
74
- filePaths[file.absoluteName] = true
75
- uniqueFiles.push(file)
76
- }
77
- })
78
-
79
- return uniqueFiles
2
+ const parseArgs = require('minimist')
3
+ const processArgv = process.argv.slice(2)
4
+
5
+ const argv = parseArgs(processArgv, {
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', 'skip-trim' ],
16
+ string: [
17
+ 'p', 'i', 'b', 'm', 'f', 'q',
18
+ 'padding',
19
+ 'theme-color',
20
+ 'png-color',
21
+ 'splashscreen-color',
22
+ 'svg-color',
23
+ 'splashscreen-icon-ratio'
24
+ ]
25
+ })
26
+
27
+ // if user hasn't explicitly specified this, then
28
+ // we shouldn't take it into account
29
+ if (processArgv.includes('--skip-trim') === false) {
30
+ delete argv['skip-trim']
80
31
  }
81
32
 
82
- function generateFile (file, opts) {
83
- // ensure that the file (and its folder) exists
84
- ensureFileSync(file.absoluteName)
85
-
86
- return new Promise(resolve => {
87
- // use the appropriate generator to handle the file creation
88
- generators[file.generator](file, opts, () => {
89
- const size = `(${getFileSize(file.absoluteName)})`
90
- const type = (file.generator + ':').padEnd(13, ' ')
91
-
92
- log(`Generated ${type} ${green(file.relativeName)} ${gray(size)}`)
93
- resolve()
94
- })
95
- })
33
+ const { green } = require('kolorist')
34
+
35
+ if (argv.help) {
36
+ const modes = Object.keys(require('../modes')).join('|')
37
+ const generators = Object.keys(require('../generators')).join('|')
38
+ const defaultParams = require('../utils/default-params')
39
+
40
+ console.log(`
41
+ Description
42
+ Generate App icons & splashscreens
43
+
44
+ Usage
45
+ $ icongenie generate [options]
46
+
47
+ # generate icons for all installed Quasar modes
48
+ $ icongenie generate -i /path/to/icon.png
49
+ $ icongenie g -i /path/to/icon.png
50
+
51
+ # generate for (as example) PWA mode only
52
+ $ icongenie generate -m pwa --icon /path/to/icon.png
53
+
54
+ # generate for (as example) Cordova & Capacitor mode only
55
+ $ icongenie g -m cordova,capacitor -i
56
+ /path/to/icon.png -b /path/to/background.png
57
+
58
+ # generate by using a profile file
59
+ $ icongenie generate -p ./icongenie-profile.json
60
+
61
+ # generate by using batch of profile files
62
+ $ icongenie generate -p ./folder-containing-profile-files
63
+
64
+ Options
65
+ --icon, -i ${green('Required')};
66
+ Path to source file for icon; must be:
67
+ - a .png file
68
+ - min resolution: 64x64 px (the higher the better!!)
69
+ - with transparency
70
+ Best results are with a square image (height = width)
71
+ Image will be trimmed automatically
72
+ (also see "skip-trim" and "padding" param)
73
+ Path can be absolute, or relative to the root of the
74
+ Quasar project folder
75
+ Recommended min size: 1024x1024 px
76
+
77
+ --background, -b Path to optional background source file (for splashscreens);
78
+ must be:
79
+ - a .png file
80
+ - min resolution: 128x128 px (the higher the better!!)
81
+ - transparency is optional (but recommended if you
82
+ combine with the splashscreen-color param)
83
+ Path can be absolute, or relative to the root of the
84
+ Quasar project folder
85
+ Recommended min size: 1024x1024 px
86
+
87
+ --mode, -m For which Quasar mode(s) to generate the assets;
88
+ Default: all
89
+ [all|${modes}]
90
+ Multiple can be specified, separated by ",":
91
+ spa,cordova
92
+
93
+ --filter, -f Filter the available generators; when used, it can
94
+ generate only one type of asset instead of all
95
+ [${generators}]
96
+
97
+ --quality Quality of the files [1 - 12] (default: ${defaultParams.quality})
98
+ - higher quality --> bigger filesize & slower to create
99
+ - lower quality --> smaller filesize & faster to create
100
+
101
+ --skip-trim Do not trim the icon source file
102
+
103
+ --padding Apply fixed padding to the icon after trimming it;
104
+ Syntax: <horiz: number>,<vert: number>
105
+ Default: 0,0
106
+ Example: "--padding 10,5" means apply 10px padding to top
107
+ 10px to bottom, 5px to left side and 5px to rightside
108
+
109
+ --theme-color Theme color to use for all generators requiring a color;
110
+ It gets overridden if any generator color is also specified;
111
+ The color must be in hex format (NOT hexa) without the leading
112
+ '#' character. Transparency not allowed.
113
+ Examples: 1976D2, eee
114
+
115
+ --svg-color Color to use for the generated monochrome svgs
116
+ Default (if no theme-color is specified): ${defaultParams.svgColor.slice(1)}
117
+ The color must be in hex format (NOT hexa) without the leading
118
+ '#' character. Transparency not allowed.
119
+ Examples: 1976D2, eee
120
+
121
+ --png-color Background color to use for the png generator, when
122
+ "background: true" in the asset definition (like for
123
+ the cordova/capacitor iOS icons);
124
+ Default (if no theme-color is specified): ${defaultParams.pngColor.slice(1)}
125
+ The color must be in hex format (NOT hexa) without the leading
126
+ '#' character. Transparency not allowed.
127
+ Examples: 1976D2, eee
128
+
129
+ --splashscreen-color Background color to use for the splashscreen generator;
130
+ Default (if no theme-color is specified): ${defaultParams.splashscreenColor.slice(1)}
131
+ The color must be in hex format (NOT hexa) without the leading
132
+ '#' character. Transparency not allowed.
133
+ Examples: 1976D2, eee
134
+
135
+ --splashscreen-icon-ratio Ratio of icon size in respect to the width or height
136
+ (whichever is smaller) of the resulting splashscreen;
137
+ Represents percentages; Valid values: 0 - 100
138
+ If 0 then it doesn't add the icon of top of background
139
+ Default: ${defaultParams.splashscreenIconRatio}
140
+
141
+ --profile, -p Use JSON profile file(s):
142
+ - path to folder (absolute or relative to current folder)
143
+ that contains JSON profile files (icongenie-*.json)
144
+ - path to a single *.json profile file (absolute or relative
145
+ to current folder)
146
+ Structure of a JSON profile file:
147
+ {
148
+ "params": {
149
+ "include": [ ... ], /* optional */
150
+ ...
151
+ },
152
+ "assets": [ /* list of custom assets */ ]
153
+ }
154
+
155
+ --help, -h Displays this message
156
+ `)
157
+ process.exit(0)
96
158
  }
97
159
 
98
- async function generateFromProfile (profile) {
99
- const params = profile.params
100
- const { assetsOf, files } = parseAssets(profile.assets, params.include)
101
-
102
- const fileOptions = await getFilesOptions(params)
103
- let uniqueFiles = getUniqueFiles(files)
104
-
105
- if (params.filter) {
106
- uniqueFiles = uniqueFiles.filter(
107
- file => file.generator === params.filter
108
- )
109
- }
110
-
111
- if (uniqueFiles.length === 0) {
112
- warn(`No assets to generate! No mode/include specified, filter too specific or the respective Quasar mode(s) are not installed`)
113
- return Promise.resolve(0)
160
+ const parseArgv = require('../utils/parse-argv')
161
+ const generate = require('../runner/generate')
162
+ const getProfileFiles = require('../utils/get-profile-files')
163
+ const filterArgvParams = require('../utils/filter-argv-params')
164
+ const { log } = require('../utils/logger')
165
+
166
+ async function runProfiles (params, profileFiles) {
167
+ for (let i = 0; i < profileFiles.length; i++) {
168
+ const profile = profileFiles[i]
169
+
170
+ console.log(`\n`)
171
+ log(`---------------------`)
172
+ log(`Generating by profile: ${profile}`)
173
+ log(`---------------------`)
174
+ console.log(`\n`)
175
+
176
+ await generate({ ...params, profile })
114
177
  }
115
-
116
- printBanner(assetsOf, params)
117
-
118
- return Promise
119
- .all(uniqueFiles.map(file => generateFile(file, fileOptions)))
120
- .then(() => { mount(uniqueFiles) })
121
- .then(() => uniqueFiles.length)
122
178
  }
123
179
 
124
- module.exports = function generate (argv) {
125
- const profile = {
126
- params: {},
127
- assets: []
128
- }
129
-
130
- if (argv.profile) {
131
- parseArgv(argv, [ 'profile' ])
132
-
133
- const userProfile = getProfileContent(argv.profile)
134
-
135
- if (userProfile.params) {
136
- const { profile: _, ...params } = argv
180
+ const params = filterArgvParams(argv)
137
181
 
138
- profile.params = mergeObjects(userProfile.params, params)
139
- parseArgv(profile.params, [ 'include' ])
140
- }
141
- if (userProfile.assets) {
142
- profile.assets = userProfile.assets
143
- }
144
- }
145
- else {
146
- parseArgv(argv, [ 'mode' ])
147
-
148
- const { mode, ...params } = argv
149
-
150
- profile.params = params
151
- profile.params.include = mode
152
- }
153
-
154
- profile.params = mergeObjects({}, profile.params)
155
-
156
- parseArgv(profile.params, [
157
- 'quality', 'filter', 'padding',
158
- 'icon', 'background',
159
- 'splashscreenIconRatio',
160
- // order matters:
161
- 'themeColor', 'pngColor', 'splashscreenColor', 'svgColor'
162
- ])
163
-
164
- // final thorough validation
165
- validateProfileObject(profile)
166
-
167
- return generateFromProfile(profile)
168
- .then(numberOfFiles => {
169
- console.log(`\n Task done - generated ${numberOfFiles} file(s)!\n`)
170
- })
182
+ if (params.profile) {
183
+ parseArgv(params, [ 'profile' ])
184
+ runProfiles(params, getProfileFiles(params.profile))
185
+ }
186
+ else {
187
+ generate(params)
171
188
  }
@@ -1,6 +1,5 @@
1
- #!/usr/bin/env node
2
1
 
3
- console.log(' Running @quasar/icongenie v' + require('../package.json').version)
2
+ console.log(' Running @quasar/icongenie v' + require('../../package.json').version)
4
3
 
5
4
  console.log(`
6
5
  Example usage
@@ -1,62 +1,149 @@
1
- const { resolve, dirname, basename } = require('path')
2
- const { writeFileSync } = require('fs')
3
- const { ensureDir } = require('fs-extra')
4
1
 
5
- const { log } = require('../utils/logger')
6
- const modes = require('../modes')
7
- const validateProfileObject = require('../utils/validate-profile-object')
8
-
9
- function getParams ({ include, ...props }) {
10
- if (include) {
11
- props.include = include.split(',')
12
- }
13
-
14
- return props
15
- }
16
-
17
- function getAssets (assets) {
18
- let list = []
19
-
20
- assets.forEach(name => {
21
- list = list.concat(modes[name].assets)
22
- })
23
-
24
- return list
25
- }
26
-
27
- function getTargetFilepath (output) {
28
- const folder = dirname(output)
29
- const name = basename(output)
30
-
31
- const prefix = name.startsWith('icongenie-')
32
- ? ''
33
- : 'icongenie-'
34
-
35
- const suffix = name.endsWith('.json')
36
- ? ''
37
- : '.json'
38
-
39
- const filename = `${prefix}${name}${suffix}`
40
- return resolve(process.cwd(), folder || '', filename)
2
+ const parseArgs = require('minimist')
3
+
4
+ const argv = parseArgs(process.argv.slice(2), {
5
+ alias: {
6
+ o: 'output',
7
+ a: 'assets',
8
+
9
+ i: 'icon',
10
+ b: 'background',
11
+ f: 'filter',
12
+ q: 'quality',
13
+ h: 'help'
14
+ },
15
+ boolean: [ 'h', 'skip-trim' ],
16
+ string: [
17
+ 'o', 'a',
18
+ 'i', 'b', 'include', 'f', 'q',
19
+ 'padding',
20
+ 'theme-color',
21
+ 'png-color',
22
+ 'splashscreen-color',
23
+ 'svg-color',
24
+ 'splashscreen-icon-ratio'
25
+ ]
26
+ })
27
+
28
+ if (argv.help) {
29
+ const modes = Object.keys(require('../modes')).join('|')
30
+ const generators = Object.keys(require('../generators')).join('|')
31
+ const defaultParams = require('../utils/default-params')
32
+
33
+ console.log(`
34
+ Description
35
+ Helper command to easily bootstrap Icon Genie profile files.
36
+
37
+ Usage
38
+ $ icongenie profile -o <filename> [options]
39
+
40
+ # supplying params list
41
+ $ icongenie profile -o <filename> --include pwa,spa --quality 7
42
+
43
+ # supplying assets based on Icon Genie's internal list
44
+ $ icongenie profile -o <filename> --assets spa,bex
45
+
46
+ Options
47
+ --output, -o Name of the new Icon Genie profile file
48
+
49
+ --assets, -a Prefill the assets Array with Icon Genie's
50
+ internal list, based on the modes that you indicate;
51
+ [all|${modes}]
52
+ Multiple can be specified, separated by ",":
53
+ spa,cordova
54
+
55
+ --icon, -i Path to source file for icons; must be:
56
+ - a .png file
57
+ - min resolution: 64x64 px (the higher the better!!)
58
+ - with transparency
59
+ Best results are with a square image (height = width)
60
+ Image will be trimmed automatically
61
+ (also see "skip-trim" and "padding" param)
62
+ Path can be absolute, or relative to the root of the
63
+ Quasar project folder
64
+ Recommended min size: 1024x1024 px
65
+
66
+ --background, -b Path to optional background source file (for splashscreens);
67
+ must be:
68
+ - a .png file
69
+ - min resolution: 128x128 px (the higher the better!!)
70
+ - transparency is optional (but recommended if you
71
+ combine with the splashscreen-color param)
72
+ Path can be absolute, or relative to the root of the
73
+ Quasar project folder
74
+ Recommended min size: 1024x1024 px
75
+
76
+ --include Prefill the params.include property;
77
+ [all|${modes}]
78
+ Multiple can be specified, separated by ",":
79
+ spa,cordova
80
+
81
+ --filter, -f Prefill the params.filter property;
82
+ [${generators}]
83
+
84
+ --quality Prefill in the params.quality property;
85
+ Quality of the files [1 - 12] (default: ${defaultParams.quality})
86
+ - higher quality --> bigger filesize & slower to create
87
+ - lower quality --> smaller filesize & faster to create
88
+
89
+ --skip-trim Do not trim the icon source file
90
+
91
+ --padding Apply fixed padding to the icon after trimming it;
92
+ Syntax: <horiz: number>,<vert: number>
93
+ Default: 0,0
94
+ Example: "--padding 10,5" means apply 10px padding to top
95
+ 10px to bottom, 5px to left side and 5px to rightside
96
+
97
+ --theme-color Prefill the params.themeColor property;
98
+ Theme color to use for all generators requiring a color;
99
+ It gets overridden if any generator color is also specified;
100
+ The color must be in hex format (NOT hexa) without the leading
101
+ '#' character. Transparency not allowed.
102
+ Examples: 1976D2, eee
103
+
104
+ --svg-color Prefill the params.svgColor property;
105
+ Color to use for the generated monochrome svgs
106
+ Default (if no theme-color is specified): ${defaultParams.svgColor.slice(1)}
107
+ The color must be in hex format (NOT hexa) without the leading
108
+ '#' character. Transparency not allowed.
109
+ Examples: 1976D2, eee
110
+
111
+ --png-color Prefill the params.pngColor property;
112
+ Background color to use for the png generator, when
113
+ "background: true" in the asset definition (like for
114
+ the Cordova/Capacitor iOS icons);
115
+ Default (if no theme-color is specified): ${defaultParams.pngColor.slice(1)}
116
+ The color must be in hex format (NOT hexa) without the leading
117
+ '#' character. Transparency not allowed.
118
+ Examples: 1976D2, eee
119
+
120
+ --splashscreen-color Prefill the params.splashscreenColor property;
121
+ Background color to use for the splashscreen generator;
122
+ Default (if no theme-color is specified): ${defaultParams.splashscreenColor.slice(1)}
123
+ The color must be in hex format (NOT hexa) without the leading
124
+ '#' character. Transparency not allowed.
125
+ Examples: 1976D2, eee
126
+
127
+ --splashscreen-icon-ratio Prefill the params.splashscreenIconRatio property;
128
+ Ratio of icon size in respect to the width or height
129
+ (whichever is smaller) of the resulting splashscreen;
130
+ Represents percentages; Valid values: 0 - 100
131
+ If 0 then it doesn't add the icon of top of background
132
+ Default: ${defaultParams.splashscreenIconRatio}
133
+ `)
134
+ process.exit(0)
41
135
  }
42
136
 
43
- module.exports = function profile ({ output, assets, ...params }) {
44
- const profile = {
45
- params: getParams(params),
46
- assets: getAssets(assets)
47
- }
137
+ const profile = require('../runner/profile')
138
+ const filterArgvParams = require('../utils/filter-argv-params')
139
+ const parseArgv = require('../utils/parse-argv')
48
140
 
49
- validateProfileObject(profile, true)
141
+ parseArgv(argv, [
142
+ 'output',
143
+ 'assets',
144
+ 'padding'
145
+ ])
50
146
 
51
- const targetFile = getTargetFilepath(output)
52
- const folderName = dirname(targetFile)
147
+ const params = filterArgvParams(argv)
53
148
 
54
- if (folderName) {
55
- ensureDir(folderName)
56
- }
57
-
58
- writeFileSync(targetFile, JSON.stringify(profile, null, 2), 'utf-8')
59
-
60
- console.log(` Generated Icon Genie profile file:`)
61
- log(`${targetFile}\n`)
62
- }
149
+ profile(params)