Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit a30b801

Browse files
authored
Merge pull request #77 from pwa-builder/master
Merging master into outdated dev
2 parents 07401d4 + 65298d6 commit a30b801

File tree

11 files changed

+7015
-481
lines changed

11 files changed

+7015
-481
lines changed

lib/fileTools.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,60 @@ function searchFile (dir, fileName, callback) {
150150
});
151151
}
152152

153+
// uses the folderScanSync to grab absolute paths of all files and folders, deleting folders (deepest first) and moving files to the target
154+
// requires an absolute path for sourcePath and targetFolderPath.
155+
function flattenFolderStructureSync(sourcePath, targetFolderPath, callback) {
156+
return Q.resolve().then(function () {
157+
var output = folderScanSync(sourcePath);
158+
159+
// move/copy files
160+
output.files.forEach(file => {
161+
fs.renameSync(file, path.resolve(targetFolderPath, path.parse(file).base), (err) => {
162+
return callback(err);
163+
});
164+
});
165+
166+
// remove directories
167+
output.folders.forEach(folder => {
168+
fs.rmdirSync(folder, (err) => {
169+
callback(err);
170+
});
171+
});
172+
173+
return Q.resolve();
174+
}).nodeify(callback);
175+
}
176+
177+
// queues new entries into the unexplored paths, and iterates through it, execution stops when all reaches end.
178+
// output is an object: { files: [], folders: [] }, the order of the files and object is reversed of traversal order
179+
function folderScanSync(directory) {
180+
const unexplored = [directory];
181+
const folders = [];
182+
const files = [];
183+
184+
for (let i = 0; i < unexplored.length; i++) {
185+
const currentPath = unexplored[i];
186+
fs.readdirSync(currentPath)
187+
.forEach(function (fileEntry) {
188+
var fileEntryPath = path.join(currentPath, fileEntry);
189+
190+
if (fs.statSync(fileEntryPath).isDirectory()) {
191+
unexplored.push(fileEntryPath);
192+
folders.push(fileEntryPath);
193+
} else {
194+
files.push(fileEntryPath);
195+
}
196+
});
197+
}
198+
199+
return {
200+
folders: folders.reverse(),
201+
files: files.reverse()
202+
};
203+
}
204+
205+
// Copies the 'source' file to 'target' if it's missing after creating the
206+
// required directory structure.
153207
function syncFile (source, target, callback) {
154208

155209
return stat(target).then(function (info) {
@@ -276,5 +330,7 @@ module.exports = {
276330
createShortcut: createShortcut,
277331
replaceFileContent: replaceFileContent,
278332
searchFile: searchFile,
279-
syncFiles: syncFiles
333+
syncFiles: syncFiles,
334+
flattenFolderStructure: flattenFolderStructureSync,
335+
folderScanSync: folderScanSync
280336
};

lib/manifestTools/assets/web-manifest.json

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"format": "uri"
4040
},
4141
"theme_color": {
42-
"description": "background color for splash screen and icons",
42+
"description": "The default theme color for the browsing contexts of an application",
4343
"type": "string"
4444
},
4545
"dir": {
@@ -68,8 +68,29 @@
6868
"prefer_related_applications": {
6969
"description": "A boolean value that is used as a hint for the user agent to say that related applications should be preferred over the web application.",
7070
"type": "boolean"
71+
},
72+
"categories": {
73+
"description": "An array of strings defining the expected application categories to which the web application belongs. While any string is considered valid, W3C maintains a list of known category strings at https://github.com/w3c/manifest/wiki/Categories",
74+
"type": "array"
75+
},
76+
"screenshots": {
77+
"description": "An array of images representing the application in common usage scenarios.",
78+
"type": "array",
79+
"items": {
80+
"$ref": "#/definitions/icon"
81+
}
82+
},
83+
"iarc_rating_id": {
84+
"description": "The International Age Rating Coalition (IARC) certification code of the web application. It is intended to be used to determine which ages the web application is appropriate for.",
85+
"type": "string"
86+
},
87+
"shortcuts": {
88+
"description": "An array of shortcut items that provide access to key tasks within a web application.",
89+
"type": "array",
90+
"items": {
91+
"$ref": "#/definitions/shortcutItem"
92+
}
7193
}
72-
7394
},
7495

7596
"definitions": {
@@ -97,6 +118,15 @@
97118
"description": "The type member of an icon is a hint as to the media type of the icon.",
98119
"type": "string",
99120
"pattern": "^[\\sa-z0-9\\-+;\\.=\\/]+$"
121+
},
122+
"purpose": {
123+
"description": "An unordered set of unique space-separated tokens that are ASCII case-insensitive. The allowed values are the icon purposes.",
124+
"type": "string",
125+
"enum": [ "badge", "maskable", "any" ]
126+
},
127+
"platform": {
128+
"description": "The platform to which a containing object applies.",
129+
"type": "string"
100130
}
101131
}
102132
},
@@ -117,6 +147,35 @@
117147
"type": "string"
118148
}
119149
}
150+
},
151+
"shortcutItem": {
152+
"type": "object",
153+
"properties": {
154+
"name": {
155+
"description": "The name of the shortcut as it is usually displayed to the user in a context menu.",
156+
"type": "string"
157+
},
158+
"short_name": {
159+
"description": "A short version of the name of the shortcut. It is intended to be used where there is insufficient space to display the full name of the shortcut.",
160+
"type": "string"
161+
},
162+
"description": {
163+
"description": "Describes the purpose of the shortcut. User agents MAY expose this information to assistive technology",
164+
"type": "string"
165+
},
166+
"url": {
167+
"description": "The URL within the application's scope that opens when the associated shortcut is activated.",
168+
"type": "string",
169+
"format": "uri"
170+
},
171+
"icons": {
172+
"description": "The images to serve as iconic representations of the shortcut in various contexts.",
173+
"type": "array",
174+
"items": {
175+
"$ref": "#/definitions/icon"
176+
}
177+
}
178+
}
120179
}
121180
}
122181
}

