Skip to content

Commit

Permalink
fix: ran generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 30, 2018
1 parent e662815 commit abb6601
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 2,215 deletions.
14 changes: 3 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ jobs:
- v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}-{{checksum "yarn.lock"}}
- v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}-
- v0-yarn-{{checksum ".circleci/config.yml"}}-master-
- run: .circleci/setup_git
- run: .circleci/yarn
- run: yarn test
- run: curl -s https://codecov.io/bash | bash
- run: .circleci/test
- store_test_results: &store_test_results
path: ~/cli/reports
- save_cache: &save_cache
Expand All @@ -31,20 +28,15 @@ jobs:
steps:
- checkout
- restore_cache: *restore_cache
- run: .circleci/setup_git
- run: .circleci/yarn
- run: yarn test
- run: curl -s https://codecov.io/bash | bash
- run: .circleci/test
- store_test_results: *store_test_results
release:
<<: *test
steps:
- add_ssh_keys
- checkout
- restore_cache: *restore_cache
- run: .circleci/setup_git
- run: .circleci/yarn
- run: yarn exec nps release
- run: .circleci/release

workflows:
version: 2
Expand Down
22 changes: 0 additions & 22 deletions .circleci/greenkeeper

This file was deleted.

11 changes: 11 additions & 0 deletions .circleci/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -ex

.circleci/setup_git

PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH

yarn global add @dxcli/semantic-release@1 semantic-release@12
yarn install --frozen-lockfile
semantic-release -e @dxcli/semantic-release
7 changes: 7 additions & 0 deletions .circleci/yarn → .circleci/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -ex

.circleci/setup_git

PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH

CLI_ENGINE_UTIL_YARN_ARGS="--frozen-lockfile"
Expand All @@ -20,3 +22,8 @@ yarn install $CLI_ENGINE_UTIL_YARN_ARGS
if [[ "$CLI_ENGINE_GREENKEEPER_BRANCH" == 1 ]]; then
greenkeeper-lockfile-upload
fi

yarn add -D nyc @dxcli/nyc-config
yarn test

curl -s https://codecov.io/bash | bash
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install:
- git submodule update --init --recursive
- git config --global user.email "dxcli@example.com"
- git config --global user.name "dxcli"
- yarn
- yarn add -D nyc @dxcli/nyc-config
test_script:
- yarn test
after_test:
Expand Down
12 changes: 6 additions & 6 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const linters = {
tslint: script('tslint -p test', 'lint ts files'),
}

