Skip to content

Commit

Permalink
Use monaco dev version on local and alpha environments (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlatkovsky authored Mar 13, 2019
1 parent 02c1fe3 commit 98a2273
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
27 changes: 26 additions & 1 deletion packages/editor/scripts/postinstall.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { PACKAGE_VERSIONS, hyphenate } from '../../common/src/package-versions';

const IS_LOCAL_OR_ALPHA_ENV = checkIfLocalOrAlphaEnvironment();
if (IS_LOCAL_OR_ALPHA_ENV) {
console.info(
'Running locally or on alpha environment, will use non-minified versions ' +
'during postinstall, where appropriate',
);
}

const expectedPackages: {
[key: string]: {
name: string;
Expand All @@ -13,7 +21,7 @@ const expectedPackages: {
name: 'monaco-editor',
version: PACKAGE_VERSIONS['monaco-editor'],
copyAsName: 'monaco-editor',
pathToCopyFrom: 'min/vs',
pathToCopyFrom: `${IS_LOCAL_OR_ALPHA_ENV ? 'dev' : 'min'}/vs`,
pathToCopyTo: 'vs',
},
officeJs: {
Expand Down Expand Up @@ -94,3 +102,20 @@ for (const key in expectedPackages) {
fs.removeSync(pair.to);
fs.copySync(pair.from, pair.to);
});

///////////////////////////////////////

function checkIfLocalOrAlphaEnvironment() {
const { TRAVIS_BRANCH } = process.env; // from travis

if (!TRAVIS_BRANCH) {
// running locally
return true;
}

if (TRAVIS_BRANCH === 'master') {
return true;
}

return false;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Regex } from './utilities';
import { REGEX } from './utilities';

describe('Editor utilities', () => {
describe('regexes', () => {
Expand All @@ -12,10 +12,12 @@ describe('Editor utilities', () => {
};

Object.keys(validRefs).forEach((ref: string) => {
const tsr = new RegExp(Regex.TRIPLE_SLASH_REF);
const tsr = new RegExp(REGEX.TRIPLE_SLASH_REF);
expect(tsr.exec(ref)).toContain(validRefs[ref]);
});
});
});
});
});

// cspell:ignore regexes
30 changes: 15 additions & 15 deletions packages/editor/src/pages/Editor/store/editor/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function doesMonacoExist() {
return !!(window as any).monaco;
}

export const Regex = {
export const REGEX = {
STARTS_WITH_TYPINGS: /^.types\/.+|^dt~.+/i,
STARTS_WITH_COMMENT: /^#.*|^\/\/.*|^\/\*.*|.*\*\/$.*/im,
ENDS_WITH_CSS: /.*\.css$/i,
Expand All @@ -25,11 +25,11 @@ export function registerLibrariesMonacoLanguage() {
monaco.languages.setMonarchTokensProvider('libraries', {
tokenizer: {
root: [
{ regex: Regex.STARTS_WITH_COMMENT, action: { token: 'comment' } },
{ regex: Regex.ENDS_WITH_CSS, action: { token: 'number' } },
{ regex: Regex.STARTS_WITH_TYPINGS, action: { token: 'string' } },
{ regex: Regex.ENDS_WITH_DTS, action: { token: 'string' } },
{ regex: Regex.GLOBAL, action: { token: 'keyword' } },
{ regex: REGEX.STARTS_WITH_COMMENT, action: { token: 'comment' } },
{ regex: REGEX.ENDS_WITH_CSS, action: { token: 'number' } },
{ regex: REGEX.STARTS_WITH_TYPINGS, action: { token: 'string' } },
{ regex: REGEX.ENDS_WITH_DTS, action: { token: 'string' } },
{ regex: REGEX.GLOBAL, action: { token: 'keyword' } },
],
},
tokenPostfix: '',
Expand All @@ -44,7 +44,7 @@ export function registerLibrariesMonacoLanguage() {
endColumn: position.column,
});

if (Regex.STARTS_WITH_COMMENT.test(currentLine)) {
if (REGEX.STARTS_WITH_COMMENT.test(currentLine)) {
return { suggestions: [] };
}

Expand Down Expand Up @@ -108,11 +108,11 @@ export interface IPrettierSettings {
export function enablePrettierInMonaco(prettierSettings: IPrettierSettings) {
import('prettier/parser-typescript').then(prettierTypeScript => {
/* Adds Prettier Formatting to Monaco for TypeScript */
const PrettierTypeScriptFormatter: monaco.languages.DocumentFormattingEditProvider = {
const prettierTypeScriptFormatter: monaco.languages.DocumentFormattingEditProvider = {
provideDocumentFormattingEdits: (
document: monaco.editor.ITextModel,
options: monaco.languages.FormattingOptions,
token: monaco.CancellationToken,
_options: monaco.languages.FormattingOptions,
_token: monaco.CancellationToken,
): monaco.languages.TextEdit[] => {
const text = document.getValue();
const formatted = runTypeScriptPrettier(
Expand All @@ -132,7 +132,7 @@ export function enablePrettierInMonaco(prettierSettings: IPrettierSettings) {

monaco.languages.registerDocumentFormattingEditProvider(
'typescript',
PrettierTypeScriptFormatter,
prettierTypeScriptFormatter,
);
});
}
Expand Down Expand Up @@ -168,8 +168,8 @@ function runTypeScriptPrettier(
}

export function parseTripleSlashRefs(url: string, content: string) {
let match = Regex.TRIPLE_SLASH_REF.exec(content);
Regex.TRIPLE_SLASH_REF.lastIndex = 0;
let match = REGEX.TRIPLE_SLASH_REF.exec(content);
REGEX.TRIPLE_SLASH_REF.lastIndex = 0;
if (!match) {
return [];
}
Expand All @@ -187,8 +187,8 @@ export function parseTripleSlashRefs(url: string, content: string) {
additionalUrls.push(newUrl);
copyContent = copyContent.replace(ref, '');

match = Regex.TRIPLE_SLASH_REF.exec(copyContent);
Regex.TRIPLE_SLASH_REF.lastIndex = 0;
match = REGEX.TRIPLE_SLASH_REF.exec(copyContent);
REGEX.TRIPLE_SLASH_REF.lastIndex = 0;
}

return additionalUrls;
Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"rules": {
"member-access": [true, "no-public"],
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"],
"member-ordering": false,
"object-literal-shorthand": false,
"ordered-imports": false,
Expand Down

0 comments on commit 98a2273

Please # to comment.