๐Ÿ“ฆ microsoft / monaco-editor

๐Ÿ“„ check-samples.ts ยท 54 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as fs from 'fs';
import * as glob from 'glob';
import * as path from 'path';
import { REPO_ROOT } from './utils';

checkEveryMonacoLanguageHasASample();

function checkEveryMonacoLanguageHasASample() {
	let languages = glob
		.sync('src/languages/definitions/*/register.ts', { cwd: REPO_ROOT })
		.map((f) => path.dirname(f))
		.map((f) => f.substring('src/languages/definitions/'.length));
	languages.push('css');
	languages.push('html');
	languages.push('json');
	languages.push('typescript');

	// some languages have a different id than their folder
	languages = languages.map((l) => {
		switch (l) {
			case 'coffee':
				return 'coffeescript';
			case 'protobuf':
				return 'proto';
			case 'solidity':
				return 'sol';
			case 'sophia':
				return 'aes';
			default:
				return l;
		}
	});

	let fail = false;
	for (const language of languages) {
		const expectedSamplePath = path.join(
			REPO_ROOT,
			`website/src/website/data/home-samples/sample.${language}.txt`
		);
		if (!fs.existsSync(expectedSamplePath)) {
			console.error(`Missing sample for ${language} at ${expectedSamplePath}`);
			fail = true;
		}
	}
	if (fail) {
		process.exit(1);
	}
}