Skip to content

Commit

Permalink
started ts conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 31, 2017
1 parent 8411caa commit c0b1aca
Show file tree
Hide file tree
Showing 16 changed files with 775 additions and 796 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
defaults: &defaults
working_directory: /cli
docker:
- image: node:8.4
- image: node:9
environment: &env
NPM_CONFIG_REGISTRY: https://cli-npm.heroku.com

Expand Down
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

17 changes: 0 additions & 17 deletions .eslintrc

This file was deleted.

18 changes: 0 additions & 18 deletions .flowconfig

This file was deleted.

8 changes: 8 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"**/*.ts": [
"prettier --write",
"git add",
"jest --bail --findRelatedTests"
]
}

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
nodejs_version: "8"
nodejs_version: "9"
cache:
- "%LOCALAPPDATA%\\Yarn"

Expand Down
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
setupTestFrameworkScriptFile: "./test/init.ts",
mapCoverage: true,
moduleFileExtensions: ['ts', 'js'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': '<rootDir>/node_modules/ts-jest/preprocessor.js',
},
}
50 changes: 16 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"bin": "heroku",
"userPlugins": true,
"dirname": "heroku",
"node": "9.2.0",
"node": "9.3.0",
"defaultCommand": "dashboard",
"legacyConverter": "./lib/legacy",
"npmRegistry": "https://cli-npm.heroku.com",
"hooks": {
"prerun": "./lib/hooks/prerun/analytics",
"plugins:parse": "./lib/hooks/plugins/parse",
"update": [
"./lib/hooks/update/analytics",
"./lib/hooks/update/completions"
Expand Down Expand Up @@ -46,11 +46,7 @@
]
},
"dependencies": {
"cli-engine": "4.6.21",
"cli-engine-command": "9.0.6",
"cli-engine-config": "3.4.0",
"cli-engine-heroku": "5.0.4",
"cli-ux": "2.0.20",
"cli-ux": "2.0.7",
"debug": "3.1.0",
"fs-extra": "5.0.0",
"heroku-apps": "2.4.19",
Expand All @@ -76,24 +72,16 @@
},
"devDependencies": {
"@heroku/heroku-cli-dev-center-generator": "1.1.7",
"babel-cli": "6.26.0",
"babel-eslint": "8.0.2",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "6.26.0",
"babel-preset-flow": "6.23.0",
"eslint": "4.12.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jest": "21.3.2",
"eslint-plugin-node": "5.2.1",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-standard": "3.0.1",
"flow-bin": "0.56.0",
"@types/fs-extra": "5.0.0",
"@types/node": "8.5.1",
"del-cli": "1.1.0",
"husky": "0.14.3",
"jest": "21.2.1",
"nock": "9.1.3"
"lint-staged": "6.0.0",
"nock": "9.1.4",
"prettier": "1.9.2",
"ts-jest": "21.2.4",
"typescript": "2.6.2"
},
"engineStrict": true,
"engines": {
Expand All @@ -104,24 +92,18 @@
"bin"
],
"homepage": "https://cli.heroku.com",
"jest": {
"modulePathIgnorePatterns": [
"tmp"
]
},
"keywords": [
"heroku",
"heroku-cli-plugin"
],
"license": "ISC",
"repository": "https://github.com/heroku/cli",
"repository": "heroku/cli",
"scripts": {
"build": "babel src -d lib --ignore '*.test.js'",
"clean": "rimraf lib tmp dist",
"download": "./scripts/download-yarn",
"lint": "./scripts/test/lint",
"precommit": "./scripts/precommit",
"prepare": "npm run build",
"posttest": "prettier -l 'src/**/*.ts'",
"precommit": "./scripts/precommit && lint-staged",
"prepare": "del-cli lib && tsc && del-cli \"lib/**/*.test.+(d.ts|js)\"",
"pretest": "tsc",
"test": "./scripts/test/all"
}
}
2 changes: 1 addition & 1 deletion scripts/build/workspace
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source ./scripts/_init
set -x

