Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.nyc_output/
lib/
node_modules/

Expand Down
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cache: yarn
language: node_js
node_js:
- node
- '8'
- '6'
os:
- linux
deploy:
provider: npm
email: support@nativecode.com
api_key:
secure: >-
EoY8os0mZH2U1SqZFDh5p5CoImh15kK1Ckap9/6WuNXHO+ZduuqRCkgI3/Q/xMlj9b+tmGDfrZ/dTxvXn+aIW+brGvqMETKHsWSdTRnfHCFV1qUpSb+I9h/oMqbljaapbqIIZRQWwbf0rMAUwdsD9F8Un/cTAjW3BrnL7UES2f62+3IAZWUbWkyfM973cuT88Vt6JqrAsHYbVKahacChrohT3pJarsGrMZ3713TQ1X1P2pgbheQYM+82puXNT3jTjp48rg6zBslSjR0ze1un3sUpTmmt8F/B4U9Gma20X9qDvOqPR3ej6Z5wvj/iI/07rDIJISFldJK2+RE8qSdILjEPvrF9OtmpLjpzaokj2JEhwX3hEYHXSu9Uhv7TqxmJYTrlLKTTJgzLu8PI5WgvU5WtfXjrSRLhz71taWVkijeCNUZYjvVSCOucDyi8w55B+zFwZfIgb6Uv8O3b5Rn+GGMlinWLreCgAQn2LqOswjXgk6LYG9Sk3DMGaILAmdxzVZ5yGM8tgg3nk4igQs8SpSRibpAaEeLi2HJfI4prGzvbKXZh+snPp7iPkDjTvHmKjH6fSfVZPwOGk+N5SRWj/v21LONxYGYejJIF/RgD35ILu/qMzz8Z8kT+Od2RJjwxatq1I2RcxLE4DCNCgkcv6MwQrL3z+hjPM2KlDFrBj/c=
on:
branch: master
tag: next
repo: nativecode-dev/chest
skip_cleanup: true
after_success:
- npm run coveralls
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[![npm](https://img.shields.io/npm/v/@beard/chest.svg?style=flat-square&label=@beard/chest)](https://www.npmjs.com/package/@beard/chest)
[![npm](https://img.shields.io/npm/l/express.svg?style=flat-square)]()
[![David](https://img.shields.io/david/nativecode-dev/chest.svg?style=flat-square&label=deps)](https://www.npmjs.com/package/@beard/chest)
[![David](https://img.shields.io/david/dev/nativecode-dev/chest.svg?style=flat-square&label=devdeps)](https://www.npmjs.com/package/@beard/chest)

[![Travis](https://img.shields.io/travis/nativecode-dev/chest/master.svg?style=flat-square&label=master)](https://travis-ci.org/nativecode-dev/chest)
[![Coveralls branch](https://img.shields.io/coveralls/github/nativecode-dev/chest/master.svg?style=flat-square)](https://coveralls.io/github/nativecode-dev/chest)

[![Travis](https://img.shields.io/travis/nativecode-dev/chest/develop.svg?style=flat-square&label=develop)](https://travis-ci.org/nativecode-dev/chest)
[![Coveralls branch](https://img.shields.io/coveralls/github/nativecode-dev/chest/develop.svg?style=flat-square)](https://coveralls.io/github/nativecode-dev/chest)

# @beard/chest

<p align="center">
<img src="chest-temp.png">
</p>

# WTF

It's a chest. With TypeScript inside.

Actually, it's a set of tools to manage TypeScript projects, whether they are stand-alone or workspace-based (either [Yarn](https://yarnpkg.com) or [Lerna](https://lernajs.io).

# What Problems Get Solved

CHEST will...

- Link `@types` dependencies as a `types` array in your `tsconfig.json`, explicitly listing your declaration dependencies.
- Propogate desriptive `package.json` properties down to child projects if using [Yarn](https://yarnpkg.com) workspaces.

# Supported Project Management Tools

- [Yarn](https://yarnpkg.com) 1.3.2+
- [Lerna](https://lernajs.io) 2.0+

# License
© 2017 NativeCode Development <support@nativecode.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file added chest-temp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--require ts-node/register
--require tsconfig-paths/register
--require source-map-support/register
--full-trace
--recursive
--bail
src/**/*.spec.ts
50 changes: 42 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
{
"bin": "./lib/cli.js",
"name": "@beard/chest",
"description": "CHEST of me best tools, matey!",
"bin": "./lib/CLI.js",
"license": "MIT",
"main": "./lib/CLI.js",
"typings": "./lib/index.d.ts",
"version": "2.0.0-alpha-1",
"dependencies": {
"chalk": "^2.3.0"
},
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/chai-as-promised": "^7.1.0",
"@types/chalk": "^2.2.0",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.52",
"bin-shebang": "^1.0.11",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.0",
"cross-env": "^5.1.1",
"mocha": "^4.0.1",
"nyc": "^11.3.0",
"rimraf": "^2.6.2",
"ts-node": "^3.3.0",
"tsconfig-paths": "^2.3.0",
"tslint": "^5.8.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.6.1"
},
"license": "MIT",
"main": "./lib/cli.js",
"name": "@beard/chest",
"nyc": {
"all": true,
"exclude": [
"src/**/*.spec.ts",
"src/CLI.ts"
],
"extension": [
".ts"
],
"include": [
"src/**/*.ts"
],
"instrument": true,
"sourceMap": true
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/nativecode-dev/chest"
},
"scripts": {
"build": "tsc --project tsconfig.json",
"lint": "tslint src/**/*.ts",
"prebuild": "rimraf lib",
"postbuild": "bin-shebang"
},
"typings": "lib/index.d.ts",
"version": "1.1.2"
"postbuild": "bin-shebang && yarn run lint",
"test": "cross-env NODE_ENV=test nyc mocha --opts mocha.opts",
"pretest": "yarn run build",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
}
}
3 changes: 3 additions & 0 deletions src/CLI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Chest } from './index'

Chest.run(process.cwd(), ...process.argv.slice(2))
58 changes: 58 additions & 0 deletions src/Chest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'mocha'

import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'

import { Chest } from './Chest'
import { Files, Registry } from './Core'

const expect = chai.expect

describe('when using RootProject to load a project', () => {

beforeEach(() => {
chai.should()
chai.use(chaiAsPromised)
})

it('should load single npm project', async () => {
const directory = Files.join(process.cwd(), 'testables', 'single')
const project = await Chest.project(directory)
const projects = await Chest.projects(project)
expect(projects.length).to.equal(1)
expect(projects[0].name).to.equal('project-single')
expect(projects[0].path).to.equal(directory)
})

it('should load yarn workspace project', async () => {
const directory = Files.join(process.cwd(), 'testables', 'workspaces')
const project = await Chest.project(directory)
const projects = await Chest.projects(project)
expect(projects.length).to.equal(2)
expect(projects[0].name).to.equal('simple-package')
expect(projects[1].name).to.equal('simple-project')
expect(projects[0].owner).to.not.equal(undefined)
expect(projects[0].owner).to.not.equal(undefined)
})

it('should throw error when single project does not exist', async () => {
const directory = Files.join(process.cwd(), 'testables', 'nonexistant')
Chest.project(directory).then(project => Chest.projects(project).should.eventually.throw())
})

it('should throw error when workspace project has no child projects', async () => {
const directory = Files.join(process.cwd(), 'testables', 'workspaces-invalid')
Chest.project(directory).then(project => Chest.projects(project).should.eventually.throw())
})

it('should run scripts for single project', () => {
const directory = Files.join(process.cwd(), 'testables', 'single')
Chest.run(directory, ...Object.keys(Registry.all()))
})

it('should run scripts for workspace project', () => {
const directory = Files.join(process.cwd(), 'testables', 'workspaces')
Chest.run(directory, ...Object.keys(Registry.all()))
})

})
61 changes: 61 additions & 0 deletions src/Chest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as path from 'path'

import { Files, NPM, Project, UpdaterType } from './Core'
import { Registry } from 'src';

export class Chest {
public static async run(root: string, ...args: string[]): Promise<void> {
const project = await Chest.project(root)
const projects = await Chest.projects(project)
const updaters = Registry.all()

Object.keys(updaters).forEach(async name => {
const updater = updaters[name]

if (updater.type === UpdaterType.Root) {
await updater.exec(root)
} else {
await Promise.all(projects.map(child => updater.workspace(child)))
}
})
}

public static async project(root: string): Promise<Project> {
const npmfile = path.join(root, 'package.json')

if (await Files.exists(npmfile) === false) {
throw new Error(`failed to find ${npmfile} in ${root}`)
}

const npm = await Files.json<NPM>(npmfile)
return new Project(npm.name, root)
}

public static async projects(owner: Project): Promise<Project[]> {
const project = await Chest.project(owner.path)
const npm = await project.package

if (npm.private && npm.workspace) {
return npm.workspace.map(workspaceRoot => Chest.workspaces(project, workspaceRoot))
.reduce(async (previous, current) => (await previous).concat(await current), Promise.resolve([]))
}

return [project]
}

private static async workspaces(owner: Project, workspaceRoot: string): Promise<Project[]> {
workspaceRoot = Files.join(owner.path, workspaceRoot.substring(0, workspaceRoot.indexOf('/*')))

if (await Files.exists(workspaceRoot) === false) {
throw new Error(`failed to find workspace ${workspaceRoot} in ${owner.name}`)
}

const projects = await Files.listdirs(workspaceRoot)

return Promise.all(projects.map(async project => {
const npmfile = path.join(project, 'package.json')
const npm = await Files.json<NPM>(npmfile)
return new Project(npm.name, project, owner)
}))
}
}
48 changes: 48 additions & 0 deletions src/Core/Actions/Packages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as path from 'path'

import { Files, Logger, NPM, Project, Registry, Updater, UpdateScript, UpdaterType } from '../index'

const ScriptName = Files.extensionless(__filename)
const log = Logger(ScriptName)
const prefix = '@types'

interface Dependency {
filename: string
filepath: string
npmname: string
scope?: string
typings?: string
}

/*
* Propogates changes from the root package.json to child
* packages.
**/
class Script extends UpdateScript {
constructor() {
super(ScriptName, UpdaterType.Projects)
}

public async workspace(project: Project): Promise<void> {
const source = await project.package
const target = await project.owner.package

target.author = source.author
target.bugs = source.bugs
target.description = source.description
target.homepage = source.homepage
target.license = source.license
target.repository = source.repository

const filename = path.join(project.path, 'package.json')

if (this.testing) {
this.log.task('updated package info', filename, target)
} else {
await Files.save(filename, target)
this.log.task('updated package info', filename)
}
}
}

Registry.add(ScriptName, new Script())
Loading