mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 16:15:41 +01:00
Move import typescrit out of gulp
This commit is contained in:
parent
c45bf2eff6
commit
4158e69096
5 changed files with 150 additions and 133 deletions
129
gulpfile.js
129
gulpfile.js
|
|
@ -69,135 +69,6 @@ gulp.task('release', ['clean-release'], function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Import files from TypeScript's dist
|
|
||||||
*/
|
|
||||||
gulp.task('import-typescript', function() {
|
|
||||||
try {
|
|
||||||
fs.statSync(TYPESCRIPT_LIB_DESTINATION);
|
|
||||||
} catch (err) {
|
|
||||||
fs.mkdirSync(TYPESCRIPT_LIB_DESTINATION);
|
|
||||||
}
|
|
||||||
importLibDeclarationFile('lib.d.ts');
|
|
||||||
importLibDeclarationFile('lib.es6.d.ts');
|
|
||||||
|
|
||||||
var tsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.js')).toString();
|
|
||||||
|
|
||||||
var tsServices_amd = tsServices +
|
|
||||||
`
|
|
||||||
// MONACOCHANGE
|
|
||||||
// Defining the entire module name because r.js has an issue and cannot bundle this file
|
|
||||||
// correctly with an anonymous define call
|
|
||||||
define("vs/language/typescript/lib/typescriptServices", [], function() { return ts; });
|
|
||||||
// END MONACOCHANGE
|
|
||||||
`;
|
|
||||||
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices-amd.js'), tsServices_amd);
|
|
||||||
|
|
||||||
var tsServices_esm = tsServices +
|
|
||||||
`
|
|
||||||
// MONACOCHANGE
|
|
||||||
export const createClassifier = ts.createClassifier;
|
|
||||||
export const createLanguageService = ts.createLanguageService;
|
|
||||||
export const displayPartsToString = ts.displayPartsToString;
|
|
||||||
export const EndOfLineState = ts.EndOfLineState;
|
|
||||||
export const flattenDiagnosticMessageText = ts.flattenDiagnosticMessageText;
|
|
||||||
export const IndentStyle = ts.IndentStyle;
|
|
||||||
export const ScriptKind = ts.ScriptKind;
|
|
||||||
export const ScriptTarget = ts.ScriptTarget;
|
|
||||||
export const TokenClass = ts.TokenClass;
|
|
||||||
// END MONACOCHANGE
|
|
||||||
`;
|
|
||||||
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.js'), tsServices_esm);
|
|
||||||
|
|
||||||
var dtsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.d.ts')).toString();
|
|
||||||
dtsServices +=
|
|
||||||
`
|
|
||||||
// MONACOCHANGE
|
|
||||||
export = ts;
|
|
||||||
// END MONACOCHANGE
|
|
||||||
`;
|
|
||||||
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), dtsServices);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Import a lib*.d.ts file from TypeScript's dist
|
|
||||||
*/
|
|
||||||
function importLibDeclarationFile(name) {
|
|
||||||
var dstName = name.replace(/\.d\.ts$/, '').replace(/\./g, '-') + '-ts';
|
|
||||||
var srcPath = path.join(TYPESCRIPT_LIB_SOURCE, name);
|
|
||||||
|
|
||||||
var contents = fs.readFileSync(srcPath).toString();
|
|
||||||
|
|
||||||
var dstPath = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.ts');
|
|
||||||
fs.writeFileSync(dstPath,
|
|
||||||
`/*---------------------------------------------------------------------------------------------
|
|
||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
||||||
*--------------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
export const contents = "${escapeText(contents)}";
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape text such that it can be used in a javascript string enclosed by double quotes (")
|
|
||||||
*/
|
|
||||||
function escapeText(text) {
|
|
||||||
// See http://www.javascriptkit.com/jsref/escapesequence.shtml
|
|
||||||
var _backspace = '\b'.charCodeAt(0);
|
|
||||||
var _formFeed = '\f'.charCodeAt(0);
|
|
||||||
var _newLine = '\n'.charCodeAt(0);
|
|
||||||
var _nullChar = 0;
|
|
||||||
var _carriageReturn = '\r'.charCodeAt(0);
|
|
||||||
var _tab = '\t'.charCodeAt(0);
|
|
||||||
var _verticalTab = '\v'.charCodeAt(0);
|
|
||||||
var _backslash = '\\'.charCodeAt(0);
|
|
||||||
var _doubleQuote = '"'.charCodeAt(0);
|
|
||||||
|
|
||||||
var startPos = 0, chrCode, replaceWith = null, resultPieces = [];
|
|
||||||
|
|
||||||
for (var i = 0, len = text.length; i < len; i++) {
|
|
||||||
chrCode = text.charCodeAt(i);
|
|
||||||
switch (chrCode) {
|
|
||||||
case _backspace:
|
|
||||||
replaceWith = '\\b';
|
|
||||||
break;
|
|
||||||
case _formFeed:
|
|
||||||
replaceWith = '\\f';
|
|
||||||
break;
|
|
||||||
case _newLine:
|
|
||||||
replaceWith = '\\n';
|
|
||||||
break;
|
|
||||||
case _nullChar:
|
|
||||||
replaceWith = '\\0';
|
|
||||||
break;
|
|
||||||
case _carriageReturn:
|
|
||||||
replaceWith = '\\r';
|
|
||||||
break;
|
|
||||||
case _tab:
|
|
||||||
replaceWith = '\\t';
|
|
||||||
break;
|
|
||||||
case _verticalTab:
|
|
||||||
replaceWith = '\\v';
|
|
||||||
break;
|
|
||||||
case _backslash:
|
|
||||||
replaceWith = '\\\\';
|
|
||||||
break;
|
|
||||||
case _doubleQuote:
|
|
||||||
replaceWith = '\\"';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (replaceWith !== null) {
|
|
||||||
resultPieces.push(text.substring(startPos, i));
|
|
||||||
resultPieces.push(replaceWith);
|
|
||||||
startPos = i + 1;
|
|
||||||
replaceWith = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultPieces.push(text.substring(startPos, len));
|
|
||||||
return resultPieces.join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGitVersion(repo) {
|
function getGitVersion(repo) {
|
||||||
var git = path.join(repo, '.git');
|
var git = path.join(repo, '.git');
|
||||||
var headPath = path.join(git, 'HEAD');
|
var headPath = path.join(git, 'HEAD');
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
"description": "TypeScript and JavaScript language support for Monaco Editor",
|
"description": "TypeScript and JavaScript language support for Monaco Editor",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha",
|
"test": "mocha",
|
||||||
"compile-amd": "node ./scripts/copy.js ./src/lib/typescriptServices-amd.js ./release/dev/lib/typescriptServices.js && tsc -p ./src/tsconfig.json",
|
"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.js ./src/lib/typescriptServices.js ./release/esm/lib/typescriptServices.js && tsc -p ./src/tsconfig.esm.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.js ./release && npm run compile-amd && npm run compile-esm",
|
"compile": "node ./scripts/rmdir ./release && npm run compile-amd && npm run compile-esm",
|
||||||
"watch": "tsc -p ./src --watch",
|
"watch": "tsc -p ./src --watch",
|
||||||
"prepublish": "npm run compile && gulp release",
|
"prepublish": "npm run compile && gulp release",
|
||||||
"import-typescript": "gulp import-typescript"
|
"import-typescript": "node ./scripts/importTypescript"
|
||||||
},
|
},
|
||||||
"author": "Microsoft Corporation",
|
"author": "Microsoft Corporation",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* 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 fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
|
|
||||||
136
scripts/importTypescript.js
Normal file
136
scripts/importTypescript.js
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const TYPESCRIPT_LIB_SOURCE = path.join(__dirname, '../node_modules/typescript/lib');
|
||||||
|
const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
fs.statSync(TYPESCRIPT_LIB_DESTINATION);
|
||||||
|
} catch (err) {
|
||||||
|
fs.mkdirSync(TYPESCRIPT_LIB_DESTINATION);
|
||||||
|
}
|
||||||
|
importLibDeclarationFile('lib.d.ts');
|
||||||
|
importLibDeclarationFile('lib.es6.d.ts');
|
||||||
|
|
||||||
|
var tsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.js')).toString();
|
||||||
|
|
||||||
|
var tsServices_amd = tsServices +
|
||||||
|
`
|
||||||
|
// MONACOCHANGE
|
||||||
|
// Defining the entire module name because r.js has an issue and cannot bundle this file
|
||||||
|
// correctly with an anonymous define call
|
||||||
|
define("vs/language/typescript/lib/typescriptServices", [], function() { return ts; });
|
||||||
|
// END MONACOCHANGE
|
||||||
|
`;
|
||||||
|
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices-amd.js'), tsServices_amd);
|
||||||
|
|
||||||
|
var tsServices_esm = tsServices +
|
||||||
|
`
|
||||||
|
// MONACOCHANGE
|
||||||
|
export const createClassifier = ts.createClassifier;
|
||||||
|
export const createLanguageService = ts.createLanguageService;
|
||||||
|
export const displayPartsToString = ts.displayPartsToString;
|
||||||
|
export const EndOfLineState = ts.EndOfLineState;
|
||||||
|
export const flattenDiagnosticMessageText = ts.flattenDiagnosticMessageText;
|
||||||
|
export const IndentStyle = ts.IndentStyle;
|
||||||
|
export const ScriptKind = ts.ScriptKind;
|
||||||
|
export const ScriptTarget = ts.ScriptTarget;
|
||||||
|
export const TokenClass = ts.TokenClass;
|
||||||
|
// END MONACOCHANGE
|
||||||
|
`;
|
||||||
|
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.js'), tsServices_esm);
|
||||||
|
|
||||||
|
var dtsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.d.ts')).toString();
|
||||||
|
dtsServices +=
|
||||||
|
`
|
||||||
|
// MONACOCHANGE
|
||||||
|
export = ts;
|
||||||
|
// END MONACOCHANGE
|
||||||
|
`;
|
||||||
|
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), dtsServices);
|
||||||
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import a lib*.d.ts file from TypeScript's dist
|
||||||
|
*/
|
||||||
|
function importLibDeclarationFile(name) {
|
||||||
|
var dstName = name.replace(/\.d\.ts$/, '').replace(/\./g, '-') + '-ts';
|
||||||
|
var srcPath = path.join(TYPESCRIPT_LIB_SOURCE, name);
|
||||||
|
|
||||||
|
var contents = fs.readFileSync(srcPath).toString();
|
||||||
|
|
||||||
|
var dstPath = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.ts');
|
||||||
|
fs.writeFileSync(dstPath,
|
||||||
|
`/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
export const contents = "${escapeText(contents)}";
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape text such that it can be used in a javascript string enclosed by double quotes (")
|
||||||
|
*/
|
||||||
|
function escapeText(text) {
|
||||||
|
// See http://www.javascriptkit.com/jsref/escapesequence.shtml
|
||||||
|
var _backspace = '\b'.charCodeAt(0);
|
||||||
|
var _formFeed = '\f'.charCodeAt(0);
|
||||||
|
var _newLine = '\n'.charCodeAt(0);
|
||||||
|
var _nullChar = 0;
|
||||||
|
var _carriageReturn = '\r'.charCodeAt(0);
|
||||||
|
var _tab = '\t'.charCodeAt(0);
|
||||||
|
var _verticalTab = '\v'.charCodeAt(0);
|
||||||
|
var _backslash = '\\'.charCodeAt(0);
|
||||||
|
var _doubleQuote = '"'.charCodeAt(0);
|
||||||
|
|
||||||
|
var startPos = 0, chrCode, replaceWith = null, resultPieces = [];
|
||||||
|
|
||||||
|
for (var i = 0, len = text.length; i < len; i++) {
|
||||||
|
chrCode = text.charCodeAt(i);
|
||||||
|
switch (chrCode) {
|
||||||
|
case _backspace:
|
||||||
|
replaceWith = '\\b';
|
||||||
|
break;
|
||||||
|
case _formFeed:
|
||||||
|
replaceWith = '\\f';
|
||||||
|
break;
|
||||||
|
case _newLine:
|
||||||
|
replaceWith = '\\n';
|
||||||
|
break;
|
||||||
|
case _nullChar:
|
||||||
|
replaceWith = '\\0';
|
||||||
|
break;
|
||||||
|
case _carriageReturn:
|
||||||
|
replaceWith = '\\r';
|
||||||
|
break;
|
||||||
|
case _tab:
|
||||||
|
replaceWith = '\\t';
|
||||||
|
break;
|
||||||
|
case _verticalTab:
|
||||||
|
replaceWith = '\\v';
|
||||||
|
break;
|
||||||
|
case _backslash:
|
||||||
|
replaceWith = '\\\\';
|
||||||
|
break;
|
||||||
|
case _doubleQuote:
|
||||||
|
replaceWith = '\\"';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (replaceWith !== null) {
|
||||||
|
resultPieces.push(text.substring(startPos, i));
|
||||||
|
resultPieces.push(replaceWith);
|
||||||
|
startPos = i + 1;
|
||||||
|
replaceWith = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultPieces.push(text.substring(startPos, len));
|
||||||
|
return resultPieces.join('');
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* 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 fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue