فهرست منبع

fix: transform manifest.json to yaml

Gerald 8 سال پیش
والد
کامیت
7182608291
4فایلهای تغییر یافته به همراه49 افزوده شده و 59 حذف شده
  1. 8 4
      gulpfile.js
  2. 1 2
      scripts/string.js
  3. 0 53
      src/manifest.json
  4. 40 0
      src/manifest.yml

+ 8 - 4
gulpfile.js

@@ -4,15 +4,16 @@ const gutil = require('gulp-util');
 const gulpFilter = require('gulp-filter');
 const uglify = require('gulp-uglify');
 const svgSprite = require('gulp-svg-sprite');
+const yaml = require('js-yaml');
 const webpack = require('webpack');
 const webpackConfig = require('./scripts/webpack.conf');
 const i18n = require('./scripts/i18n');
-const json = require('./scripts/json');
+const string = require('./scripts/string');
 const { IS_DEV } = require('./scripts/utils');
 const pkg = require('./package.json');
 
 const paths = {
-  manifest: 'src/manifest.json',
+  manifest: 'src/manifest.yml',
   copy: [
     'src/public/images/**',
     'src/public/lib/**',
@@ -69,9 +70,12 @@ gulp.task('js-prd', cb => {
 
 gulp.task('manifest', () => (
   gulp.src(paths.manifest, { base: 'src' })
-  .pipe(json(data => {
+  .pipe(string((input, file) => {
+    const data = yaml.safeLoad(input);
+    // Strip alphabetic suffix
     data.version = pkg.version.replace(/-[^.]*/, '');
-    return data;
+    file.path = file.path.replace(/\.yml$/, '.json');
+    return JSON.stringify(data);
   }))
   .pipe(gulp.dest('dist'))
 ));

+ 1 - 2
scripts/json.js → scripts/string.js

@@ -5,8 +5,7 @@ module.exports = function (handle) {
   return through.obj(function (file, enc, cb) {
     if (file.isNull()) return cb();
     if (file.isStream()) return this.emit('error', new gutil.PluginError('VM-json', 'Stream is not supported.'));
-    handle = handle || (i => i);
-    file.contents = new Buffer(JSON.stringify(handle(JSON.parse(String(file.contents)))));
+    if (handle) file.contents = new Buffer(handle(String(file.contents), file));
     cb(null, file);
   });
 };

+ 0 - 53
src/manifest.json

@@ -1,53 +0,0 @@
-{
-  "name": "__MSG_extName__",
-  "version": "__VERSION__",
-  "manifest_version": 2,
-  "description": "__MSG_extDescription__",
-  "author": "Gerald",
-  "homepage_url": "https://violentmonkey.github.io/",
-  "icons": {
-    "16": "public/images/icon16.png",
-    "48": "public/images/icon48.png",
-    "128": "public/images/icon128.png"
-  },
-  "default_locale": "en",
-  "browser_action": {
-    "default_icon": {
-      "19": "public/images/icon19.png",
-      "38": "public/images/icon38.png"
-    },
-    "default_title": "__MSG_extName__",
-    "default_popup": "popup/index.html"
-  },
-  "background": {
-    "page": "background/index.html"
-  },
-  "options_page": "options/index.html",
-  "options_ui": {
-    "page": "options/index.html",
-    "open_in_tab": true
-  },
-  "content_scripts": [
-    {
-      "js": [
-        "browser.js",
-        "injected-web.js",
-        "injected.js"
-      ],
-      "matches": [
-        "<all_urls>"
-      ],
-      "run_at": "document_start",
-      "all_frames": true
-    }
-  ],
-  "permissions": [
-    "tabs",
-    "<all_urls>",
-    "webRequest",
-    "webRequestBlocking",
-    "notifications",
-    "storage",
-    "unlimitedStorage"
-  ]
-}

+ 40 - 0
src/manifest.yml

@@ -0,0 +1,40 @@
+name: __MSG_extName__
+version: __VERSION__
+manifest_version: 2
+description: __MSG_extDescription__
+author: Gerald
+homepage_url: 'https://violentmonkey.github.io/'
+icons:
+  '16': public/images/icon16.png
+  '48': public/images/icon48.png
+  '128': public/images/icon128.png
+default_locale: en
+browser_action:
+  default_icon:
+    '19': public/images/icon19.png
+    '38': public/images/icon38.png
+  default_title: __MSG_extName__
+  default_popup: popup/index.html
+background:
+  page: background/index.html
+options_page: options/index.html
+options_ui:
+  page: options/index.html
+  open_in_tab: true
+content_scripts:
+  - js:
+      - browser.js
+      - injected-web.js
+      - injected.js
+    matches:
+      - <all_urls>
+    run_at: document_start
+    all_frames: true
+permissions:
+  - tabs
+  - <all_urls>
+  - webRequest
+  - webRequestBlocking
+  - notifications
+  - storage
+  - unlimitedStorage