This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(package): update apis for package and apis version
- Loading branch information
Kamontat Chantrachirathumrong
committed
Dec 28, 2018
1 parent
d91b284
commit e25f73b
Showing
9 changed files
with
196 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const { | ||
ParseParameters, | ||
GenObj | ||
} = require('../../lib/parseUrl') | ||
|
||
const { | ||
FetchUrl, | ||
GenerateGithubLink | ||
} = require("../../lib/ghLink") | ||
|
||
exports.handler = function (event, _, callback) { | ||
const result = ParseParameters(event, | ||
GenObj("type", ["all", "name", "description", "author", "version", "license", "dependencies", "devDependencies", "repository", "scripts"], ["all"]), | ||
GenObj("format", ["json", "text", "text-head"]), | ||
GenObj("repo", ["apis", "web", "docs"]), | ||
GenObj("branch", ["master", "dev"])); | ||
|
||
let repo = result.repo | ||
if (repo === "web") repo = "website" | ||
else if (repo === "docs") repo = "documents" | ||
|
||
const url = GenerateGithubLink("package.json", { | ||
repo, | ||
branch: result.branch, | ||
noPrefix: true | ||
}) | ||
|
||
FetchUrl(url).then(pkg => { | ||
// case all | ||
if (result.type.includes("all")) return callback(undefined, { | ||
statusCode: 200, | ||
headers: { | ||
"Content-Type": result.format === "json" ? "application/json" : "text/plain", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "*" | ||
}, | ||
body: JSON.stringify(pkg) | ||
}); | ||
|
||
let response = result.type.reduce((p, c) => { | ||
p[c] = pkg[c]; | ||
return p | ||
}, {}) | ||
|
||
// transform to json | ||
if (result.format === "text" || result.format === "text-head") { | ||
response = Object.keys(response).reduce((p, key) => { | ||
const v = result.format === "text" ? response[key] : `${key}: ${response[key]}` | ||
|
||
if (p) | ||
return `${p}\n${v}` | ||
else return v | ||
}, undefined) | ||
} | ||
|
||
callback(undefined, { | ||
statusCode: 200, | ||
headers: { | ||
"Content-Type": result.format === "json" ? "application/json" : "text/plain", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "*" | ||
}, | ||
body: result.format === "json" ? JSON.stringify(response) : response | ||
}); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const pkg = require("../../package.json") | ||
|
||
const { | ||
ParseParameters, | ||
GenObj | ||
} = require('../../lib/parseUrl') | ||
|
||
exports.handler = function (event, _, callback) { | ||
const result = ParseParameters(event, | ||
GenObj("format", ["json", "text"])) | ||
|
||
callback(undefined, { | ||
statusCode: 200, | ||
headers: { | ||
"Content-Type": result.format === "json" ? "application/json" : "text/plain", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "*" | ||
}, | ||
body: result.format === "json" ? JSON.stringify({ | ||
version: pkg.version | ||
}) : pkg.version | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters