Skip to content

Commit

Permalink
Use postman-request instead of node-fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jun 30, 2023
1 parent 9c0c2b9 commit 2ca89c3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 93 deletions.
74 changes: 0 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"build-docs": "statigen -s docs -o .tmp/docs",
"watch-docs": "npm run build-docs -- --watch",
"releases": "ts-node scripts/releases.ts",
"sync-syntaxes": "node scripts/sync-scenegraph-tmlanguage.js"
"sync-syntaxes": "ts-node scripts/sync-scenegraph-tmlanguage.ts"
},
"dependencies": {
"@vscode/extension-telemetry": "^0.4.7",
Expand Down Expand Up @@ -110,7 +110,6 @@
"eslint-plugin-no-only-tests": "^2.6.0",
"latest-version": "^5.1.0",
"mocha": "^9.1.3",
"node-fetch": "^2.6.1",
"node-notifier": "^10.0.1",
"nyc": "^15.0.0",
"ovsx": "^0.5.2",
Expand Down
17 changes: 0 additions & 17 deletions scripts/sync-scenegraph-tmlanguage.js

This file was deleted.

35 changes: 35 additions & 0 deletions scripts/sync-scenegraph-tmlanguage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as fsExtra from 'fs-extra';
import * as r from 'postman-request';
import type { Response } from 'request';
import type * as requestType from 'request';
const request = r as typeof requestType;

(async () => {
const json = JSON.parse(
(await httpGet('https://raw.githubusercontent.com/microsoft/vscode/main/extensions/xml/syntaxes/xml.tmLanguage.json')).body
);
json.scopeName = 'scenegraph.xml';
json.name = 'scenegraph';
json.fileTypes = ['xml'];
delete json.information_for_contributors;
delete json.version;
//find the CDATA pattern
const pattern = json.patterns.find(x => x.name === 'string.unquoted.cdata.xml');
pattern.name = 'source.brighterscript.embedded.scenegraph';
pattern.patterns = [{
include: 'source.brs'
}];
fsExtra.outputFileSync(`${__dirname}/../syntaxes/scenegraph.tmLanguage.json`, JSON.stringify(json, null, 4));
})().catch(e => console.error(e));


/**
* Do an http GET request
*/
function httpGet(url: string) {
return new Promise<Response>((resolve, reject) => {
request.get(url, (err, response) => {
return err ? reject(err) : resolve(response);
});
});
}
26 changes: 26 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import * as url from 'url';
import { debounce } from 'debounce';
import * as vscode from 'vscode';
import { Cache } from 'brighterscript/dist/Cache';
import * as r from 'postman-request';
import type { Response } from 'request';
import type * as requestType from 'request';
const request = r as typeof requestType;

class Util {
public async readDir(dirPath: string) {
Expand Down Expand Up @@ -381,6 +385,28 @@ class Util {
public escapeRegex(text: string) {
return text?.toString().replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}

/**
* Do an http GET request
*/
public httpGet(url: string) {
return new Promise<Response>((resolve, reject) => {
request.get(url, (err, response) => {
return err ? reject(err) : resolve(response);
});
});
}

/**
* Do an http POST request
*/
public httpPost(url: string) {
return new Promise<Response>((resolve, reject) => {
request.post(url, (err, response) => {
return err ? reject(err) : resolve(response);
});
});
}
}

const util = new Util();
Expand Down

0 comments on commit 2ca89c3

Please sign in to comment.