Skip to content

Commit

Permalink
chore: remove typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenme committed Nov 11, 2019
1 parent 23dd3fe commit 9ba0488
Show file tree
Hide file tree
Showing 15 changed files with 755 additions and 729 deletions.
28 changes: 2 additions & 26 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
extends: [
'plugin:@typescript-eslint/recommended',
'eslint-config-kentcdodds',
'eslint-config-kentcdodds/jest',
'prettier/@typescript-eslint',
],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
extends: ['eslint-config-kentcdodds', 'eslint-config-kentcdodds/jest'],
rules: {
'no-console': 'off',
'consistent-return': 'off',
'import/extensions': 'off',
},
overrides: [
{
files: ['**/__tests__/**/*.ts'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
],
};
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache:
notifications:
email: false
node_js:
- '8'
- '10'
before_install:
- yarn global add codecov
before_script:
Expand Down
1 change: 0 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
},
},
],
'@babel/preset-typescript',
],
plugins: [
'lodash',
Expand Down
55 changes: 19 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"sideEffects": false,
"main": "dist/github-trending.cjs.js",
"module": "dist/github-trending.esm.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=10.0.0"
},
Expand All @@ -27,7 +26,7 @@
},
"homepage": "https://github.com/huchenme/github-trending-api#readme",
"dependencies": {
"@babel/runtime": "^7.6.2",
"@babel/runtime": "^7.7.2",
"cheerio": "^1.0.0-rc.3",
"cors": "^2.8.5",
"express": "^4.17.1",
Expand All @@ -38,53 +37,40 @@
"opencollective-postinstall": "^2.0.2"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/node": "^7.6.2",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/core": "^7.7.2",
"@babel/node": "^7.7.0",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.6.2",
"@babel/preset-typescript": "^7.6.0",
"@types/cors": "^2.8.6",
"@types/express": "^4.17.1",
"@types/jest": "^24.0.21",
"@types/lodash": "^4.14.141",
"@types/memory-cache": "^0.2.0",
"@types/node-fetch": "^2.5.2",
"@typescript-eslint/eslint-plugin": "^2.3.2",
"@typescript-eslint/parser": "^2.3.2",
"@babel/preset-env": "^7.7.1",
"@babel/preset-typescript": "^7.7.2",
"babel-jest": "^24.9.0",
"babel-plugin-lodash": "^3.3.4",
"doctoc": "^1.4.0",
"eslint": "^6.5.1",
"eslint-config-kentcdodds": "14.5.0",
"husky": "^3.0.8",
"eslint": "^6.6.0",
"eslint-config-kentcdodds": "14.6.1",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lint-staged": "^9.4.1",
"nodemon": "^1.19.3",
"lint-staged": "^9.4.2",
"nodemon": "^1.19.4",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"rollup": "^1.22.0",
"rollup": "^1.26.4",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.2",
"semantic-release": "^15.13.24",
"travis-deploy-once": "^5.0.11",
"typescript": "^3.6.3"
"semantic-release": "^15.13.30",
"travis-deploy-once": "^5.0.11"
},
"scripts": {
"dev": "nodemon --exec babel-node --extensions .ts ./src/server.ts",
"dev": "nodemon --exec babel-node ./src/server.js",
"test": "jest --coverage",
"eslint": "eslint . --ext .ts,.js",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"validate": "npm-run-all eslint type-check test",
"eslint": "eslint .",
"validate": "npm-run-all eslint test",
"prebuild": "rimraf dist",
"build": "npm-run-all build:*",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "NODE_ENV=production rollup -c",
"build": "NODE_ENV=production rollup -c",
"semantic-release": "semantic-release",
"travis-deploy-once": "travis-deploy-once",
"start": "node ./dist/server.cjs.js",
Expand Down Expand Up @@ -113,8 +99,5 @@
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/github-trending-api"
},
"resolutions": {
"@types/node": "^9.6.7"
}
}
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pkg from './package.json';

const external = id => !id.startsWith('.') && !path.isAbsolute(id);

const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const extensions = ['.js', '.jsx'];

