Skip to content

Commit

Permalink
Merge pull request #177 from terascope/switch-to-ts
Browse files Browse the repository at this point in the history
Migrate to typescript to reduce the dependencies
  • Loading branch information
peterdemartini authored Sep 30, 2021
2 parents b6035e8 + 44a533c commit 5019b77
Show file tree
Hide file tree
Showing 44 changed files with 3,241 additions and 2,925 deletions.
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.{js,ts,jsx,tsx,json,md}]
indent_style = space
indent_size = 4

[*.{yml,yaml}]
indent_style = space
indent_size = 2

[*.md]
max_line_length = off
11 changes: 1 addition & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"parser": "babel-eslint",
"extends": "airbnb/base",
"env": {
"mocha": true,
"node": true
},
"rules": {
"comma-dangle": 0,
"no-console": 0
}
"extends": "@terascope"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.log
node_modules
lib
dist
tmp
coverage
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
dist: bionic
language: node_js
node_js:
- '10'
- '12'
- '14'
branches:
only:
- master
- "/^v\\d+\\.\\d+\\.\\d+/"
- master
- "/^v\\d+\\.\\d+\\.\\d+/"
install:
- yarn
- yarn
before_script:
- yarn build
script:
- stty cols 80
- yarn test:cov
- yarn build:lib
- stty cols 80
- yarn test
after_script:
- yarn lint
after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
deploy:
provider: npm
email: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ yarn add @terascope/fetch-github-release
### Usage

```javascript
const downloadRelease = require('@terascope/fetch-github-release');
const { downloadRelease } = require('@terascope/fetch-github-release');

const user = 'some user';
const repo = 'some repo';
Expand Down
2 changes: 1 addition & 1 deletion bin/fetch-github-release
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

var path = require('path');
var fs = require('fs');
require(path.join(path.dirname(fs.realpathSync(__filename)), '../lib/cli'));
require(path.join(path.dirname(fs.realpathSync(__filename)), '../dist/src/cli'));
54 changes: 0 additions & 54 deletions index.d.ts

This file was deleted.

30 changes: 30 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

module.exports = {
verbose: true,
testEnvironment: 'node',
setupFilesAfterEnv: ['jest-extended'],
collectCoverage: true,
coverageReporters: ['json', 'lcov', 'text', 'html'],
coverageDirectory: 'coverage',
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/**/coverage/**',
'!<rootDir>/**/*.d.ts',
'!<rootDir>/**/dist/**',
'!<rootDir>/**/coverage/**'
],
testMatch: [
'<rootDir>/test/**/*-spec.{ts,js}',
'<rootDir>/test/*-spec.{ts,js}',
],
preset: 'ts-jest',
globals: {
'ts-jest': {
tsconfig: './tsconfig.json',
diagnostics: true,
},
ignoreDirectories: ['dist'],
availableExtensions: ['.js', '.ts']
}
};
61 changes: 30 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
"publishConfig": {
"access": "public"
},
"version": "0.7.9",
"version": "0.8.0",
"description": "Download a specific release from github",
"files": [
"bin/*",
"dist/src/**/*"
],
"main": "lib/index.js",
"typings": "index.d.ts",
"typings": "dist/src/index.d.ts",
"scripts": {
"test": "mocha --require @babel/polyfill --require @babel/register --require should --recursive",
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive --require should --require should",
"lint": "eslint src test",
"check": "npm run lint && npm run test",
"build:lib": "babel src --out-dir lib",
"build": " tsc --project tsconfig.json",
"build:watch": "yarn build --watch",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"lint:fix": "yarn lint --fix",
"setup": "yarn && yarn build",
"test": "jest",
"test:cov": "jest --collectCoverage",
"test:watch": "jest --coverage=false --notify --watch --onlyChanged",
"test:debug": "env DEBUG=\"${DEBUG:-*teraslice*}\" jest --detectOpenHandles --coverage=false --runInBand",
"check": "yarn run lint && yarn run test",
"clean": "rimraf lib coverage",
"preversion": "npm run clean && npm run check",
"version": "npm run build:lib",
"postversion": "git push && git push --tags && npm run clean",
"prepublishOnly": "npm run clean && npm run build:lib"
"prepublishOnly": "yarn run clean && yarn run build"
},
"bin": {
"fetch-github-release": "bin/fetch-github-release"
Expand All @@ -37,35 +43,28 @@
"url": "https://github.com/terascope/fetch-github-release/issues"
},
"dependencies": {
"commander": "^7.0.0",
"core-js": "^3.6.5",
"extract-zip": "^2.0.1",
"gauge": "^3.0.0",
"got": "^11.4.0",
"multi-progress": "^4.0.0",
"progress": "^2.0.3",
"regenerator-runtime": "^0.13.5"
"yargs": "^17.2.1"
},
"devDependencies": {
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/node": "^7.10.4",
"@babel/polyfill": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/register": "^7.10.4",
"babel-eslint": "^10.1.0",
"eslint": "^5.8.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"isparta": "^4.0.0",
"mocha": "^8.0.1",
"@terascope/eslint-config": "^0.6.1",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.2",
"@types/stream-buffers": "^3.0.4",
"@types/tmp": "^0.2.1",
"eslint": "^7.32.0",
"jest": "^27.2.4",
"jest-extended": "^0.11.5",
"nock": "^13.0.2",
"node-notifier": "^10.0.0",
"rimraf": "^3.0.0",
"should": "^13.2.3",
"sinon": "^11.1.1",
"stream-buffers": "^3.0.0",
"tmp": "0.2.1"
"tmp": "0.2.1",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
}
}
36 changes: 0 additions & 36 deletions src/cli.js

This file was deleted.

64 changes: 64 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import yargs from 'yargs';
import { downloadRelease } from './downloadRelease';
import { version } from '../package.json';
import { GithubRelease, GithubReleaseAsset } from './interfaces';

const command = yargs
.option('prerelease', {
description: 'download prerelease',
type: 'boolean',
alias: 'p',
default: false
})
.option('search', {
description: 'filter assets name, this can be regex',
alias: 's',
type: 'string',
})
.option('quiet', {
description: 'don\'t log to console',
type: 'boolean',
alias: 'q',
default: false
})
.option('zipped', {
description: 'don\'t extract zip files',
type: 'boolean',
alias: 'z',
default: false
})
.positional('user', {
description: 'The Github user',
type: 'string',
})
.requiresArg('user')
.positional('repo', {
description: 'The Github repo',
type: 'string',
})
.requiresArg('repo')
.positional('outputdir', {
description: 'The directory to download the assets to',
type: 'string',
default: process.cwd()
})
.version(version)
.argv;

const { user, repo, outputdir } = command;

function filterRelease(release: GithubRelease): boolean {
return release.draft === false && release.prerelease === !!command.prerelease;
}

function filterAsset(asset: GithubReleaseAsset): boolean {
if (!command.search) {
return true;
}

return new RegExp(command.search).test(asset.name);
}

downloadRelease(user!, repo!, outputdir, filterRelease, filterAsset,
!!command.zipped, !!command.quiet)
.catch((err) => console.error(err.message));
Loading

0 comments on commit 5019b77

Please sign in to comment.