From a8741f55a939acf1a754e6415c47153fffe7b0d3 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 12 Mar 2018 13:52:13 +0100 Subject: [PATCH] Adopt monaco-plugin-helpers --- package-lock.json | 9 ++++++++ package.json | 3 ++- scripts/bundle.js | 4 ++-- scripts/copy.js | 30 --------------------------- scripts/git.js | 52 ----------------------------------------------- scripts/rmdir.js | 28 ------------------------- 6 files changed, 13 insertions(+), 113 deletions(-) delete mode 100644 scripts/copy.js delete mode 100644 scripts/git.js delete mode 100644 scripts/rmdir.js diff --git a/package-lock.json b/package-lock.json index f3b02eef..36f1d224 100644 --- a/package-lock.json +++ b/package-lock.json @@ -645,6 +645,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": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/package.json b/package.json index 7183dcef..70962ecc 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.9.0", "description": "Bundle of many languages for the Monaco Editor.", "scripts": { - "compile": "node ./scripts/rmdir ./release && tsc -p ./src/tsconfig.json && tsc -p ./src/tsconfig.esm.json", + "compile": "mrmdir ./release && tsc -p ./src/tsconfig.json && tsc -p ./src/tsconfig.esm.json", "watch": "tsc -p ./src --watch", "test": "mocha", "prepublish": "npm run compile && node ./scripts/bundle" @@ -21,6 +21,7 @@ "jsdom-no-contextify": "^3.1.0", "mocha": "^3.4.2", "monaco-editor-core": "0.11.1", + "monaco-plugin-helpers": "^1.0.2", "requirejs": "^2.3.5", "typescript": "2.7.2", "uglify-js": "^3.3.14" diff --git a/scripts/bundle.js b/scripts/bundle.js index 6cb50163..1d3ad68a 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -2,11 +2,11 @@ const requirejs = require('requirejs'); const path = require('path'); const fs = require('fs'); const UglifyJS = require("uglify-js"); -const git = require('./git'); +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 + ')'; diff --git a/scripts/copy.js b/scripts/copy.js deleted file mode 100644 index 154d8562..00000000 --- a/scripts/copy.js +++ /dev/null @@ -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]}`); diff --git a/scripts/git.js b/scripts/git.js deleted file mode 100644 index f7d46f1d..00000000 --- a/scripts/git.js +++ /dev/null @@ -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]; -}; diff --git a/scripts/rmdir.js b/scripts/rmdir.js deleted file mode 100644 index 6bb4855d..00000000 --- a/scripts/rmdir.js +++ /dev/null @@ -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); -}