function build () {
setarch $ARCH
setarch "$ARCH"
# setup workspace
o="$WORKSPACE_DIR"
rm -rf "${o}"
Expand Down
2 changes: 0 additions & 2 deletions scripts/test/lint
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ if [ -x "$(command -v shellcheck)" ]; then
else
echoerr "install shellcheck to lint the scripts"
fi

npx eslint .
30 changes: 18 additions & 12 deletions src/analytics.js → src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// @flow

import fs from 'fs-extra'
import type {Config} from 'cli-engine-config'
import * as fs from 'fs-extra'
import {Config} from 'cli-engine-config'
import {HTTP} from 'http-call'
import Netrc from 'netrc-parser'
import path from 'path'
import vars from 'cli-engine-heroku/lib/vars'
import type {Command} from 'cli-engine-command'
import * as path from 'path'
import {vars} from 'cli-engine-heroku/lib/vars'
import {ICommand} from 'cli-engine-config'

const Netrc = require('netrc-parser')

const debug = require('debug')('heroku:analytics')

type AnalyticsJSONCommand = {
command: string,
completion: number,
version: string,
plugin: string,
plugin_version: string,
os: string,
shell: string,
Expand All @@ -29,11 +29,13 @@ type AnalyticsJSON = {
type AnalyticsJSONPost = {
schema: 1,
commands: AnalyticsJSONCommand[],
install: string
cli: string
user: string
}

type RecordOpts = {
Command: Class<Command<*>>,
Command: ICommand,
argv: string[],
}

Expand Down Expand Up @@ -110,15 +112,16 @@ export default class AnalyticsCommand {
get analyticsPath (): string { return path.join(this.config.cacheDir, 'analytics.json') }

get usingHerokuAPIKey (): boolean {
return !!(process.env['HEROKU_API_KEY'] && process.env['HEROKU_API_KEY'].length > 0)
const k = process.env.HEROKU_API_KEY
return !!(k && k.length > 0)
}

get netrcLogin (): ?string {
get netrcLogin (): string | undefined {
let netrc = new Netrc()
return netrc.machines[vars.apiHost].login
}

get user (): ?string {
get user (): string | undefined {
if (this.config.skipAnalytics || this.usingHerokuAPIKey) return
return this.netrcLogin
}
Expand All @@ -144,8 +147,11 @@ export default class AnalyticsCommand {

async _acAnalytics (): Promise<number> {
let meta = {
// @ts-ignore
cmd: fs.exists(this._acAnalyticsPath('command')),
// @ts-ignore
flag: fs.exists(this._acAnalyticsPath('flag')),
// @ts-ignore
value: fs.exists(this._acAnalyticsPath('value'))
}
let score = 0
Expand Down
17 changes: 17 additions & 0 deletions src/hooks/plugins/parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Config} from 'cli-engine-config'
import {PluginsParseHookOptions} from 'cli-engine/lib/hooks'

function getID (c: any): string {
let id = []
if (c.topic) id.push(c.topic)
if (c.command) id.push(c.command)
return id.join(':')
}

module.exports = (_: Config, opts: PluginsParseHookOptions) => {
const m = opts.module
m.commands = m.commands.map((c: any) => {
if (!c.id) c.id = getID(c)
return c
})
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// @flow

import type {Config} from 'cli-engine-config'
import type {PreRun} from 'cli-engine/lib/hooks'
import {Config} from 'cli-engine-config'
import {PreRunOptions} from 'cli-engine/lib/hooks'

const debug = require('debug')('heroku:analytics')

async function run (config: Config, opts: PreRun) {
async function run (config: Config, opts: PreRunOptions) {
try {
const Analytics = require('../../analytics').default
const analytics = new Analytics(config)
Expand Down
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"strict": true,
"alwaysStrict": true,
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
"noUnusedLocals": true,
"noUnusedParameters": true,
"target": "esnext"
},
"include": [
"src/**/*"
]
}
Loading

0 comments on commit c0b1aca

Please sign in to comment.