let test = 'mocha --forbid-only "test/**/*.test.ts"'
let mocha = 'mocha --forbid-only "test/**/*.test.ts"'
if (process.env.CI) {
if (process.env.CIRCLECI) {
// add mocha junit reporter
test = crossEnv(`MOCHA_FILE=reports/mocha.xml ${test} --reporter mocha-junit-reporter`)
mocha = crossEnv(`MOCHA_FILE=reports/mocha.xml ${mocha} --reporter mocha-junit-reporter`)
// add eslint reporter
linters.eslint.script = `${linters.eslint.script} --format junit --output-file reports/eslint.xml`
// add tslint reporter
Expand All @@ -32,12 +32,12 @@ if (process.env.CI) {
// add code coverage reporting with nyc
const nyc = 'nyc --nycrc-path node_modules/@dxcli/nyc-config/.nycrc'
const nycReport = `${nyc} report --reporter text-lcov > coverage.lcov`
test = series(`${nyc} ${test}`, nycReport)
mocha = series(`${nyc} ${mocha}`, nycReport)
}

test = concurrent({
let test = concurrent({
...linters,
test: series('nps build', test),
test: series('nps build', mocha),
})

if (process.env.CI) test = series(mkdirp('reports'), test)
Expand All @@ -48,6 +48,6 @@ module.exports = {
build: series('rm -rf lib', 'tsc'),
lint: concurrent(linters),
test,
release: 'semantic-release -e @dxcli/semantic-release',
mocha,
},
}
31 changes: 19 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/jdxcode/plugins/issues",
"dependencies": {
"@dxcli/command": "^0.1.23",
"@dxcli/config": "^0.1.28",
"@dxcli/loader": "^0.2.9",
"@dxcli/manifest-file": "^0.0.4",
"@dxcli/parser": "^0.0.5",
"@dxcli/command": "^0.2.6",
"@dxcli/config": "^0.1.39",
"@dxcli/manifest-file": "^0.1.0",
"@heroku-cli/color": "^1.1.1",
"cli-ux": "^3.2.2",
"cli-ux": "^3.3.8",
"debug": "^3.1.0",
"fs-extra": "^5.0.0",
"lodash": "^4.17.4",
Expand All @@ -20,14 +18,23 @@
"yarn": "^1.3.2"
},
"devDependencies": {
"@dxcli/dev": "^2.0.13",
"@dxcli/engine": "^0.1.13",
"@dxcli/semantic-release": "^0.3.3",
"@dxcli/test": "^0.9.17",
"@dxcli/tslint": "^0.0.24",
"@commitlint/cli": "^6.0.2",
"@commitlint/config-conventional": "^6.0.2",
"@dxcli/engine": "^0.1.20",
"@dxcli/test": "^0.9.19",
"@dxcli/tslint": "^0.1.3",
"@types/chai": "^4.1.2",
"@types/fs-extra": "^5.0.0",
"@types/lodash": "^4.14.98",
"@types/mocha": "^2.2.47",
"@types/nock": "^9.1.2",
"@types/node": "^9.4.0",
"@types/node-notifier": "^0.0.28",
"@types/read-pkg": "^3.0.0",
"@types/supports-color": "^3.1.0",
"chai": "^4.1.2",
"eslint": "^4.16.0",
"eslint-config-dxcli": "^1.2.1",
"husky": "^0.14.3",
"mocha": "^5.0.0",
"mocha-junit-reporter": "^1.17.0",
Expand All @@ -53,7 +60,7 @@
"license": "MIT",
"repository": "dxcli/plugins",
"scripts": {
"commitmsg": "dxcli-commitlint",
"commitmsg": "commitlint -x @commitlint/config-conventional -e $GIT_PARAMS",
"precommit": "nps lint -l warn",
"prepublishOnly": "nps build",
"test": "nps test -l warn"
Expand Down
11 changes: 9 additions & 2 deletions src/commands/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import color from '@heroku-cli/color'
import cli from 'cli-ux'
import * as _ from 'lodash'

import Plugins from '../../plugins'

let examplePlugins = {
'heroku-ci': {version: '1.8.0'},
'heroku-cli-status': {version: '3.0.10', type: 'link'},
Expand All @@ -19,17 +21,22 @@ if (g.config) {
}
const examplePluginsHelp = Object.entries(examplePlugins).map(([name, p]: [string, any]) => ` ${name} ${p.version}`)

export default class Plugins extends Command {
static flags: flags.Input = {
export default class PluginsIndex extends Command {
static flags: flags.Input<PluginsIndex['flags']> = {
core: flags.boolean({description: 'show core plugins'})
}
static description = 'list installed plugins'
static help = `Example:
$ ${bin} plugins
${examplePluginsHelp.join('\n')}
`
plugins: Plugins
flags: {
core: boolean
}

async run() {
this.plugins = new Plugins(this.config)
let plugins = this.config.engine!.plugins
plugins = plugins.filter(p => p.type !== 'builtin' && p.type !== 'main')
_.sortBy(plugins, 'name')
Expand Down
11 changes: 3 additions & 8 deletions src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import {IConfig, IPlugin} from '@dxcli/config'

import Plugins from './plugins'

export default async function (config: IConfig) {
try {
const plugins = new Plugins(config)
return await plugins.load()
} catch (err) {
const cli = require('cli-ux').scope('loading plugins')
cli.warn(err)
}
export default async function (config: IConfig, cb: any) {
const plugins = new Plugins(config)
await Promise.all((await plugins.list()).map((([n]) => cb({name: n, root: plugins.userPluginPath(n), type: 'user'}))))
}

export {IPlugin}
32 changes: 11 additions & 21 deletions src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {IConfig, IPlugin} from '@dxcli/config'
import {load} from '@dxcli/loader'
import {IConfig, read} from '@dxcli/config'
import {cli} from 'cli-ux'
import * as fs from 'fs-extra'
import * as _ from 'lodash'
import * as path from 'path'

import Manifest from './manifest'
Expand All @@ -29,35 +27,30 @@ export default class Plugins {
cli.info(`Installing plugin ${name}${tag === 'latest' ? '' : '@' + tag}`)
await this.createPJSON()
await this.yarn.exec(['add', `${name}@${tag}`])
let plugin = await this.loadPlugin(name, tag)
if (!plugin.commands.length) throw new Error('no commands found in plugin')
await this.loadPlugin(name, tag)
// if (!plugin.commands.length) throw new Error('no commands found in plugin')
await this.manifest.add(name, tag)
} catch (err) {
await this.uninstall(name).catch(err => this.debug(err))
throw err
}
}

async load(): Promise<IPlugin[]> {
const plugins = await this.list()
return _.compact(await Promise.all(plugins.map(async ([name, {tag}]) => {
try {
return await this.loadPlugin(name, tag)
} catch (err) {
cli.warn(err)
}
})))
}

public async uninstall(name: string) {
const plugins = await this.manifest.list()
if (!plugins[name]) return
await this.manifest.remove(name)
await this.yarn.exec(['remove', name])
}

private async loadPlugin(name: string, tag: string) {
return load({root: this.userPluginPath(name), type: 'user', tag, resetCache: true})
userPluginPath(name: string): string {
return path.join(this.userPluginsDir, 'node_modules', name)
}

private async loadPlugin(name: string, _: string) {
const config = await read({root: this.userPluginPath(name)})
return this.config.engine!.load(config)
// return this.config.engine!.load(config, {resetCache: true})
}

private async createPJSON() {
Expand All @@ -66,9 +59,6 @@ export default class Plugins {
}
}

private userPluginPath(name: string): string {
return path.join(this.userPluginsDir, 'node_modules', name)
}
private get userPluginsDir() {
return path.join(this.config.dataDir, 'plugins')
}
Expand Down
11 changes: 5 additions & 6 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {IConfig} from '@dxcli/config'
import {load} from '@dxcli/loader'
import {IConfig, read} from '@dxcli/config'
import {expect, FancyTypes, NockScope, test as base} from '@dxcli/test'
import * as fs from 'fs-extra'

export const test = base
.finally(async () => {
const plugin = await load({root: __dirname, type: 'core'})
const config = await read({root: __dirname})
await Promise.all([
fs.remove(plugin.config.cacheDir),
fs.remove(plugin.config.configDir),
fs.remove(plugin.config.dataDir),
fs.remove(config.cacheDir),
fs.remove(config.configDir),
fs.remove(config.dataDir),
])
})

Expand Down
Loading

0 comments on commit abb6601

Please sign in to comment.