mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) import -> load.js
This commit is contained in:
parent
4b528280ba
commit
3e310724ff
24 changed files with 306 additions and 325 deletions
|
|
@ -29,11 +29,13 @@ const plugins = [
|
|||
extractMain,
|
||||
];
|
||||
|
||||
const cssLoader = isDev ? 'css-loader' : 'css-loader?minimize';
|
||||
|
||||
const rules = [{
|
||||
test: /\.css$/,
|
||||
exclude: /css\/(nojs|view|config|columns.*)\.css/,
|
||||
use: extractMain.extract([
|
||||
'css-loader?minimize',
|
||||
cssLoader,
|
||||
]),
|
||||
},
|
||||
...cssPlugins.map(extract), {
|
||||
|
|
@ -60,12 +62,11 @@ function getCSSList(dir) {
|
|||
|
||||
function extract(extractPlugin) {
|
||||
const {filename} = extractPlugin;
|
||||
const loader = isDev ? 'css-loader' : 'css-loader?minimize';
|
||||
|
||||
return {
|
||||
test: RegExp(`css/${filename}`),
|
||||
use: extractPlugin.extract([
|
||||
loader
|
||||
cssLoader
|
||||
])
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const rules = clean([
|
|||
loader: 'babel-loader',
|
||||
},
|
||||
isDev && {
|
||||
test: /sw.js$/,
|
||||
test: /sw\.js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
options: babelDev
|
||||
|
|
@ -58,7 +58,7 @@ const plugins = [
|
|||
|
||||
const splitChunks = {
|
||||
name: 'cloudcmd.common',
|
||||
chunks: 'async',
|
||||
chunks: 'all',
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ const args = require('minimist')(argv.slice(2), {
|
|||
default: {
|
||||
server : true,
|
||||
name : choose(env('name'), config('name')),
|
||||
auth : choose(env('auth'), config('auth')),
|
||||
auth : choose(env.bool('auth'), config('auth')),
|
||||
port : config('port'),
|
||||
online : config('online'),
|
||||
open : config('open'),
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ function CloudCmdProto(DOM) {
|
|||
initModules,
|
||||
baseInit,
|
||||
loadPlugins,
|
||||
loadStyle,
|
||||
exec.with(CloudCmd.route, location.hash),
|
||||
], noop);
|
||||
|
||||
|
|
@ -164,6 +165,13 @@ function CloudCmdProto(DOM) {
|
|||
exec.if(document.body.scrollIntoViewIfNeeded, func, funcBefore);
|
||||
};
|
||||
|
||||
function loadStyle(callback) {
|
||||
const prefix = CloudCmd.PREFIX;
|
||||
const name = prefix + '/dist/cloudcmd.common.css';
|
||||
|
||||
DOM.load.css(name, callback);
|
||||
}
|
||||
|
||||
function loadPlugins(callback) {
|
||||
const prefix = CloudCmd.PREFIX;
|
||||
const plugins = prefix + '/plugins.js';
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@
|
|||
/* global CloudCmd */
|
||||
|
||||
const exec = require('execon');
|
||||
const {promisify} = require('es6-promisify');
|
||||
const tryToCatch = require('try-to-catch/legacy');
|
||||
const {
|
||||
kebabToCamelCase,
|
||||
} = require('../common/util');
|
||||
|
||||
const loadJS = promisify(require('./dom/load').js);
|
||||
|
||||
/**
|
||||
* function load modules
|
||||
* @params = {name, path, func, dobefore, arg}
|
||||
|
|
@ -16,7 +19,7 @@ module.exports = function loadModule(params) {
|
|||
if (!params)
|
||||
return;
|
||||
|
||||
let path = params.path;
|
||||
const {path} = params;
|
||||
const name = params.name || path && kebabToCamelCase(path);
|
||||
const doBefore = params.dobefore;
|
||||
|
||||
|
|
@ -25,10 +28,15 @@ module.exports = function loadModule(params) {
|
|||
|
||||
CloudCmd[name] = () => {
|
||||
exec(doBefore);
|
||||
return import(`./modules/${path}` /* webpackChunkName: "cloudcmd-" */).then(async (module) => {
|
||||
const prefix = CloudCmd.PREFIX;
|
||||
const pathFull = prefix + CloudCmd.DIRCLIENT_MODULES + path + '.js';
|
||||
|
||||
return loadJS(pathFull).then(async () => {
|
||||
const newModule = async (f) => f && f();
|
||||
const module = CloudCmd[name];
|
||||
|
||||
Object.assign(newModule, module);
|
||||
|
||||
CloudCmd[name] = newModule;
|
||||
|
||||
CloudCmd.log('init', name);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ const Images = require('../dom/images');
|
|||
|
||||
const upload = currify(_upload);
|
||||
|
||||
const Name = 'Cloud';
|
||||
CloudCmd[Name] = module.exports;
|
||||
|
||||
module.exports.init = async () => {
|
||||
await loadFiles();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ const Files = require('../dom/files');
|
|||
const {getTitle} = require('../../common/cloudfunc');
|
||||
const {Dialog, setTitle} = DOM;
|
||||
|
||||
const TITLE = 'Config';
|
||||
const alert = currify(Dialog.alert, TITLE);
|
||||
const Name = 'Config';
|
||||
CloudCmd[Name] = module.exports;
|
||||
const alert = currify(Dialog.alert, Name);
|
||||
|
||||
const loadSocket = promisify(DOM.loadSocket);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,12 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
CloudCmd.Contact = ContactProto;
|
||||
CloudCmd.Contact = exports;
|
||||
|
||||
const {promisify} = require('es6-promisify');
|
||||
|
||||
const exec = require('execon');
|
||||
const Images = require('../dom/images');
|
||||
|
||||
function ContactProto(callback) {
|
||||
init(callback);
|
||||
|
||||
return exports;
|
||||
}
|
||||
const loadJS = require('../dom/load').js;
|
||||
|
||||
const Events = DOM.Events;
|
||||
const Key = CloudCmd.Key;
|
||||
|
|
@ -23,41 +19,38 @@ module.exports.hide = hide;
|
|||
|
||||
let Inited = false;
|
||||
|
||||
function init(callback) {
|
||||
module.exports.init = async () => {
|
||||
if (Inited)
|
||||
return;
|
||||
|
||||
load(() => {
|
||||
Inited = true;
|
||||
|
||||
olark.identify('6216-545-10-4223');
|
||||
olark('api.box.onExpand', show);
|
||||
olark('api.box.onShow', show);
|
||||
olark('api.box.onShrink', hide);
|
||||
|
||||
exec(callback);
|
||||
});
|
||||
|
||||
Events.addKey(onKey);
|
||||
}
|
||||
await load();
|
||||
|
||||
Inited = true;
|
||||
|
||||
olark.identify('6216-545-10-4223');
|
||||
olark('api.box.onExpand', show);
|
||||
olark('api.box.onShow', show);
|
||||
olark('api.box.onShrink', hide);
|
||||
};
|
||||
|
||||
function load(callback) {
|
||||
const load = promisify((callback) => {
|
||||
const {PREFIX} = CloudCmd;
|
||||
const path = `${PREFIX}/modules/olark/olark.min.js`;
|
||||
|
||||
Images.show.load('top');
|
||||
|
||||
DOM.load.js(path, callback);
|
||||
}
|
||||
return loadJS(path, callback);
|
||||
});
|
||||
|
||||
function show() {
|
||||
Key.unsetBind();
|
||||
Images.hide();
|
||||
|
||||
if (Inited)
|
||||
return olark('api.box.expand');
|
||||
if (!Inited)
|
||||
return;
|
||||
|
||||
init(show);
|
||||
olark('api.box.expand');
|
||||
}
|
||||
|
||||
function hide() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
/* global CloudCmd */
|
||||
|
||||
CloudCmd.EditFileVim = exports;
|
||||
|
||||
const Events = require('../dom/events');
|
||||
|
||||
const {Key} = CloudCmd;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
/* global CloudCmd, DOM*/
|
||||
|
||||
CloudCmd.EditFile = exports;
|
||||
|
||||
const Format = require('format-io/legacy');
|
||||
const exec = require('execon');
|
||||
const supermenu = require('supermenu');
|
||||
|
|
|
|||
|
|
@ -2,54 +2,47 @@
|
|||
|
||||
/* global CloudCmd */
|
||||
|
||||
const exec = require('execon');
|
||||
const Events = require('../dom/events');
|
||||
CloudCmd.EditNamesVim = exports;
|
||||
|
||||
const Events = require('../dom/events');
|
||||
const {Key} = CloudCmd;
|
||||
|
||||
CloudCmd.EditNamesVim = function EditNamesVimProto(callback) {
|
||||
const EditNamesVim = this;
|
||||
|
||||
const ConfigView = {
|
||||
bindKeys: false,
|
||||
beforeClose: () => {
|
||||
Events.rmKey(listener);
|
||||
CloudCmd.EditNames.isChanged();
|
||||
}
|
||||
};
|
||||
|
||||
function init(callback) {
|
||||
exec.series([
|
||||
CloudCmd.EditNames,
|
||||
callback || EditNamesVim.show,
|
||||
]);
|
||||
const ConfigView = {
|
||||
bindKeys: false,
|
||||
beforeClose: () => {
|
||||
Events.rmKey(listener);
|
||||
CloudCmd.EditNames.isChanged();
|
||||
}
|
||||
|
||||
this.show = () => {
|
||||
Events.addKey(listener);
|
||||
|
||||
CloudCmd.EditNames
|
||||
.show(ConfigView)
|
||||
.getEditor()
|
||||
.setKeyMap('vim');
|
||||
};
|
||||
|
||||
this.hide = () => {
|
||||
CloudCmd.Edit.hide();
|
||||
};
|
||||
|
||||
function listener(event) {
|
||||
const {
|
||||
keyCode,
|
||||
shiftKey,
|
||||
} = event;
|
||||
|
||||
if (shiftKey && keyCode === Key.ESC) {
|
||||
event.preventDefault();
|
||||
EditNamesVim.hide();
|
||||
}
|
||||
}
|
||||
|
||||
init(callback);
|
||||
};
|
||||
|
||||
module.exports.init = async () => {
|
||||
await CloudCmd.EditNames();
|
||||
};
|
||||
|
||||
module.exports.show = () => {
|
||||
Events.addKey(listener);
|
||||
|
||||
CloudCmd.EditNames
|
||||
.show(ConfigView)
|
||||
.getEditor()
|
||||
.setKeyMap('vim');
|
||||
};
|
||||
|
||||
module.exports.hide = hide;
|
||||
|
||||
function hide() {
|
||||
CloudCmd.Edit.hide();
|
||||
}
|
||||
|
||||
function listener(event) {
|
||||
const {
|
||||
keyCode,
|
||||
shiftKey,
|
||||
} = event;
|
||||
|
||||
if (shiftKey && keyCode === Key.ESC) {
|
||||
event.preventDefault();
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,227 +2,207 @@
|
|||
|
||||
/* global CloudCmd, DOM */
|
||||
|
||||
CloudCmd.EditNames = exports;
|
||||
|
||||
const currify = require('currify/legacy');
|
||||
const store = require('fullstore/legacy');
|
||||
const squad = require('squad/legacy');
|
||||
const wraptile = require('wraptile/legacy');
|
||||
const exec = require('execon');
|
||||
const supermenu = require('supermenu');
|
||||
|
||||
const reject = Promise.reject.bind(Promise);
|
||||
|
||||
const call = currify((fn, callback) => {
|
||||
fn();
|
||||
callback();
|
||||
});
|
||||
const Info = DOM.CurrentInfo;
|
||||
const Dialog = DOM.Dialog;
|
||||
|
||||
CloudCmd.EditNames = function EditNamesProto(callback) {
|
||||
const Info = DOM.CurrentInfo;
|
||||
const Dialog = DOM.Dialog;
|
||||
const TITLE = 'Edit Names';
|
||||
const alert = currify(Dialog.alert, TITLE);
|
||||
const refresh = currify(_refresh);
|
||||
const rename = currify(_rename);
|
||||
|
||||
let Menu;
|
||||
|
||||
const EditNames = exec.bind();
|
||||
const ConfigView = {
|
||||
beforeClose: () => {
|
||||
exec.ifExist(Menu, 'hide');
|
||||
DOM.Events.remove('keydown', keyListener);
|
||||
isChanged();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.init = async () => {
|
||||
await CloudCmd.Edit();
|
||||
|
||||
const TITLE = 'Edit Names';
|
||||
const alert = currify(Dialog.alert, TITLE);
|
||||
const refresh = currify(_refresh);
|
||||
const rename = currify(_rename);
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
setListeners(editor);
|
||||
};
|
||||
|
||||
module.exports.show = (options) => {
|
||||
const names = getActiveNames().join('\n');
|
||||
const config = {
|
||||
...ConfigView,
|
||||
...options,
|
||||
};
|
||||
|
||||
let Menu;
|
||||
if (Info.name === '..' && names.length === 1)
|
||||
return Dialog.alert.noFiles(TITLE);
|
||||
|
||||
const EditNames = exec.bind();
|
||||
const ConfigView = {
|
||||
beforeClose: () => {
|
||||
exec.ifExist(Menu, 'hide');
|
||||
DOM.Events.remove('keydown', keyListener);
|
||||
EditNames.isChanged();
|
||||
DOM.Events.addKey(keyListener);
|
||||
|
||||
CloudCmd.Edit
|
||||
.getEditor()
|
||||
.setValueFirst('edit-names', names)
|
||||
.setMode()
|
||||
.setOption('keyMap', 'default')
|
||||
.disableKey();
|
||||
|
||||
CloudCmd.Edit.show(config);
|
||||
|
||||
return CloudCmd.Edit;
|
||||
};
|
||||
|
||||
function keyListener(event) {
|
||||
const ctrl = event.ctrlKey;
|
||||
const meta = event.metaKey;
|
||||
const ctrlMeta = ctrl || meta;
|
||||
const Key = CloudCmd.Key;
|
||||
|
||||
if (!ctrlMeta || event.keyCode !== Key.S)
|
||||
return;
|
||||
|
||||
EditNames.hide();
|
||||
}
|
||||
|
||||
function getActiveNames() {
|
||||
return DOM.getFilenames(DOM.getActiveFiles());
|
||||
}
|
||||
|
||||
module.exports.hide = () => {
|
||||
CloudCmd.Edit.hide();
|
||||
};
|
||||
|
||||
function setListeners() {
|
||||
const element = CloudCmd.Edit.getElement();
|
||||
|
||||
DOM.Events.addOnce('contextmenu', element, setMenu);
|
||||
}
|
||||
|
||||
function applyNames() {
|
||||
const dir = Info.dirPath;
|
||||
const from = getActiveNames();
|
||||
const nameIndex = from.indexOf(Info.name);
|
||||
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const to = editor
|
||||
.getValue()
|
||||
.split('\n');
|
||||
|
||||
const root = CloudCmd.config('root');
|
||||
|
||||
Promise.resolve(root)
|
||||
.then(rename(dir, from, to))
|
||||
.then(refresh(to, nameIndex))
|
||||
.catch(alert);
|
||||
}
|
||||
|
||||
function _refresh(to, nameIndex, res) {
|
||||
if (res.status === 404)
|
||||
return res.text().then(reject);
|
||||
|
||||
const currentName = to[nameIndex];
|
||||
|
||||
CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
}
|
||||
|
||||
function getDir(root, dir) {
|
||||
if (root === '/')
|
||||
return dir;
|
||||
|
||||
return root + dir;
|
||||
}
|
||||
|
||||
function _rename(path, from, to, root) {
|
||||
const dir = getDir(root, path);
|
||||
|
||||
return fetch(CloudCmd.PREFIX + '/rename', {
|
||||
method: 'put',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
from,
|
||||
to,
|
||||
dir,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function setMenu(event) {
|
||||
const position = {
|
||||
x: event.clientX,
|
||||
y: event.clientY
|
||||
};
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (Menu)
|
||||
return;
|
||||
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const options = {
|
||||
beforeShow: (params) => {
|
||||
params.x -= 18;
|
||||
params.y -= 27;
|
||||
},
|
||||
|
||||
afterClick: () => {
|
||||
editor.focus();
|
||||
}
|
||||
};
|
||||
|
||||
function init(callback) {
|
||||
const editor = store();
|
||||
|
||||
const getMainEditor = () => CloudCmd.Edit.getEditor();
|
||||
const getEditor = squad(editor, getMainEditor);
|
||||
const listeners = squad(setListeners, editor);
|
||||
|
||||
const show = callback ? exec : EditNames.show;
|
||||
|
||||
exec.series([
|
||||
CloudCmd.Edit,
|
||||
call(getEditor),
|
||||
call(listeners),
|
||||
show,
|
||||
], callback);
|
||||
}
|
||||
|
||||
EditNames.show = (options) => {
|
||||
const names = getActiveNames().join('\n');
|
||||
const config = {
|
||||
...ConfigView,
|
||||
...options,
|
||||
};
|
||||
|
||||
if (Info.name === '..' && names.length === 1)
|
||||
return Dialog.alert.noFiles(TITLE);
|
||||
|
||||
DOM.Events.addKey(keyListener);
|
||||
|
||||
CloudCmd.Edit
|
||||
.getEditor()
|
||||
.setValueFirst('edit-names', names)
|
||||
.setMode()
|
||||
.setOption('keyMap', 'default')
|
||||
.disableKey();
|
||||
|
||||
CloudCmd.Edit.show(config);
|
||||
|
||||
return CloudCmd.Edit;
|
||||
const menuData = {
|
||||
'Save Ctrl+S' : () => {
|
||||
editor.save();
|
||||
EditNames.hide();
|
||||
},
|
||||
'Go To Line Ctrl+G' : () => {
|
||||
editor.goToLine();
|
||||
},
|
||||
'Cut Ctrl+X' : () => {
|
||||
editor.cutToClipboard();
|
||||
},
|
||||
'Copy Ctrl+C' : () => {
|
||||
editor.copyToClipboard();
|
||||
},
|
||||
'Paste Ctrl+V' : () => {
|
||||
editor.pasteFromClipboard();
|
||||
},
|
||||
'Delete Del' : () => {
|
||||
editor.remove('right');
|
||||
},
|
||||
'Select All Ctrl+A' : () => {
|
||||
editor.selectAll();
|
||||
},
|
||||
'Close Esc' : () => {
|
||||
EditNames.hide();
|
||||
}
|
||||
};
|
||||
|
||||
function keyListener(event) {
|
||||
const ctrl = event.ctrlKey;
|
||||
const meta = event.metaKey;
|
||||
const ctrlMeta = ctrl || meta;
|
||||
const Key = CloudCmd.Key;
|
||||
|
||||
if (!ctrlMeta || event.keyCode !== Key.S)
|
||||
return;
|
||||
|
||||
EditNames.hide();
|
||||
}
|
||||
const element = CloudCmd.Edit.getElement();
|
||||
|
||||
function getActiveNames() {
|
||||
return DOM.getFilenames(DOM.getActiveFiles());
|
||||
}
|
||||
|
||||
EditNames.hide = () => {
|
||||
CloudCmd.Edit.hide();
|
||||
};
|
||||
|
||||
function setListeners() {
|
||||
const element = CloudCmd.Edit.getElement();
|
||||
|
||||
DOM.Events.addOnce('contextmenu', element, setMenu);
|
||||
}
|
||||
|
||||
function applyNames() {
|
||||
const dir = Info.dirPath;
|
||||
const from = getActiveNames();
|
||||
const nameIndex = from.indexOf(Info.name);
|
||||
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const to = editor
|
||||
.getValue()
|
||||
.split('\n');
|
||||
|
||||
const root = CloudCmd.config('root');
|
||||
|
||||
Promise.resolve(root)
|
||||
.then(rename(dir, from, to))
|
||||
.then(refresh(to, nameIndex))
|
||||
.catch(alert);
|
||||
}
|
||||
|
||||
function _refresh(to, nameIndex, res) {
|
||||
if (res.status === 404)
|
||||
return res.text().then(reject);
|
||||
|
||||
const currentName = to[nameIndex];
|
||||
|
||||
CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
}
|
||||
|
||||
function getDir(root, dir) {
|
||||
if (root === '/')
|
||||
return dir;
|
||||
|
||||
return root + dir;
|
||||
}
|
||||
|
||||
function _rename(path, from, to, root) {
|
||||
const dir = getDir(root, path);
|
||||
|
||||
return fetch(CloudCmd.PREFIX + '/rename', {
|
||||
method: 'put',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
from,
|
||||
to,
|
||||
dir,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function setMenu(event) {
|
||||
const position = {
|
||||
x: event.clientX,
|
||||
y: event.clientY
|
||||
};
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (Menu)
|
||||
return;
|
||||
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const options = {
|
||||
beforeShow: (params) => {
|
||||
params.x -= 18;
|
||||
params.y -= 27;
|
||||
},
|
||||
|
||||
afterClick: () => {
|
||||
editor.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const menuData = {
|
||||
'Save Ctrl+S' : () => {
|
||||
editor.save();
|
||||
EditNames.hide();
|
||||
},
|
||||
'Go To Line Ctrl+G' : () => {
|
||||
editor.goToLine();
|
||||
},
|
||||
'Cut Ctrl+X' : () => {
|
||||
editor.cutToClipboard();
|
||||
},
|
||||
'Copy Ctrl+C' : () => {
|
||||
editor.copyToClipboard();
|
||||
},
|
||||
'Paste Ctrl+V' : () => {
|
||||
editor.pasteFromClipboard();
|
||||
},
|
||||
'Delete Del' : () => {
|
||||
editor.remove('right');
|
||||
},
|
||||
'Select All Ctrl+A' : () => {
|
||||
editor.selectAll();
|
||||
},
|
||||
'Close Esc' : () => {
|
||||
EditNames.hide();
|
||||
}
|
||||
};
|
||||
|
||||
const element = CloudCmd.Edit.getElement();
|
||||
|
||||
Menu = supermenu(element, options, menuData);
|
||||
Menu.show(position.x, position.y);
|
||||
}
|
||||
|
||||
EditNames.isChanged = () => {
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const msg = 'Apply new names?';
|
||||
|
||||
if (!editor.isChanged())
|
||||
return;
|
||||
|
||||
Dialog.confirm(TITLE, msg, {cancel: false})
|
||||
.then(applyNames);
|
||||
};
|
||||
|
||||
setTimeout(wraptile(init, callback));
|
||||
|
||||
return EditNames;
|
||||
};
|
||||
Menu = supermenu(element, options, menuData);
|
||||
Menu.show(position.x, position.y);
|
||||
}
|
||||
|
||||
module.exports.isChanged = isChanged;
|
||||
|
||||
function isChanged() {
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const msg = 'Apply new names?';
|
||||
|
||||
if (!editor.isChanged())
|
||||
return;
|
||||
|
||||
Dialog.confirm(TITLE, msg, {cancel: false})
|
||||
.then(applyNames);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc');
|
|||
const {time, timeEnd} = require('../../common/util');
|
||||
|
||||
const Name = 'Edit';
|
||||
|
||||
CloudCmd[Name] = exports;
|
||||
|
||||
const EditorName = CloudCmd.config('editor');
|
||||
|
||||
let Loading = true;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
/* global CloudCmd */
|
||||
|
||||
CloudCmd.Help = exports;
|
||||
|
||||
const Images = require('../dom/images');
|
||||
|
||||
module.exports.init = () => {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
/* global DOM */
|
||||
/* global Console */
|
||||
|
||||
CloudCmd.Konsole = exports;
|
||||
|
||||
const exec = require('execon');
|
||||
const {promisify} = require('es6-promisify');
|
||||
const currify = require('currify/legacy');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
/*global CloudCmd */
|
||||
/* global CloudCmd */
|
||||
|
||||
CloudCmd.Markdown = exports;
|
||||
|
||||
const Images = require('../dom/images');
|
||||
const load = require('../dom/load');
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ let MenuContextFile;
|
|||
|
||||
module.exports.ENABLED = false;
|
||||
|
||||
CloudCmd.Menu = exports;
|
||||
|
||||
module.exports.init = () => {
|
||||
const {isAuth, menuDataFile} = getFileMenuData();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
|
||||
const currify = require('currify/legacy');
|
||||
const wraptile = require('wraptile/legacy');
|
||||
const {promisify} = require('es6-promisify');
|
||||
|
|
@ -23,6 +22,8 @@ const getNextCurrentName = require('./get-next-current-name');
|
|||
const removeQuery = (a) => a.replace(/\?.*/, '');
|
||||
|
||||
const Name = 'Operation';
|
||||
CloudCmd[Name] = exports;
|
||||
|
||||
const {
|
||||
TITLE,
|
||||
config,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ const TITLE = 'Terminal';
|
|||
const {Dialog} = DOM;
|
||||
const {Key} = CloudCmd;
|
||||
|
||||
CloudCmd.Terminal = exports;
|
||||
|
||||
let Element;
|
||||
let Loaded;
|
||||
let Terminal;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
CloudCmd.Upload = exports;
|
||||
|
||||
const load = require('../dom/load');
|
||||
const Files = require('../dom/files');
|
||||
const Images = require('../dom/images');
|
||||
|
|
|
|||
|
|
@ -24,13 +24,14 @@ const lifo = currify((fn, el, cb, name) => fn(name, el, cb));
|
|||
const addEvent = lifo(Events.add);
|
||||
const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i');
|
||||
|
||||
//module.exports = exec.bind();
|
||||
module.exports.show = show;
|
||||
module.exports.hide = hide;
|
||||
|
||||
let Loading = false;
|
||||
|
||||
const Name = 'View';
|
||||
CloudCmd[Name] = module.exports;
|
||||
|
||||
const Info = DOM.CurrentInfo;
|
||||
const Key = CloudCmd.Key;
|
||||
const basename = (a) => a.split('/').pop();
|
||||
|
|
|
|||
|
|
@ -99,12 +99,12 @@ test('sw: register: registerSW', async (t) => {
|
|||
registerSW,
|
||||
} = mock.reRequire('./register');
|
||||
|
||||
await registerSW();
|
||||
await registerSW('hello');
|
||||
|
||||
global.location = location;
|
||||
global.navigator = navigator;
|
||||
|
||||
t.ok(register.calledWith(), 'should call register');
|
||||
t.ok(register.calledWith('/hello/sw.js'), 'should call register');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const preval = require('preval.macro');
|
||||
const codegen = require('codegen.macro');
|
||||
const tryToCatch = require('try-to-catch/legacy');
|
||||
const currify = require('currify/legacy');
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const tryWrap = (a) => (...b) => tryToCatch(a, ...b);
|
||||
|
||||
const wait = currify((f, e) => e.waitUntil(f()));
|
||||
const respondWith = currify((f, e) => e.respondWith(f(e)));
|
||||
const getPathName = (url) => new URL(url).pathname;
|
||||
|
||||
const date = preval`module.exports = Date()`;
|
||||
const date = codegen`module.exports = '"' + Date() + '"'`;
|
||||
const NAME = `cloudcmd: ${date}`;
|
||||
|
||||
const isGet = (a) => a.method === 'GET';
|
||||
|
|
@ -69,7 +67,7 @@ async function onFetch(event) {
|
|||
if (!isDev && response)
|
||||
return response;
|
||||
|
||||
const [e, resp] = await tryToRequest(request);
|
||||
const [e, resp] = await tryToCatch(fetch, request.clone());
|
||||
|
||||
if (e)
|
||||
return console.error(e, response, pathname);
|
||||
|
|
@ -96,28 +94,3 @@ async function addToCache(request, response) {
|
|||
return cache.put(request, response);
|
||||
}
|
||||
|
||||
async function tryToRequest(req) {
|
||||
const {url} = req;
|
||||
const path = url.replace(`${location.origin}/`, '');
|
||||
const get = tryWrap(fetch);
|
||||
const prefix = getPrefix();
|
||||
|
||||
if (prefix && /^dist/.test(path))
|
||||
return await get(createRequest(`${prefix}${path}`));
|
||||
|
||||
return await get(req.clone());
|
||||
}
|
||||
|
||||
function getPrefix() {
|
||||
const {
|
||||
href,
|
||||
origin,
|
||||
} = location;
|
||||
|
||||
const prefix = href
|
||||
.replace(origin, '')
|
||||
.replace('sw.js', '');
|
||||
|
||||
return prefix;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@
|
|||
"babel-plugin-macros": "^2.2.1",
|
||||
"clean-css-loader": "^1.0.1",
|
||||
"clear-module": "^2.1.0",
|
||||
"codegen.macro": "^2.0.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"css-loader": "^0.28.4",
|
||||
"domtokenlist-shim": "^1.2.0",
|
||||
|
|
@ -193,7 +194,6 @@
|
|||
"nyc": "^12.0.1",
|
||||
"philip": "^2.0.0",
|
||||
"place": "^1.1.4",
|
||||
"preval.macro": "^1.0.2",
|
||||
"readjson": "^1.1.3",
|
||||
"redrun": "^6.0.0",
|
||||
"request": "^2.76.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue