-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Support macOS and Windows, migrate JavaScript to TypeScript (#32)
- Support macOS and Windows (Close #24 ) - Refactoring - Error handling - TypeScript - Prettier (Close #29 ) - GHA: Add upload-artifact step for test coverage - deps: Install husky
- Loading branch information
Showing
24 changed files
with
924 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": { | ||
} | ||
} | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"ecmaVersion": 2019 | ||
}, | ||
"rules": { | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"bracketSpacing": false, | ||
"arrowParens": "avoid", | ||
"parser": "typescript" | ||
} |
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,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} |
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,18 @@ | ||
import getOS from '../src/get-os'; | ||
|
||
describe('getOS', () => { | ||
test('test', () => { | ||
expect(getOS('linux')).toBe('Linux'); | ||
expect(getOS('darwin')).toBe('macOS'); | ||
expect(getOS('win32')).toBe('Windows'); | ||
}); | ||
|
||
test('test exception', () => { | ||
// expect(() => { | ||
// getOS("win32"); | ||
// }).toThrowError("Windows is not supported"); | ||
expect(() => { | ||
getOS('centos'); | ||
}).toThrowError('centos is not supported'); | ||
}); | ||
}); |
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,22 @@ | ||
import getURL from '../src/get-url'; | ||
|
||
describe('getURL()', () => { | ||
test('test', () => { | ||
const baseURL = | ||
'https://github.com/gohugoio/hugo/releases/download/v0.58.2'; | ||
const urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`; | ||
const urlLinuxExtended = `${baseURL}/hugo_extended_0.58.2_Linux-64bit.tar.gz`; | ||
const urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`; | ||
const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`; | ||
expect(getURL('Linux', 'false', '0.58.2')).toBe(urlLinux); | ||
expect(getURL('Linux', 'true', '0.58.2')).toBe(urlLinuxExtended); | ||
expect(getURL('macOS', 'false', '0.58.2')).toBe(urlMacOS); | ||
expect(getURL('Windows', 'false', '0.58.2')).toBe(urlWindows); | ||
}); | ||
|
||
// test("test exception", () => { | ||
// expect(() => { | ||
// getURL("Linux", "hoge", "0.58.2"); | ||
// }).toThrowError("Invalid input (extended): hoge"); | ||
// }); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
moduleFileExtensions: ['js', 'ts'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
testRunner: 'jest-circus/runner', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
verbose: true | ||
} |
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | ||
|
||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | ||
function getLatestVersion() { | ||
return new Promise((resolve, reject) => { | ||
const xhr = new XMLHttpRequest(); | ||
const url = "https://formulae.brew.sh/api/formula/hugo.json"; | ||
xhr.open("GET", url); | ||
xhr.send(); | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState === 4 && xhr.status === 200) { | ||
const result = JSON.parse(xhr.responseText); | ||
const latestVersion = result.versions.stable; | ||
resolve(latestVersion); | ||
} else if (xhr.readyState === 4 && xhr.status !== 200) { | ||
reject(`ERROR: got status ${xhr.status} of ${url}`); | ||
} | ||
}; | ||
}); | ||
return new Promise((resolve, reject) => { | ||
const xhr = new XMLHttpRequest(); | ||
const url = 'https://formulae.brew.sh/api/formula/hugo.json'; | ||
xhr.open('GET', url); | ||
xhr.send(); | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState === 4 && xhr.status === 200) { | ||
const result = JSON.parse(xhr.responseText); | ||
const latestVersion = result.versions.stable; | ||
resolve(latestVersion); | ||
} | ||
else if (xhr.readyState === 4 && xhr.status !== 200) { | ||
reject(`ERROR: got status ${xhr.status} of ${url}`); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
module.exports = getLatestVersion; | ||
exports.default = getLatestVersion; |
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,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getOS(platform) { | ||
if (platform === 'linux') { | ||
return 'Linux'; | ||
} | ||
else if (platform === 'darwin') { | ||
return 'macOS'; | ||
} | ||
else if (platform === 'win32') { | ||
return 'Windows'; | ||
// throw new Error("Windows is not supported"); | ||
} | ||
else { | ||
throw new Error(`${platform} is not supported`); | ||
} | ||
} | ||
exports.default = getOS; |
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,27 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getURL(os, extended, version) { | ||
const extendedStr = (extended) => { | ||
if (extended === 'true') { | ||
return 'extended_'; | ||
} | ||
else { | ||
return ''; | ||
// } else { | ||
// throw new Error(`Invalid input (extended): ${extended}`); | ||
} | ||
}; | ||
const ext = (os) => { | ||
if (os === 'Windows') { | ||
return 'zip'; | ||
} | ||
else { | ||
return 'tar.gz'; | ||
} | ||
}; | ||
const hugoName = `hugo_${extendedStr(extended)}${version}_${os}-64bit`; | ||
const baseURL = 'https://github.com/gohugoio/hugo/releases/download'; | ||
const url = `${baseURL}/v${version}/${hugoName}.${ext(os)}`; | ||
return url; | ||
} | ||
exports.default = getURL; |
Oops, something went wrong.