Skip to content

Auto update vs links #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ gulp.task("styles", function () {
.pipe(reload({stream: true}));
});

// Updates the file: src/_data/urls.json
gulp.task("automate:download_urls", shell.task("node scripts/updateURLs.js"));

gulp.task("handbook-images", function() {
return gulp.src("./TypeScript-Handbook/assets/images/**")
.pipe(changed("site/assets/images"))
Expand Down Expand Up @@ -303,5 +306,5 @@ gulp.task("build", ["jekyll:prod", "styles"], function () {});
// Builds your site with the "build" command and then runs all the optimizations on
// it and outputs it to "./site"
gulp.task("publish", ["build"], function () {
gulp.start("html", "copy", "images", "handbook-images", "fonts", "scripts", "cname", "webconfig", "playground");
gulp.start("automate:download_urls", "html", "copy", "images", "handbook-images", "fonts", "scripts", "cname", "webconfig", "playground");
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"dependencies": {},
"devDependencies": {
"@types/jquery": "^2.0.34",
"@types/node": "^12.7.0",
"axios": "^0.19.0",
"browser-sync": "^2.0.0",
"del": "^1.1.1",
"gh-pages": "^2.0.0",
Expand Down
87 changes: 87 additions & 0 deletions scripts/updateURLs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// @ts-check

/**
* A script to automatically update the Visual Studio links
* based on the latest *stable* version of TypeScript shipped
* to npm.
*/


const axios = require('axios').default;
const {writeFileSync} = require("fs")

/**
* Gets the NPM package JSON for a module
* @param {string} name
*/
const getLatestNPMPackage = async (name) => {
const packageJSON = await axios({
url: `https://registry.npmjs.org/${name}`
})

return packageJSON.data
}

/**
* Queries the VS markplace for typescript extensions, returns
* only official extensions
*/
const getLatestVSExtensions = async () => {
var headers = {
'Content-Type': 'application/json',
'Accept': 'application/json;api-version=5.2-preview.1;excludeUrls=true',
'Host': 'marketplace.visualstudio.com',
'Origin': 'https://marketplace.visualstudio.com',
'Referer': 'https://marketplace.visualstudio.com/search?term=typescript&target=VS&category=All%20categories&vsVersion=vs2019&sortBy=Relevance',
'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',
'Content-Length': '1082',
'Connection': 'keep-alive',
'X-TFS-Session': 'e16c1b5b-850f-42ee-ab7c-519c79f6e356',
'X-Requested-With': 'XMLHttpRequest',
'X-VSS-ReauthenticationAction': 'Suppress',
};

const query = (name) =>
`{"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}`


const extensionSearchResults = await axios({
url: 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery',
method: 'POST',
headers: headers,
data: query("typescript")
})

if (!extensionSearchResults.data || !extensionSearchResults.data.results) {
throw new Error("Got a bad response from VS marketplace")
}

const extensions = extensionSearchResults.data.results[0].extensions
const officialExtensions = extensions.filter(e => e.publisher.publisherId === "4f0355d2-4a53-4ab1-a8ea-507f4a333a6f")
return officialExtensions
}

const go = async () => {
// curl https://registry.npmjs.org/typescript | jq
console.log("Grabbing the TypeScript package from NPM, this takes about 10-15s")
const tsPackage = await getLatestNPMPackage("typescript")
const latest = tsPackage["dist-tags"].latest

console.log(`Grabbing the VS TypeScript extension for ${latest} from the marketplace`)
const extensions = await getLatestVSExtensions()
const currentExtension = extensions.find(e => e.versions[0].version === latest)

// @ts-ignore
const currentURLs = require("../src/_data/urls")

if (currentExtension) {
const extensionURL = `https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.${currentExtension.extensionName}`
currentURLs.vs2017_download = extensionURL
currentURLs.vs2019_download = extensionURL
}

writeFileSync("src/_data/urls.json", JSON.stringify(currentURLs, null, " "))
console.log(`Updated src/_data/urls.json`)
}

go()
22 changes: 22 additions & 0 deletions src/_data/urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"vs2017_download": "https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.typescript-353",
"vs2019_download": "https://marketplace.visualstudio.com/items?itemName=TypeScriptTeam.typescript-353",
"vscode_download": "https://code.visualstudio.com",
"sublime_ts_download": "https://github.com/Microsoft/TypeScript-Sublime-Plugin",
"atom_ts_download": "https://atom.io/packages/atom-typescript",
"eclipse_ts_download": "https://marketplace.eclipse.org/content/codemix-3",
"webstorm_download": "https://www.jetbrains.com/webstorm/",
"vim_ts_download": "https://github.com/Microsoft/TypeScript/wiki/TypeScript-Editor-Support#vim",
"emacs_ts_download": "https://github.com/ananthakumaran/tide",
"ts_github": "https://github.com/Microsoft/TypeScript",
"ts_github_issues": "https://github.com/Microsoft/TypeScript/issues",
"ts_spec_markdown": "https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md",
"ts_spec_docx": "https://github.com/Microsoft/TypeScript/blob/master/doc/TypeScript%20Language%20Specification.docx?raw=true",
"ts_spec_pdf": "https://github.com/Microsoft/TypeScript/blob/master/doc/TypeScript%20Language%20Specification.pdf?raw=true",
"definitelytyped_github": "https://github.com/DefinitelyTyped/DefinitelyTyped",
"ts_blog": "http://blogs.msdn.com/b/typescript/",
"ts_stackoverflow_tagged": "https://stackoverflow.com/questions/tagged/typescript",
"ts_twitter": "https://twitter.com/typescript/",
"ts_twitter_search": "https://twitter.com/search?q=%23typescript",
"landing_page_video": "http://video.ch9.ms/ch9/4ae3/062c336d-9cf0-498f-ae9a-582b87954ae3/B881_mid.mp4"
}
26 changes: 0 additions & 26 deletions src/_data/urls.yml

This file was deleted.

Loading