From 60776dcae6e2fcd83034524dc5f38194ff17b2b1 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 19 Nov 2018 14:06:24 +0800 Subject: [PATCH] add strip-json-comments --- generator.js | 7 -- node_modules/strip-json-comments/index.js | 70 +++++++++++++++++++ node_modules/strip-json-comments/package.json | 42 +++++++++++ package.json | 1 + yarn.lock | 4 ++ 5 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 node_modules/strip-json-comments/index.js create mode 100644 node_modules/strip-json-comments/package.json diff --git a/generator.js b/generator.js index 1f07312..981d9cf 100644 --- a/generator.js +++ b/generator.js @@ -51,13 +51,6 @@ module.exports = (api, options, rootOptions) => { autoprefixer: {}, '@dcloudio/vue-cli-plugin-uni/packages/postcss': {} } - }, - vue: { - baseUrl: '/', - assetsDir: 'static', - css: { - extract: false - } } }) diff --git a/node_modules/strip-json-comments/index.js b/node_modules/strip-json-comments/index.js new file mode 100644 index 0000000..4e6576e --- /dev/null +++ b/node_modules/strip-json-comments/index.js @@ -0,0 +1,70 @@ +'use strict'; +var singleComment = 1; +var multiComment = 2; + +function stripWithoutWhitespace() { + return ''; +} + +function stripWithWhitespace(str, start, end) { + return str.slice(start, end).replace(/\S/g, ' '); +} + +module.exports = function (str, opts) { + opts = opts || {}; + + var currentChar; + var nextChar; + var insideString = false; + var insideComment = false; + var offset = 0; + var ret = ''; + var strip = opts.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace; + + for (var i = 0; i < str.length; i++) { + currentChar = str[i]; + nextChar = str[i + 1]; + + if (!insideComment && currentChar === '"') { + var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\'; + if (!escaped) { + insideString = !insideString; + } + } + + if (insideString) { + continue; + } + + if (!insideComment && currentChar + nextChar === '//') { + ret += str.slice(offset, i); + offset = i; + insideComment = singleComment; + i++; + } else if (insideComment === singleComment && currentChar + nextChar === '\r\n') { + i++; + insideComment = false; + ret += strip(str, offset, i); + offset = i; + continue; + } else if (insideComment === singleComment && currentChar === '\n') { + insideComment = false; + ret += strip(str, offset, i); + offset = i; + } else if (!insideComment && currentChar + nextChar === '/*') { + ret += str.slice(offset, i); + offset = i; + insideComment = multiComment; + i++; + continue; + } else if (insideComment === multiComment && currentChar + nextChar === '*/') { + i++; + insideComment = false; + ret += strip(str, offset, i + 1); + offset = i + 1; + continue; + } + } + + return ret + (insideComment ? strip(str.substr(offset)) : str.substr(offset)); +}; diff --git a/node_modules/strip-json-comments/package.json b/node_modules/strip-json-comments/package.json new file mode 100644 index 0000000..288ecc7 --- /dev/null +++ b/node_modules/strip-json-comments/package.json @@ -0,0 +1,42 @@ +{ + "name": "strip-json-comments", + "version": "2.0.1", + "description": "Strip comments from JSON. Lets you use comments in your JSON files!", + "license": "MIT", + "repository": "sindresorhus/strip-json-comments", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "keywords": [ + "json", + "strip", + "remove", + "delete", + "trim", + "comments", + "multiline", + "parse", + "config", + "configuration", + "conf", + "settings", + "util", + "env", + "environment" + ], + "devDependencies": { + "ava": "*", + "xo": "*" + } +} diff --git a/package.json b/package.json index 45dde9c..aff7450 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "isbinaryfile": "^3.0.3", "ora": "^3.0.0", "rimraf": "^2.6.2", + "strip-json-comments": "^2.0.1", "user-home": "^2.0.0" } } diff --git a/yarn.lock b/yarn.lock index b4f3c03..67e8fcd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -554,6 +554,10 @@ strip-dirs@^2.0.0: dependencies: is-natural-number "^4.0.1" +strip-json-comments@^2.0.1: + version "2.0.1" + resolved "http://registry.npm.taobao.org/strip-json-comments/download/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + strip-outer@^1.0.0: version "1.0.1" resolved "http://registry.npm.taobao.org/strip-outer/download/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"