瀏覽代碼

Adopt monaco-plugin-helpers

Alex Dima 7 年之前
父節點
當前提交
d75e5fdb8f
共有 6 個文件被更改,包括 21 次插入121 次删除
  1. 12 3
      package-lock.json
  2. 6 5
      package.json
  3. 3 3
      scripts/bundle.js
  4. 0 30
      scripts/copy.js
  5. 0 52
      scripts/git.js
  6. 0 28
      scripts/rmdir.js

+ 12 - 3
package-lock.json

@@ -132,6 +132,15 @@
       "integrity": "sha512-zbi+FI4Bm1B48AvAVjir0XUJlH85ZyFHaBcXvZjfy+mui8VaE7Run2ai/l9cvb6oqzTKQwg/UpYDu0BWyB8K5w==",
       "dev": true
     },
+    "monaco-plugin-helpers": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/monaco-plugin-helpers/-/monaco-plugin-helpers-1.0.2.tgz",
+      "integrity": "sha512-7kUx8dtd5qVNVgUARBRhnM8oftPglYwlINfigC4yGUiuzqtIN22u1tly8umiOCIPR0eFiBLjt6aN23oZh2QJgg==",
+      "dev": true,
+      "requires": {
+        "typescript": "2.7.2"
+      }
+    },
     "ms": {
       "version": "0.7.1",
       "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz",
@@ -175,9 +184,9 @@
       "dev": true
     },
     "uglify-js": {
-      "version": "3.3.13",
-      "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.13.tgz",
-      "integrity": "sha512-7rdn/bDOG1ElSTPdh7AI5TCjLv63ZD4k8BBadN3ssIkhlaQL2c0yRxmXCyOYhZK0wZTgGgUSnYQ4CGu+Jos5cA==",
+      "version": "3.3.14",
+      "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.14.tgz",
+      "integrity": "sha512-OY8VPQU25q09gQRbC+Ekk3xgEVBmYFEfVcgS47ksjTiNht2LmLlUkWutyi38ZsDSToJHwbe76kDGwmD226Z2Fg==",
       "dev": true,
       "requires": {
         "commander": "2.14.1",

+ 6 - 5
package.json

@@ -4,11 +4,11 @@
   "description": "TypeScript and JavaScript language support for Monaco Editor",
   "scripts": {
     "test": "mocha",
-    "compile-amd": "node ./scripts/copy ./src/lib/typescriptServices-amd.js ./release/dev/lib/typescriptServices.js && tsc -p ./src/tsconfig.json",
-    "compile-esm": "node ./scripts/copy ./src/lib/typescriptServices.js ./release/esm/lib/typescriptServices.js && tsc -p ./src/tsconfig.esm.json",
-    "compile": "node ./scripts/rmdir ./release && npm run compile-amd && npm run compile-esm",
+    "compile-amd": "mcopy ./src/lib/typescriptServices-amd.js ./release/dev/lib/typescriptServices.js && tsc -p ./src/tsconfig.json",
+    "compile-esm": "mcopy ./src/lib/typescriptServices.js ./release/esm/lib/typescriptServices.js && tsc -p ./src/tsconfig.esm.json",
+    "compile": "mrmdir ./release && npm run compile-amd && npm run compile-esm",
     "watch": "tsc -p ./src --watch",
-    "prepublish": "npm run compile && node ./scripts/bundle && node ./scripts/copy ./src/monaco.d.ts ./release/monaco.d.ts",
+    "prepublish": "npm run compile && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts",
     "import-typescript": "node ./scripts/importTypescript"
   },
   "author": "Microsoft Corporation",
@@ -23,8 +23,9 @@
   "devDependencies": {
     "mocha": "^2.5.3",
     "monaco-editor-core": "0.11.1",
+    "monaco-plugin-helpers": "^1.0.2",
     "requirejs": "^2.3.5",
     "typescript": "2.7.2",
-    "uglify-js": "^3.3.13"
+    "uglify-js": "^3.3.14"
   }
 }

+ 3 - 3
scripts/bundle.js

@@ -1,12 +1,12 @@
 const requirejs = require('requirejs');
 const path = require('path');
 const fs = require('fs');
-const UglifyJS = require("uglify-js");
-const git = require('./git');
+const UglifyJS = require('uglify-js');
+const helpers = require('monaco-plugin-helpers');
 
 const REPO_ROOT = path.resolve(__dirname, '..');
 
-const sha1 = git.getGitVersion(REPO_ROOT);
+const sha1 = helpers.getGitVersion(REPO_ROOT);
 const semver = require('../package.json').version;
 const headerVersion = semver + '(' + sha1 + ')';
 

+ 0 - 30
scripts/copy.js

@@ -1,30 +0,0 @@
-/*---------------------------------------------------------------------------------------------
- *  Copyright (c) Microsoft Corporation. All rights reserved.
- *  Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
-
-const fs = require('fs');
-const path = require('path');
-
-const source = path.join(process.cwd(), process.argv[2]);
-const destination = path.join(process.cwd(), process.argv[3]);
-
-// ensure target dir
-(function () {
-	let dirs = [];
-	let dirname = path.dirname(destination);
-	while (dirname !== process.cwd()) {
-		dirs.push(dirname);
-		dirname = path.dirname(dirname);
-	}
-
-	dirs.reverse();
-
-	dirs.forEach((dir) => {
-		try { fs.mkdirSync(dir); } catch (err) { }
-	})
-})();
-
-fs.writeFileSync(destination, fs.readFileSync(source));
-
-console.log(`Copied ${process.argv[2]} to ${process.argv[3]}`);

+ 0 - 52
scripts/git.js

@@ -1,52 +0,0 @@
-const path = require('path');
-const fs = require('fs');
-
-exports.getGitVersion = function(repo) {
-	var git = path.join(repo, '.git');
-	var headPath = path.join(git, 'HEAD');
-	var head;
-
-	try {
-		head = fs.readFileSync(headPath, 'utf8').trim();
-	} catch (e) {
-		return void 0;
-	}
-
-	if (/^[0-9a-f]{40}$/i.test(head)) {
-		return head;
-	}
-
-	var refMatch = /^ref: (.*)$/.exec(head);
-
-	if (!refMatch) {
-		return void 0;
-	}
-
-	var ref = refMatch[1];
-	var refPath = path.join(git, ref);
-
-	try {
-		return fs.readFileSync(refPath, 'utf8').trim();
-	} catch (e) {
-		// noop
-	}
-
-	var packedRefsPath = path.join(git, 'packed-refs');
-	var refsRaw;
-
-	try {
-		refsRaw = fs.readFileSync(packedRefsPath, 'utf8').trim();
-	} catch (e) {
-		return void 0;
-	}
-
-	var refsRegex = /^([0-9a-f]{40})\s+(.+)$/gm;
-	var refsMatch;
-	var refs = {};
-
-	while (refsMatch = refsRegex.exec(refsRaw)) {
-		refs[refsMatch[2]] = refsMatch[1];
-	}
-
-	return refs[ref];
-};

+ 0 - 28
scripts/rmdir.js

@@ -1,28 +0,0 @@
-/*---------------------------------------------------------------------------------------------
- *  Copyright (c) Microsoft Corporation. All rights reserved.
- *  Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
-
-const fs = require('fs');
-const path = require('path');
-
-const target = path.join(process.cwd(), process.argv[2]);
-if (fs.existsSync(target)) {
-	rmDir(target);
-}
-console.log(`Deleted ${process.argv[2]}`);
-
-function rmDir(dirPath) {
-	let entries = fs.readdirSync(dirPath);
-	if (entries.length > 0) {
-		for (var i = 0; i < entries.length; i++) {
-			var filePath = path.join(dirPath, entries[i]);
-			if (fs.statSync(filePath).isFile()) {
-				fs.unlinkSync(filePath);
-			} else {
-				rmDir(filePath);
-			}
-		}
-	}
-	fs.rmdirSync(dirPath);
-}