Refactor project shape

This commit is contained in:
Alex Dima 2018-03-08 15:28:00 +01:00
parent 5c70cefbad
commit 92af97ca38
25 changed files with 96 additions and 104 deletions

View file

@ -1,8 +1,7 @@
/.vscode/ /.vscode/
/lib/
/out/ /out/
/scripts/
/src/ /src/
/test/
/gulpfile.js /gulpfile.js
/tsconfig.json /tsconfig.json
/.npmignore /.npmignore

View file

@ -8,7 +8,7 @@ herein, whether by implication, estoppel or otherwise.
%% typescript version 1.8.10 (https://github.com/Microsoft/TypeScript) %% typescript version 2.7.2 (https://github.com/Microsoft/TypeScript)
========================================= =========================================
Copyright (c) Microsoft Corporation. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved.

View file

@ -15,10 +15,10 @@ var rimraf = require('rimraf');
var es = require('event-stream'); var es = require('event-stream');
var TYPESCRIPT_LIB_SOURCE = path.join(__dirname, 'node_modules', 'typescript', 'lib'); var TYPESCRIPT_LIB_SOURCE = path.join(__dirname, 'node_modules', 'typescript', 'lib');
var TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, 'lib'); var TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, 'src', 'lib');
gulp.task('clean-release', function(cb) { rimraf('release', { maxBusyTries: 1 }, cb); }); gulp.task('clean-release', function(cb) { rimraf('release', { maxBusyTries: 1 }, cb); });
gulp.task('release', ['clean-release','compile'], function() { gulp.task('release', ['clean-release'], function() {
var sha1 = getGitVersion(__dirname); var sha1 = getGitVersion(__dirname);
var semver = require('./package.json').version; var semver = require('./package.json').version;
@ -36,22 +36,22 @@ gulp.task('release', ['clean-release','compile'], function() {
function bundleOne(moduleId, exclude) { function bundleOne(moduleId, exclude) {
return rjs({ return rjs({
baseUrl: '/out/', baseUrl: '/out/amd/',
name: 'vs/language/typescript/' + moduleId, name: 'vs/language/typescript/' + moduleId,
out: moduleId + '.js', out: moduleId + '.js',
exclude: exclude, exclude: exclude,
paths: { paths: {
'vs/language/typescript': __dirname + '/out' 'vs/language/typescript': __dirname + '/out/amd/'
} }
}) })
} }
return merge( return merge(
merge( merge(
bundleOne('src/monaco.contribution'), bundleOne('monaco.contribution'),
bundleOne('lib/typescriptServices'), bundleOne('lib/typescriptServices'),
bundleOne('src/mode', ['vs/language/typescript/lib/typescriptServices']), bundleOne('mode', ['vs/language/typescript/lib/typescriptServices']),
bundleOne('src/worker', ['vs/language/typescript/lib/typescriptServices']) bundleOne('worker', ['vs/language/typescript/lib/typescriptServices'])
) )
.pipe(uglify({ .pipe(uglify({
preserveComments: 'some' preserveComments: 'some'
@ -65,31 +65,10 @@ gulp.task('release', ['clean-release','compile'], function() {
})) }))
.pipe(gulp.dest('./release/')), .pipe(gulp.dest('./release/')),
gulp.src('src/monaco.d.ts').pipe(gulp.dest('./release/')) gulp.src('src/monaco.d.ts').pipe(gulp.dest('./release/')),
); );
}); });
var compilation = tsb.create(assign({ verbose: true }, require('./tsconfig.json').compilerOptions));
var tsSources = require('./tsconfig.json').include.concat(require('./tsconfig.json').files);
function compileTask() {
return merge(
gulp.src('lib/*.js', { base: '.' }),
gulp.src(tsSources).pipe(compilation())
)
.pipe(gulp.dest('out'));
}
gulp.task('clean-out', function(cb) { rimraf('out', { maxBusyTries: 1 }, cb); });
gulp.task('compile', ['clean-out'], compileTask);
gulp.task('compile-without-clean', compileTask);
gulp.task('watch', ['compile'], function() {
gulp.watch(tsSources, ['compile-without-clean']);
});
/** /**
* Import files from TypeScript's dist * Import files from TypeScript's dist
*/ */
@ -132,27 +111,14 @@ function importLibDeclarationFile(name) {
var contents = fs.readFileSync(srcPath).toString(); var contents = fs.readFileSync(srcPath).toString();
var dstPath1 = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.js'); var dstPath = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.ts');
fs.writeFileSync(dstPath1, fs.writeFileSync(dstPath,
`/*--------------------------------------------------------------------------------------------- `/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
// This is a generated file from ${name} export const contents = "${escapeText(contents)}";
define([], function() { return { contents: "${escapeText(contents)}"}; });
`);
var dstPath2 = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.d.ts');
fs.writeFileSync(dstPath2,
`/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export declare var contents: string;
`); `);
} }

6
lib/lib-es6-ts.d.ts vendored
View file

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

File diff suppressed because one or more lines are too long

6
lib/lib-ts.d.ts vendored
View file

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

File diff suppressed because one or more lines are too long

View file

@ -4,8 +4,9 @@
"description": "TypeScript and JavaScript language support for Monaco Editor", "description": "TypeScript and JavaScript language support for Monaco Editor",
"scripts": { "scripts": {
"test": "mocha", "test": "mocha",
"watch": "gulp watch", "compile": "node ./scripts/rmdir.js ./out && node ./scripts/copy.js ./src/lib/typescriptServices.js ./out/amd/lib/typescriptServices.js && tsc -p ./src",
"prepublish": "gulp release", "watch": "tsc -p ./src --watch",
"prepublish": "npm run compile && gulp release",
"import-typescript": "gulp import-typescript" "import-typescript": "gulp import-typescript"
}, },
"author": "Microsoft Corporation", "author": "Microsoft Corporation",

25
scripts/copy.js Normal file
View file

@ -0,0 +1,25 @@
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]}`);

21
scripts/rmdir.js Normal file
View file

@ -0,0 +1,21 @@
const fs = require('fs');
const path = require('path');
const target = path.join(process.cwd(), process.argv[2]);
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);
}

View file

@ -5,7 +5,7 @@
'use strict'; 'use strict';
import { LanguageServiceDefaultsImpl } from './monaco.contribution'; import { LanguageServiceDefaultsImpl } from './monaco.contribution';
import * as ts from '../lib/typescriptServices'; import * as ts from './lib/typescriptServices';
import { TypeScriptWorker } from './worker'; import { TypeScriptWorker } from './worker';
import Uri = monaco.Uri; import Uri = monaco.Uri;

6
src/lib/lib-es6-ts.ts Normal file

File diff suppressed because one or more lines are too long

6
src/lib/lib-ts.ts Normal file

File diff suppressed because one or more lines are too long

View file

@ -196,7 +196,7 @@ monaco.languages.typescript = createAPI();
// --- Registration to monaco editor --- // --- Registration to monaco editor ---
function withMode(callback: (module: typeof mode) => void): void { function withMode(callback: (module: typeof mode) => void): void {
require<typeof mode>(['vs/language/typescript/src/mode'], callback); require<typeof mode>(['./mode'], callback);
} }
monaco.languages.register({ monaco.languages.register({

View file

@ -5,7 +5,7 @@
'use strict'; 'use strict';
import * as assert from 'assert'; import * as assert from 'assert';
import {createTokenizationSupport, Language} from '../src/tokenization'; import {createTokenizationSupport, Language} from '../tokenization';
suite('tokenization', () => { suite('tokenization', () => {

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import ts = require('../lib/typescriptServices'); import ts = require('./lib/typescriptServices');
export enum Language { export enum Language {
TypeScript, TypeScript,

13
src/tsconfig.json Normal file
View file

@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "amd",
"outDir": "../out/amd",
"target": "es5"
},
"include": [
"**/*.ts"
],
"files": [
"../node_modules/monaco-editor-core/monaco.d.ts"
]
}

View file

@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import ts = require('../lib/typescriptServices'); import ts = require('./lib/typescriptServices');
import { contents as libdts } from '../lib/lib-ts'; import { contents as libdts } from './lib/lib-ts';
import { contents as libes6ts } from '../lib/lib-es6-ts'; import { contents as libes6ts } from './lib/lib-es6-ts';
import Promise = monaco.Promise; import Promise = monaco.Promise;
import IWorkerContext = monaco.worker.IWorkerContext; import IWorkerContext = monaco.worker.IWorkerContext;

View file

@ -63,7 +63,7 @@ export class WorkerManager {
this._worker = monaco.editor.createWebWorker<TypeScriptWorker>({ this._worker = monaco.editor.createWebWorker<TypeScriptWorker>({
// module that exports the create() method and returns a `TypeScriptWorker` instance // module that exports the create() method and returns a `TypeScriptWorker` instance
moduleId: 'vs/language/typescript/src/worker', moduleId: 'vs/language/typescript/worker',
label: this._modeId, label: this._modeId,

View file

@ -4,7 +4,7 @@ var path = require('path');
requirejs.config({ requirejs.config({
baseUrl: 'out', baseUrl: 'out',
paths: { paths: {
'vs/language/typescript': path.join(__dirname, '/../out') 'vs/language/typescript': path.join(__dirname, '/../out/amd')
}, },
nodeRequire: require nodeRequire: require
}); });

View file

@ -1,15 +0,0 @@
{
"compilerOptions": {
"module": "amd",
"outDir": "out",
"target": "es5"
},
"include": [
"src/*.ts",
"test/*.ts",
"lib/*.d.ts"
],
"files": [
"node_modules/monaco-editor-core/monaco.d.ts"
]
}