mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-17 03:51:13 +02:00
eslint fixes
This commit is contained in:
@@ -13,7 +13,7 @@ export const commandPaletteService = {
|
|||||||
publish(eventName, ...args) {
|
publish(eventName, ...args) {
|
||||||
const callbacks = this.subscriptions[eventName] || [];
|
const callbacks = this.subscriptions[eventName] || [];
|
||||||
callbacks.forEach(callback => {
|
callbacks.forEach(callback => {
|
||||||
callback.apply(null, args);
|
callback(...args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,3 @@
|
|||||||
import { deferred } from './deferred';
|
|
||||||
const esprima = require('esprima');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the extension from the file name.
|
* Returns the extension from the file name.
|
||||||
* @param {dtring} fileName File name
|
* @param {dtring} fileName File name
|
||||||
@@ -16,13 +13,12 @@ export function getExtensionFromFileName(fileName) {
|
|||||||
* @param {array} files Nested file structure
|
* @param {array} files Nested file structure
|
||||||
*/
|
*/
|
||||||
export function linearizeFiles(files) {
|
export function linearizeFiles(files) {
|
||||||
function reduceToLinearFiles(files) {
|
function reduceToLinearFiles(_files) {
|
||||||
return files.reduce((list, currentFile) => {
|
return _files.reduce((list, currentFile) => {
|
||||||
if (currentFile.isFolder) {
|
if (currentFile.isFolder) {
|
||||||
return [...list, ...reduceToLinearFiles(currentFile.children)];
|
return [...list, ...reduceToLinearFiles(currentFile.children)];
|
||||||
} else {
|
|
||||||
return [...list, currentFile];
|
|
||||||
}
|
}
|
||||||
|
return [...list, currentFile];
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
return reduceToLinearFiles(files);
|
return reduceToLinearFiles(files);
|
||||||
@@ -68,7 +64,7 @@ export function getFileFromPath(files, path) {
|
|||||||
let currentFolder = files;
|
let currentFolder = files;
|
||||||
const pathPieces = path.split('/');
|
const pathPieces = path.split('/');
|
||||||
while (pathPieces.length > 1) {
|
while (pathPieces.length > 1) {
|
||||||
let folderName = pathPieces.shift();
|
const folderName = pathPieces.shift();
|
||||||
currentFolder = getChildFileFromName(currentFolder, folderName).file
|
currentFolder = getChildFileFromName(currentFolder, folderName).file
|
||||||
.children;
|
.children;
|
||||||
}
|
}
|
||||||
@@ -86,7 +82,7 @@ export function removeFileAtPath(files, path) {
|
|||||||
let currentFolder = files;
|
let currentFolder = files;
|
||||||
const pathPieces = path.split('/');
|
const pathPieces = path.split('/');
|
||||||
while (pathPieces.length > 1) {
|
while (pathPieces.length > 1) {
|
||||||
let folderName = pathPieces.shift();
|
const folderName = pathPieces.shift();
|
||||||
currentFolder = getChildFileFromName(currentFolder, folderName).file
|
currentFolder = getChildFileFromName(currentFolder, folderName).file
|
||||||
.children;
|
.children;
|
||||||
}
|
}
|
||||||
@@ -123,7 +119,7 @@ export function getParentPath(path) {
|
|||||||
*/
|
*/
|
||||||
export function importGithubRepo(repoUrl) {
|
export function importGithubRepo(repoUrl) {
|
||||||
let repoSlug, match;
|
let repoSlug, match;
|
||||||
if ((match = repoUrl.match(/github\.com\/([^\/]*\/[^\/]*)/))) {
|
if ((match = repoUrl.match(/github\.com\/([^/]*\/[^/]*)/))) {
|
||||||
repoSlug = match[1];
|
repoSlug = match[1];
|
||||||
} else {
|
} else {
|
||||||
repoSlug = 'chinchang/github';
|
repoSlug = 'chinchang/github';
|
||||||
@@ -141,7 +137,7 @@ export function importGithubRepo(repoUrl) {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response) {
|
if (!response) {
|
||||||
return;
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
response.map(file => {
|
response.map(file => {
|
||||||
@@ -161,6 +157,7 @@ export function importGithubRepo(repoUrl) {
|
|||||||
currentDir.push(newEntry);
|
currentDir.push(newEntry);
|
||||||
return fetchDir(`${file.path}`, newEntry.children);
|
return fetchDir(`${file.path}`, newEntry.children);
|
||||||
}
|
}
|
||||||
|
return Promise.resolve();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -2,11 +2,12 @@ self.addEventListener('fetch', function(event) {
|
|||||||
// console.log("fetch event", event.request.url);
|
// console.log("fetch event", event.request.url);
|
||||||
if (event.request.url.indexOf('/user/') !== -1) {
|
if (event.request.url.indexOf('/user/') !== -1) {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.match(event.request).then(function(response) {
|
caches.match(event.request).then(response => {
|
||||||
// console.log("responding with ", response);
|
// console.log("responding with ", response);
|
||||||
if (response !== undefined) {
|
if (response !== undefined) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
return '';
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -21,20 +22,23 @@ function getContentType(url) {
|
|||||||
if (url.match(/\.js$/)) {
|
if (url.match(/\.js$/)) {
|
||||||
return 'application/javascript; charset=UTF-8';
|
return 'application/javascript; charset=UTF-8';
|
||||||
}
|
}
|
||||||
|
return 'text/html; charset=UTF-8';
|
||||||
}
|
}
|
||||||
self.addEventListener('message', function(e) {
|
self.addEventListener('message', function(e) {
|
||||||
// console.log("message aya sw main", e.data);
|
// console.log("message aya sw main", e.data);
|
||||||
caches.open('v1').then(function(cache) {
|
caches.open('webmaker-files').then(function(cache) {
|
||||||
for (url in e.data) {
|
for (const url in e.data) {
|
||||||
// console.log('Received data', url, e.data[url])
|
if (Object.prototype.hasOwnProperty.call(e.data, url)) {
|
||||||
cache.put(
|
// console.log('Received data', url, e.data[url])
|
||||||
url,
|
cache.put(
|
||||||
new Response(e.data[url], {
|
url,
|
||||||
headers: {
|
new Response(e.data[url], {
|
||||||
'Content-Type': getContentType(url)
|
headers: {
|
||||||
}
|
'Content-Type': getContentType(url)
|
||||||
})
|
}
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user