lib/manifestTools/manifestCreator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ function manifestCreator(opts, callback) {
3939
'Dir',
4040
'Lang',
4141
'Name',
42+
'Short_name',
4243
'Icons',
4344
'Scope',
4445
'Display',
4546
'Start_url',
46-
'Short_name',
47+
'Background_color',
4748
'Theme_color',
4849
'Description',
4950
'Orientation',
50-
'Background_color',
5151
'Related_applications',
5252
'Prefer_related_applications'
5353
].map(function(name) {

lib/manifestTools/manifestLoader.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ var constants = require('../constants'),
2020
var manifestCreator = require('./manifestCreator');
2121

2222
// Request settings taken from https://github.com/InternetExplorer/modern.IE-static-code-scan/blob/master/app.js
23+
// Then the user agent is updated to that of a PWA-capable browser
2324
var request = request.defaults({
2425
followAllRedirects: true,
2526
encoding: null,
2627
gzip: true,
2728
jar: false,
29+
rejectUnauthorized: false,
2830
headers: {
2931
'Accept': 'text/html, application/xhtml+xml, */*',
3032
'Accept-Language': 'en-US,en;q=0.5',
31-
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)'
33+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
3234
}
3335
});
3436

@@ -48,7 +50,8 @@ function fetchManifestUrlFromSite (siteUrl, callback) {
4850
if (manifestUrl) {
4951
var parsedManifestUrl = url.parse(manifestUrl);
5052
if (!parsedManifestUrl.host) {
51-
manifestUrl = url.resolve(siteUrl, parsedManifestUrl.pathname);
53+
var searchOrEmpty = parsedManifestUrl.search || "";
54+
manifestUrl = url.resolve(siteUrl, parsedManifestUrl.pathname + searchOrEmpty);
5255
}
5356
}
5457

@@ -218,7 +221,7 @@ function generateImagesForManifest(image, manifest, options, callback) {
218221
}
219222
};
220223

221-
var imgGenerationSvc = options.generationSvcUrl || constants.IMG_GEN_SVC_URL;
224+
var imgGenerationSvc = constants.IMG_GEN_SVC_URL || 'https://appimagegenerator-prod.azurewebsites.net';
222225
log.debug('Generating images from app image generation service: ' + imgGenerationSvc);
223226
return Q.nfcall(request.post, { url: _url.resolve(imgGenerationSvc, constants.IMG_GEN_SVC_API), formData: formData })
224227
.then(function(response) {

0 commit comments

Comments
 (0)