Skip to content

Commit b739de0

Browse files
author
Orta
authored
Merge pull request #39 from microsoft/auto-update-vs-links
Auto update vs links
2 parents 200bf1f + efd47c6 commit b739de0

File tree

6 files changed

+1052
-809
lines changed

6 files changed

+1052
-809
lines changed

gulpfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ gulp.task("styles", function () {
113113
.pipe(reload({stream: true}));
114114
});
115115

116+
// Updates the file: src/_data/urls.json
117+
gulp.task("automate:download_urls", shell.task("node scripts/updateURLs.js"));
118+
116119
gulp.task("handbook-images", function() {
117120
return gulp.src("./TypeScript-Handbook/assets/images/**")
118121
.pipe(changed("site/assets/images"))
@@ -303,5 +306,5 @@ gulp.task("build", ["jekyll:prod", "styles"], function () {});
303306
// Builds your site with the "build" command and then runs all the optimizations on
304307
// it and outputs it to "./site"
305308
gulp.task("publish", ["build"], function () {
306-
gulp.start("html", "copy", "images", "handbook-images", "fonts", "scripts", "cname", "webconfig", "playground");
309+
gulp.start("automate:download_urls", "html", "copy", "images", "handbook-images", "fonts", "scripts", "cname", "webconfig", "playground");
307310
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"dependencies": {},
77
"devDependencies": {
88
"@types/jquery": "^2.0.34",
9+
"@types/node": "^12.7.0",
10+
"axios": "^0.19.0",
911
"browser-sync": "^2.0.0",
1012
"del": "^1.1.1",
1113
"gh-pages": "^2.0.0",

scripts/updateURLs.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// @ts-check
2+
3+
/**
4+
* A script to automatically update the Visual Studio links
5+
* based on the latest *stable* version of TypeScript shipped
6+
* to npm.
7+
*/
8+
9+
10+
const axios = require('axios').default;
11+
const {writeFileSync} = require("fs")
12+
13+
/**
14+
* Gets the NPM package JSON for a module
15+
* @param {string} name
16+
*/
17+
const getLatestNPMPackage = async (name) => {
18+
const packageJSON = await axios({
19+
url: `https://registry.npmjs.org/${name}`
20+
})
21+
22+
return packageJSON.data
23+
}
24+
25+
/**
26+
* Queries the VS markplace for typescript extensions, returns
27+
* only official extensions
28+
*/
29+
const getLatestVSExtensions = async () => {
30+
var headers = {
31+
'Content-Type': 'application/json',
32+
'Accept': 'application/json;api-version=5.2-preview.1;excludeUrls=true',
33+
'Host': 'marketplace.visualstudio.com',
34+
'Origin': 'https://marketplace.visualstudio.com',
35+
'Referer': 'https://marketplace.visualstudio.com/search?term=typescript&target=VS&category=All%20categories&vsVersion=vs2019&sortBy=Relevance',
36+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15',
37+
'Content-Length': '1082',
38+
'Connection': 'keep-alive',
39+
'X-TFS-Session': 'e16c1b5b-850f-42ee-ab7c-519c79f6e356',
40+
'X-Requested-With': 'XMLHttpRequest',
41+
'X-VSS-ReauthenticationAction': 'Suppress',
42+
};
43+
44+
const query = (name) =>
45+
`{"assetTypes":["Microsoft.VisualStudio.Services.Icons.Default","Microsoft.VisualStudio.Services.Icons.Branding","Microsoft.VisualStudio.Services.Icons.Small"],"filters":[{"criteria":[{"filterType":8,"value":"Microsoft.VisualStudio.Ide"},{"filterType":10,"value":"${name}"},{"filterType":12,"value":"37888"}],"direction":2,"pageSize":54,"pageNumber":1,"sortBy":0,"sortOrder":0,"pagingToken":null}],"flags":870}`
46+
47+
48+
const extensionSearchResults = await axios({
49+
url: 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery',
50+
method: 'POST',
51+
headers: headers,
52+
data: query("typescript")
53+
})
54+
55+
if (!extensionSearchResults.data || !extensionSearchResults.data.results) {
56+
throw new Error("Got a bad response from VS marketplace")
57+
}
58+
59+
const extensions = extensionSearchResults.data.results[0].extensions
60+
const officialExtensions = extensions.filter(e => e.publisher.publisherId === "4f0355d2-4a53-4ab1-a8ea-507f4a333a6f")
61+
return officialExtensions
62+
}
63+
64+
const go = async () => {
65+
// curl https://registry.npmjs.org/typescript | jq
66+
console.log("Grabbing the TypeScript package from NPM, this takes about 10-15s")
67+
const tsPackage = await getLatestNPMPackage("typescript")
68+
const latest = tsPackage["dist-tags"].latest
69+
70+
console.log(`Grabbing the VS TypeScript extension for ${latest} from the marketplace`)
71+
const extensions = await getLatestVSExtensions()
72+
const currentExtension = extensions.find(e => e.versions[0].version === latest)
73+
74+
// @ts-ignore
75+
const currentURLs = require("../src/_data/urls")
76+
77+
if (currentExtension) {
78+
const extensionURL = `https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.${currentExtension.extensionName}`
79+
currentURLs.vs2017_download = extensionURL
80+
currentURLs.vs2019_download = extensionURL
81+
}
82+
83+
writeFileSync("src/_data/urls.json", JSON.stringify(currentURLs, null, " "))
84+
console.log(`Updated src/_data/urls.json`)
85+
}
86+
87+
go()

src/_data/urls.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"vs2017_download": "https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.typescript-353",
3+
"vs2019_download": "https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.typescript-353",
4+
"vscode_download": "https://code.visualstudio.com",
5+
"sublime_ts_download": "https://github.com/Microsoft/TypeScript-Sublime-Plugin",
6+
"atom_ts_download": "https://atom.io/packages/atom-typescript",
7+
"eclipse_ts_download": "https://marketplace.eclipse.org/content/codemix-3",
8+
"webstorm_download": "https://www.jetbrains.com/webstorm/",
9+
"vim_ts_download": "https://github.com/Microsoft/TypeScript/wiki/TypeScript-Editor-Support#vim",
10+
"emacs_ts_download": "https://github.com/ananthakumaran/tide",
11+
"ts_github": "https://github.com/Microsoft/TypeScript",
12+
"ts_github_issues": "https://github.com/Microsoft/TypeScript/issues",
13+
"ts_spec_markdown": "https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md",
14+
"ts_spec_docx": "https://github.com/Microsoft/TypeScript/blob/master/doc/TypeScript%20Language%20Specification.docx?raw=true",
15+
"ts_spec_pdf": "https://github.com/Microsoft/TypeScript/blob/master/doc/TypeScript%20Language%20Specification.pdf?raw=true",
16+
"definitelytyped_github": "https://github.com/DefinitelyTyped/DefinitelyTyped",
17+
"ts_blog": "http://blogs.msdn.com/b/typescript/",
18+
"ts_stackoverflow_tagged": "https://stackoverflow.com/questions/tagged/typescript",
19+
"ts_twitter": "https://twitter.com/typescript/",
20+
"ts_twitter_search": "https://twitter.com/search?q=%23typescript",
21+
"landing_page_video": "http://video.ch9.ms/ch9/4ae3/062c336d-9cf0-498f-ae9a-582b87954ae3/B881_mid.mp4"
22+
}

src/_data/urls.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)