Skip to content

Commit 331acc5

Browse files
jriekenalexdima
authored andcommitted
Initial version
1 parent a818bff commit 331acc5

26 files changed

+59386
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/out/
3+
/release/

.npmignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.vscode/
2+
/lib/
3+
/out/
4+
/src/
5+
/test/
6+
/gulpfile.js
7+
/tsconfig.json
8+
/.npmignore

.vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.trimTrailingWhitespace": true,
4+
"search.exclude": {
5+
"**/node_modules": true,
6+
"**/release": true,
7+
"**/out": true
8+
}
9+
}

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Microsoft Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
# monaco-typescript
2-
TypeScript/JavaScript language support for the Monaco Editor
1+
# Monaco TypeScript
2+
3+
TypeScript and JavaScript language support for the Monaco Editor.
4+
5+
![typescript](https://cloud.githubusercontent.com/assets/5047891/15926623/5262fe08-2e3d-11e6-9b90-1d43fda07178.gif)
6+
7+
## Installing
8+
9+
This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module.
10+
11+
## License
12+
[MIT](https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md)

gulpfile.js

+273
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
var gulp = require('gulp');
7+
var tsb = require('gulp-tsb');
8+
var assign = require('object-assign');
9+
var fs = require('fs');
10+
var path = require('path');
11+
var merge = require('merge-stream');
12+
var rjs = require('gulp-requirejs');
13+
var uglify = require('gulp-uglify');
14+
var rimraf = require('rimraf');
15+
var es = require('event-stream');
16+
17+
var TYPESCRIPT_LIB_SOURCE = path.join(__dirname, 'node_modules', 'typescript', 'lib');
18+
var TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, 'lib');
19+
20+
gulp.task('clean-release', function(cb) { rimraf('release', { maxBusyTries: 1 }, cb); });
21+
gulp.task('release', ['clean-release','compile'], function() {
22+
23+
var sha1 = getGitVersion(__dirname);
24+
var semver = require('./package.json').version;
25+
var headerVersion = semver + '(' + sha1 + ')';
26+
27+
var BUNDLED_FILE_HEADER = [
28+
'/*!-----------------------------------------------------------------------------',
29+
' * Copyright (c) Microsoft Corporation. All rights reserved.',
30+
' * monaco-typescript version: ' + headerVersion,
31+
' * Released under the MIT license',
32+
' * https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md',
33+
' *-----------------------------------------------------------------------------*/',
34+
''
35+
].join('\n');
36+
37+
function bundleOne(moduleId, exclude) {
38+
return rjs({
39+
baseUrl: '/out/',
40+
name: 'vs/language/typescript/' + moduleId,
41+
out: moduleId + '.js',
42+
exclude: exclude,
43+
paths: {
44+
'vs/language/typescript': __dirname + '/out'
45+
}
46+
})
47+
}
48+
49+
return merge(
50+
bundleOne('src/monaco.contribution'),
51+
bundleOne('lib/typescriptServices'),
52+
bundleOne('src/mode', ['vs/language/typescript/lib/typescriptServices']),
53+
bundleOne('src/worker', ['vs/language/typescript/lib/typescriptServices'])
54+
)
55+
.pipe(uglify({
56+
preserveComments: 'some'
57+
}))
58+
.pipe(es.through(function(data) {
59+
data.contents = new Buffer(
60+
BUNDLED_FILE_HEADER
61+
+ data.contents.toString()
62+
);
63+
this.emit('data', data);
64+
}))
65+
.pipe(gulp.dest('./release/'));
66+
});
67+
68+
69+
var compilation = tsb.create(assign({ verbose: true }, require('./tsconfig.json').compilerOptions));
70+
71+
var tsSources = require('./tsconfig.json').filesGlob;
72+
73+
function compileTask() {
74+
return merge(
75+
gulp.src('lib/*.js', { base: '.' }),
76+
gulp.src(tsSources).pipe(compilation())
77+
)
78+
.pipe(gulp.dest('out'));
79+
}
80+
81+
gulp.task('clean-out', function(cb) { rimraf('out', { maxBusyTries: 1 }, cb); });
82+
gulp.task('compile', ['clean-out'], compileTask);
83+
gulp.task('compile-without-clean', compileTask);
84+
gulp.task('watch', ['compile'], function() {
85+
gulp.watch(tsSources, ['compile-without-clean']);
86+
});
87+
88+
89+
/**
90+
* Import files from TypeScript's dist
91+
*/
92+
gulp.task('import-typescript', function() {
93+
try {
94+
fs.statSync(TYPESCRIPT_LIB_DESTINATION);
95+
} catch (err) {
96+
fs.mkdirSync(TYPESCRIPT_LIB_DESTINATION);
97+
}
98+
importLibDeclarationFile('lib.d.ts');
99+
importLibDeclarationFile('lib.es6.d.ts');
100+
101+
var tsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.js')).toString();
102+
tsServices +=
103+
`
104+
// MONACOCHANGE
105+
define([], function() { return ts; });
106+
// END MONACOCHANGE
107+
`;
108+
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.js'), tsServices);
109+
110+
var dtsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.d.ts')).toString();
111+
dtsServices +=
112+
`
113+
// MONACOCHANGE
114+
export = ts;
115+
// END MONACOCHANGE
116+
`;
117+
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), dtsServices);
118+
});
119+
120+
/**
121+
* Import a lib*.d.ts file from TypeScript's dist
122+
*/
123+
function importLibDeclarationFile(name) {
124+
var dstName = name.replace(/\.d\.ts$/, '').replace(/\./g, '-') + '-ts';
125+
var srcPath = path.join(TYPESCRIPT_LIB_SOURCE, name);
126+
127+
var contents = fs.readFileSync(srcPath).toString();
128+
129+
var dstPath1 = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.js');
130+
fs.writeFileSync(dstPath1,
131+
`/*---------------------------------------------------------------------------------------------
132+
* Copyright (c) Microsoft Corporation. All rights reserved.
133+
* Licensed under the MIT License. See License.txt in the project root for license information.
134+
*--------------------------------------------------------------------------------------------*/
135+
136+
// This is a generated file from ${name}
137+
138+
define([], function() { return { contents: "${escapeText(contents)}"}; });
139+
140+
`);
141+
142+
var dstPath2 = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.d.ts');
143+
fs.writeFileSync(dstPath2,
144+
`/*---------------------------------------------------------------------------------------------
145+
* Copyright (c) Microsoft Corporation. All rights reserved.
146+
* Licensed under the MIT License. See License.txt in the project root for license information.
147+
*--------------------------------------------------------------------------------------------*/
148+
149+
export declare var contents: string;
150+
`);
151+
}
152+
153+
/**
154+
* Escape text such that it can be used in a javascript string enclosed by double quotes (")
155+
*/
156+
function escapeText(text) {
157+
// http://www.javascriptkit.com/jsref/escapesequence.shtml
158+
// \b Backspace.
159+
// \f Form feed.
160+
// \n Newline.
161+
// \O Nul character.
162+
// \r Carriage return.
163+
// \t Horizontal tab.
164+
// \v Vertical tab.
165+
// \' Single quote or apostrophe.
166+
// \" Double quote.
167+
// \\ Backslash.
168+
// \ddd The Latin-1 character specified by the three octal digits between 0 and 377. ie, copyright symbol is \251.
169+
// \xdd The Latin-1 character specified by the two hexadecimal digits dd between 00 and FF. ie, copyright symbol is \xA9.
170+
// \udddd The Unicode character specified by the four hexadecimal digits dddd. ie, copyright symbol is \u00A9.
171+
var _backspace = '\b'.charCodeAt(0);
172+
var _formFeed = '\f'.charCodeAt(0);
173+
var _newLine = '\n'.charCodeAt(0);
174+
var _nullChar = 0;
175+
var _carriageReturn = '\r'.charCodeAt(0);
176+
var _tab = '\t'.charCodeAt(0);
177+
var _verticalTab = '\v'.charCodeAt(0);
178+
var _backslash = '\\'.charCodeAt(0);
179+
var _doubleQuote = '"'.charCodeAt(0);
180+
181+
var startPos = 0, chrCode, replaceWith = null, resultPieces = [];
182+
183+
for (var i = 0, len = text.length; i < len; i++) {
184+
chrCode = text.charCodeAt(i);
185+
switch (chrCode) {
186+
case _backspace:
187+
replaceWith = '\\b';
188+
break;
189+
case _formFeed:
190+
replaceWith = '\\f';
191+
break;
192+
case _newLine:
193+
replaceWith = '\\n';
194+
break;
195+
case _nullChar:
196+
replaceWith = '\\0';
197+
break;
198+
case _carriageReturn:
199+
replaceWith = '\\r';
200+
break;
201+
case _tab:
202+
replaceWith = '\\t';
203+
break;
204+
case _verticalTab:
205+
replaceWith = '\\v';
206+
break;
207+
case _backslash:
208+
replaceWith = '\\\\';
209+
break;
210+
case _doubleQuote:
211+
replaceWith = '\\"';
212+
break;
213+
}
214+
if (replaceWith !== null) {
215+
resultPieces.push(text.substring(startPos, i));
216+
resultPieces.push(replaceWith);
217+
startPos = i + 1;
218+
replaceWith = null;
219+
}
220+
}
221+
resultPieces.push(text.substring(startPos, len));
222+
return resultPieces.join('');
223+
}
224+
225+
function getGitVersion(repo) {
226+
var git = path.join(repo, '.git');
227+
var headPath = path.join(git, 'HEAD');
228+
var head;
229+
230+
try {
231+
head = fs.readFileSync(headPath, 'utf8').trim();
232+
} catch (e) {
233+
return void 0;
234+
}
235+
236+
if (/^[0-9a-f]{40}$/i.test(head)) {
237+
return head;
238+
}
239+
240+
var refMatch = /^ref: (.*)$/.exec(head);
241+
242+
if (!refMatch) {
243+
return void 0;
244+
}
245+
246+
var ref = refMatch[1];
247+
var refPath = path.join(git, ref);
248+
249+
try {
250+
return fs.readFileSync(refPath, 'utf8').trim();
251+
} catch (e) {
252+
// noop
253+
}
254+
255+
var packedRefsPath = path.join(git, 'packed-refs');
256+
var refsRaw;
257+
258+
try {
259+
refsRaw = fs.readFileSync(packedRefsPath, 'utf8').trim();
260+
} catch (e) {
261+
return void 0;
262+
}
263+
264+
var refsRegex = /^([0-9a-f]{40})\s+(.+)$/gm;
265+
var refsMatch;
266+
var refs = {};
267+
268+
while (refsMatch = refsRegex.exec(refsRaw)) {
269+
refs[refsMatch[2]] = refsMatch[1];
270+
}
271+
272+
return refs[ref];
273+
}

lib/lib-es6-ts.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export declare var contents: string;

lib/lib-es6-ts.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/lib-ts.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export declare var contents: string;

lib/lib-ts.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)