const resolvePlugin = resolve({
extensions,
Expand All @@ -21,7 +21,7 @@ const babelPlugin = babel({

export default [
{
input: 'src/index.ts',
input: 'src/index.js',
external,
output: [
{ file: pkg.main, format: 'cjs' },
Expand All @@ -35,7 +35,7 @@ export default [
],
},
{
input: 'src/server.ts',
input: 'src/server.js',
external,
output: [{ file: 'dist/server.cjs.js', format: 'cjs' }],
plugins: [json(), resolvePlugin, babelPlugin],
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions src/__tests__/fetch.ts → src/__tests__/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { fetchRepositories, fetchDevelopers } from '../fetch';

jest.mock('node-fetch');

const mockedFetch = (fetch as unknown) as jest.Mock;

describe('fetchRepositories()', () => {
mockedFetch.mockReturnValueOnce({
fetch.mockReturnValueOnce({
text: jest.fn().mockReturnValue(mockRepositories),
});

Expand All @@ -18,7 +16,7 @@ describe('fetchRepositories()', () => {
});

describe('fetchDevelopers()', () => {
mockedFetch.mockReturnValueOnce({
fetch.mockReturnValueOnce({
text: jest.fn().mockReturnValue(mockDevelopers),
});

Expand Down
21 changes: 8 additions & 13 deletions src/fetch.ts → src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { omitBy, isNil } from 'lodash';

const GITHUB_URL = 'https://github.com';

function omitNil(object): any {
function omitNil(object) {
return omitBy(object, isNil);
}

function removeDefaultAvatarSize(src?: string): string {
function removeDefaultAvatarSize(src) {
/* istanbul ignore if */
if (!src) {
return src;
Expand All @@ -19,23 +19,21 @@ function removeDefaultAvatarSize(src?: string): string {
export async function fetchRepositories({
language = '',
since = 'daily',
} = {}): Promise<any> {
} = {}) {
const url = `${GITHUB_URL}/trending/${language}?since=${since}`;
const data = await fetch(url);
const $ = cheerio.load(await data.text());
return (
$('.Box article.Box-row')
.get()
// eslint-disable-next-line complexity
.map((repo): any => {
.map(repo => {
const $repo = $(repo);
const title = $repo
.find('.h3')
.text()
.trim();
const [username, repoName] = title
.split('/')
.map((v): string => v.trim());
const [username, repoName] = title.split('/').map(v => v.trim());
const relativeUrl = $repo
.find('.h3')
.find('a')
Expand All @@ -49,7 +47,7 @@ export async function fetchRepositories({
const builtBy = $repo
.find('span:contains("Built by")')
.find('[data-hovercard-type="user"]')
.map((i, user): any => {
.map((i, user) => {
const altString = $(user)
.children('img')
.attr('alt');
Expand Down Expand Up @@ -118,17 +116,14 @@ export async function fetchRepositories({
);
}

export async function fetchDevelopers({
language = '',
since = 'daily',
} = {}): Promise<any> {
export async function fetchDevelopers({ language = '', since = 'daily' } = {}) {
const data = await fetch(
`${GITHUB_URL}/trending/developers/${language}?since=${since}`
);
const $ = cheerio.load(await data.text());
return $('.Box article.Box-row')
.get()
.map((dev): any => {
.map(dev => {
const $dev = $(dev);
const relativeUrl = $dev.find('.h3 a').attr('href');
const name = $dev
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import languages from './languages.json';

const SERVER_URL = 'https://github-trending-api.now.sh';

function buildUrl(baseUrl, params = {}): string {
function buildUrl(baseUrl, params = {}) {
const queryString = Object.keys(params)
.filter((key): string | undefined => params[key])
.map((key): string => `${key}=${params[key]}`)
.filter(key => params[key])
.map(key => `${key}=${params[key]}`)
.join('&');

return queryString === '' ? baseUrl : `${baseUrl}?${queryString}`;
}

export async function fetchRepositories(params): Promise<any> {
export async function fetchRepositories(params) {
const res = await fetch(buildUrl(`${SERVER_URL}/repositories`, params));
if (!res.ok) {
throw new Error('Something went wrong');
}
return res.json();
}

export async function fetchDevelopers(params): Promise<any> {
export async function fetchDevelopers(params) {
const res = await fetch(buildUrl(`${SERVER_URL}/developers`, params));
if (!res.ok) {
throw new Error('Something went wrong');
}
return res.json();
}

export async function fetchRandomRepository(params): Promise<any> {
export async function fetchRandomRepository(params) {
const res = await fetch(buildUrl(`${SERVER_URL}/repositories`, params));
if (!res.ok) {
throw new Error('Something went wrong');
Expand All @@ -38,7 +38,7 @@ export async function fetchRandomRepository(params): Promise<any> {
return sample(json);
}

export async function fetchRandomRepositories(size = 1, params): Promise<any> {
export async function fetchRandomRepositories(size = 1, params) {
const res = await fetch(buildUrl(`${SERVER_URL}/repositories`, params));
if (!res.ok) {
throw new Error('Something went wrong');
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9ba0488

Please sign in to comment.