Przeglądaj źródła

refactor(background): extract util functions from index

Gerald 8 lat temu
rodzic
commit
12e792879b

+ 1 - 0
package.json

@@ -19,6 +19,7 @@
     "babel-core": "^6.24.1",
     "babel-eslint": "^7.2.2",
     "babel-loader": "^7.0.0",
+    "babel-plugin-transform-export-extensions": "^6.22.0",
     "babel-plugin-transform-runtime": "^6.23.0",
     "babel-preset-es2015": "^6.24.1",
     "css-loader": "^0.28.0",

+ 19 - 18
src/.babelrc

@@ -4,24 +4,25 @@
       "polyfill": false,
       // "helpers": false,
     }],
-    "babel-plugin-transform-es2015-template-literals",
-    "babel-plugin-transform-es2015-literals",
-    "babel-plugin-transform-es2015-function-name",
-    "babel-plugin-transform-es2015-arrow-functions",
-    "babel-plugin-transform-es2015-block-scoped-functions",
-    "babel-plugin-transform-es2015-classes",
-    "babel-plugin-transform-es2015-object-super",
-    "babel-plugin-transform-es2015-shorthand-properties",
-    "babel-plugin-transform-es2015-duplicate-keys",
-    "babel-plugin-transform-es2015-computed-properties",
-    "babel-plugin-transform-es2015-for-of",
-    "babel-plugin-transform-es2015-sticky-regex",
-    "babel-plugin-transform-es2015-unicode-regex",
-    "babel-plugin-check-es2015-constants",
-    "babel-plugin-transform-es2015-spread",
-    "babel-plugin-transform-es2015-parameters",
-    "babel-plugin-transform-es2015-destructuring",
-    "babel-plugin-transform-es2015-block-scoping",
+    "transform-es2015-template-literals",
+    "transform-es2015-literals",
+    "transform-es2015-function-name",
+    "transform-es2015-arrow-functions",
+    "transform-es2015-block-scoped-functions",
+    "transform-es2015-classes",
+    "transform-es2015-object-super",
+    "transform-es2015-shorthand-properties",
+    "transform-es2015-duplicate-keys",
+    "transform-es2015-computed-properties",
+    "transform-es2015-for-of",
+    "transform-es2015-sticky-regex",
+    "transform-es2015-unicode-regex",
+    "check-es2015-constants",
+    "transform-es2015-spread",
+    "transform-es2015-parameters",
+    "transform-es2015-destructuring",
+    "transform-es2015-block-scoping",
+    "transform-export-extensions",
   ],
   "comments": false
 }

+ 7 - 8
src/background/app.js

@@ -1,13 +1,12 @@
 import { i18n, defaultImage } from 'src/common';
 import * as sync from './sync';
-import { notify } from './utils';
-import { getRequestId, httpRequest, abortRequest, confirmInstall } from './utils/requests';
-import cache from './utils/cache';
-import { newScript, parseMeta } from './utils/script';
-import { setClipboard } from './utils/clipboard';
-import { getOption, setOption, hookOptions, getAllOptions } from './utils/options';
-import * as vmdb from './utils/db';
-import checkUpdate from './utils/update';
+import {
+  notify, cache, vmdb,
+  getRequestId, httpRequest, abortRequest, confirmInstall,
+  newScript, parseMeta,
+  setClipboard, checkUpdate,
+  getOption, setOption, hookOptions, getAllOptions,
+} from './utils';
 
 const VM_VER = browser.runtime.getManifest().version;
 

+ 6 - 3
src/background/sync/base.js

@@ -1,7 +1,10 @@
 import { debounce, normalizeKeys, request, noop } from 'src/common';
-import getEventEmitter from '../utils/events';
-import { getOption, setOption, hookOptions } from '../utils/options';
-import { getScriptsByIndex, parseScript, removeScript, checkPosition } from '../utils/db';
+import {
+  getEventEmitter, vmdb,
+  getOption, setOption, hookOptions,
+} from '../utils';
+
+const { getScriptsByIndex, parseScript, removeScript, checkPosition } = vmdb;
 
 const serviceNames = [];
 const services = {};

+ 1 - 1
src/background/sync/dropbox.js

@@ -1,4 +1,4 @@
-import { loadQuery, dumpQuery } from '../utils/search';
+import { loadQuery, dumpQuery } from '../utils';
 import { getURI, BaseService, isScriptFile, register } from './base';
 
 const config = {

+ 1 - 1
src/background/sync/onedrive.js

@@ -1,6 +1,6 @@
 // Reference: https://dev.onedrive.com/README.htm
 import { object, noop } from 'src/common';
-import { dumpQuery } from '../utils/search';
+import { dumpQuery } from '../utils';
 import { BaseService, isScriptFile, register, getURI } from './base';
 
 const config = Object.assign({

+ 1 - 2
src/background/utils/clipboard.js

@@ -8,8 +8,7 @@ function oncopy(e) {
 }
 document.addEventListener('copy', oncopy, false);
 
-/* eslint-disable import/prefer-default-export */
-export function setClipboard(data) {
+export default function setClipboard(data) {
   clipboardData.type = data.type;
   clipboardData.data = data.data;
   textarea.focus();

+ 10 - 0
src/background/utils/index.js

@@ -1,5 +1,15 @@
 import { i18n, defaultImage } from 'src/common';
 
+export cache from './cache';
+export setClipboard from './clipboard';
+export checkUpdate from './update';
+export getEventEmitter from './events';
+export * from './script';
+export * from './options';
+export * from './requests';
+export * as vmdb from './db';
+export * from './search';
+
 export function notify(options) {
   browser.notifications.create(options.id || 'ViolentMonkey', {
     type: 'basic',