Skip to content

Commit db97f2d

Browse files
authored
Merge pull request #25 from scriptex/feature/optional-components
Make separate components optional
2 parents 4e64c05 + caf22cd commit db97f2d

File tree

4 files changed

+91
-37
lines changed

4 files changed

+91
-37
lines changed

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ _.config.yml
4545
create-pwa.sketch
4646

4747
# Tests
48+
favicons
4849
icons
4950
launch-screens
51+
config.xml
52+
*.appcache
5053
manifest.json
5154
service-worker.js
52-
*.appcache

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ const appIcon = require('fs').resolve(__dirname, './your_icon.png');
440440
setIcons(appIcon);
441441
```
442442

443+
**The generated icons are located in the `/icons` folder.**
444+
443445
3. To create only the launch screens:
444446

445447
```javascript
@@ -449,6 +451,8 @@ const launchScreen = require('fs').resolve(__dirname, './your_launch_screen.png'
449451
setLaunchScreens(launchScreen);
450452
```
451453

454+
**The generated files are located in the `/launch-screens` folder.**
455+
452456
4. To create only manifest file:
453457

454458
```javascript
@@ -460,31 +464,27 @@ setManifest(appName);
460464

461465
**The generated `manifest.json` file contains references to the application icons. You must have these already generated otherwise you must edit your `manifest.json` file and remove them.**
462466

463-
5. To create only service worker file:
467+
5. To create only favicon files:
464468

465469
```javascript
466-
const { setServiceWorker } = require('create-pwa');
467-
const appName = 'Your application name';
470+
const { setFavicons } = require('create-pwa');
471+
const appIcon = require('fs').resolve(__dirname, './your_icon.png');
468472

469-
setServiceWorker(appName);
473+
setFavicons(appIcon);
470474
```
471475

472-
**The generated `service-worker.js` file contains references to the application icons and application launch screens. You must have these already generated otherwise you must edit your `service-worker.js` file and remove them.**
476+
**The generated files are located in the `/favicons` folder.**
473477

474-
6. To create all files:
478+
6. To create only service worker file:
475479

476480
```javascript
477-
const createPWA = require('create-pwa');
478-
const icon = require('fs').resolve(__dirname, './your_icon.png');
479-
const launch = require('fs').resolve(__dirname, './your_launch_screen.png');
480-
481-
createPWA({
482-
icon,
483-
launch
484-
});
481+
const { setServiceWorker } = require('create-pwa');
482+
const appName = 'Your application name';
483+
484+
setServiceWorker(appName);
485485
```
486486

487-
**This command assumes that you have a `package.json` file in the folder you run the command from and this `package.json` file contains a non-empty `name` member.**
487+
**The generated `service-worker.js` file contains references to the application icons and application launch screens. You must have these already generated otherwise you must edit your `service-worker.js` file and remove them.**
488488

489489
## LICENSE
490490

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "create-pwa",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Easily create a progressive web app",
55
"scripts": {
6+
"pwa": "src/index.js --icon=\"./icon.png\" --launch=\"./launch.png\" --icons=false --app-cache=false --manifest=false --favicons=false --service-worker=false --launch-screens=false",
67
"test": "tape test.js"
78
},
89
"bin": {

src/index.js

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,51 @@
66
const { resolve, sep } = require('path');
77
const { existsSync, writeFileSync, mkdirSync } = require('fs');
88

9+
/**
10+
* Default options
11+
*/
12+
const DEFAULTS = {
13+
icon: './icon.png',
14+
launch: './launch.png'
15+
};
16+
917
/**
1018
* External dependencies
1119
*/
12-
const argv = require('yargs').argv;
20+
const argv = require('yargs').options({
21+
icon: {
22+
default: DEFAULTS.icon,
23+
type: 'string'
24+
},
25+
launch: {
26+
default: DEFAULTS.launch,
27+
type: 'string'
28+
},
29+
icons: {
30+
default: true,
31+
type: 'boolean'
32+
},
33+
manifest: {
34+
default: true,
35+
type: 'boolean'
36+
},
37+
appCache: {
38+
default: true,
39+
type: 'boolean'
40+
},
41+
favicons: {
42+
default: true,
43+
type: 'boolean'
44+
},
45+
serviceWorker: {
46+
default: true,
47+
type: 'boolean'
48+
},
49+
launchScreens: {
50+
default: true,
51+
type: 'boolean'
52+
}
53+
}).argv;
1354

1455
/**
1556
* Internal dependencies
@@ -27,14 +68,6 @@ const serviceWorkerTemplate = require('./sw');
2768
*/
2869
const pwd = process.env.PWD;
2970

30-
/**
31-
* Default options
32-
*/
33-
const DEFAULTS = {
34-
icon: './icon.png',
35-
launch: './launch.png'
36-
};
37-
3871
/**
3972
* Get application's name
4073
*/
@@ -122,23 +155,41 @@ const setFavicons = icon => generateImages(icon, 'favicons', generateFavicons);
122155
* Create all PWA required files
123156
* @param {Object} => { icon: File, launch: File}
124157
*/
125-
const create = (options = DEFAULTS) => {
158+
const create = () => {
126159
const name = getAppName();
127160

128-
let { icon, launch } = options;
161+
const { icon, launch, icons, manifest, favicons, appCache, serviceWorker, launchScreens } = argv;
162+
const iconToUse = icon || DEFAULTS.icon;
163+
const launchToUse = launch || DEFAULTS.launch;
164+
165+
if (icons) {
166+
setIcons(iconToUse);
167+
}
168+
169+
if (manifest) {
170+
setManifest(name);
171+
}
172+
173+
if (appCache) {
174+
setAppCache(name);
175+
}
129176

130-
icon = argv.icon || icon;
131-
launch = argv.launch || launch;
177+
if (favicons) {
178+
setFavicons(iconToUse);
179+
setMsTileConfig();
180+
}
132181

133-
setIcons(icon);
134-
setAppCache(name);
135-
setManifest(name);
136-
setFavicons(icon);
137-
setMsTileConfig();
138-
setServiceWorker(name);
139-
setLaunchScreens(launch);
182+
if (serviceWorker) {
183+
setServiceWorker(name);
184+
}
185+
186+
if (launchScreens) {
187+
setLaunchScreens(launchToUse);
188+
}
140189
};
141190

191+
create();
192+
142193
module.exports = create;
143194
module.exports.setIcons = setIcons;
144195
module.exports.setAppCache = setAppCache;

0 commit comments

Comments
 (0)