Skip to content

Commit

Permalink
Merge branch 'canary' into add-core-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flybayer committed Mar 2, 2020
2 parents 39fb911 + 8f6d0e0 commit 0c65a32
Show file tree
Hide file tree
Showing 22 changed files with 4,531 additions and 316 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
reports
*.log
**/.env*
coverage
.nyc_output
**/coverage
3 changes: 3 additions & 0 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const {fs} = require('memfs')

module.exports = fs
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
},
"scripts": {
"dev": "lerna run start --scope @blitzjs/* --stream --parallel",
"dev2": "lerna run start --stream --parallel",
"build": "lerna run build --scope @blitzjs/* --stream",
"lerna": "lerna",
"lerna-prepare": "lerna run prepare",
"test": "lerna run test --parallel"
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/jest": "^25.1.3",
"@types/node": "^13.7.4",
"cross-env": "^7.0.0",
"debug": "^4.1.1",
"husky": "^4.2.3",
"jest": "^25.1.0",
"lerna": "^3.20.2",
Expand All @@ -29,6 +31,7 @@
"prettier": "^1.19.1",
"pretty-quick": "2.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^25.2.1",
"tsdx": "^0.12.3",
"tslib": "^1.10.0",
"typescript": "^3.7.5"
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ node_modules
.rts2_cache_umd
.rts2_cache_system
dist
tmp

# good directory to use for testing app generation
_app
91 changes: 91 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# blitz-cli

Blitz CLI

[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![Version](https://img.shields.io/npm/v/blitz-cli.svg)](https://npmjs.org/package/blitz-cli)
[![Downloads/week](https://img.shields.io/npm/dw/blitz-cli.svg)](https://npmjs.org/package/blitz-cli)
[![License](https://img.shields.io/npm/l/blitz-cli.svg)](https://github.com/mabadir/blitz-cli/blob/master/package.json)

## Contributing

Run `yarn` from the monorepo root

**Run locally from this directory:**
`yarn b [COMMAND]`

**Run tests:**
`yarn test`

**Build package:**
`yarn build`

<!-- toc -->

- [blitz-cli](#blitz-cli)
- [Usage](#usage)
- [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->

```sh-session
$ npm install -g @blitzjs/cli
$ blitz COMMAND
running command...
$ blitz (-v|--version|version)
@blitzjs/cli/0.0.1 darwin-x64 node-v12.16.1
$ blitz --help [COMMAND]
USAGE
$ blitz COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- commands -->

- [`blitz help [COMMAND]`](#blitz-help-command)
- [`blitz new [PATH]`](#blitz-new-path)

## `blitz help [COMMAND]`

display help for blitz

```
USAGE
$ blitz help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_

## `blitz new [PATH]`

Create a new Blitz project

```
USAGE
$ blitz new [PATH]
ARGUMENTS
PATH path to the new project, defaults to the current directory
OPTIONS
-h, --help show CLI help
-t, --[no-]ts generate a TypeScript project
--yarn use Yarn as the package manager
```

_See code: [lib/commands/new.js](https://github.com/blitz-js/blitz/blob/v0.0.1/lib/commands/new.js)_

<!-- commandsstop -->
5 changes: 5 additions & 0 deletions packages/cli/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

require('@oclif/command').run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'))
3 changes: 3 additions & 0 deletions packages/cli/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
23 changes: 23 additions & 0 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json'],
coverageReporters: ['json', 'lcov', 'text', 'clover'],
// collectCoverage: !!`Boolean(process.env.CI)`,
collectCoverageFrom: ['src/**/*.ts'],
coveragePathIgnorePatterns: ['/templates/'],
// TODO enable threshold
// coverageThreshold: {
// global: {
// branches: 100,
// functions: 100,
// lines: 100,
// statements: 100,
// },
// },
globals: {
'ts-jest': {
tsConfig: 'test/tsconfig.json',
},
},
}
81 changes: 50 additions & 31 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
{
"name": "@blitzjs/cli",
"description": "Framework for building monolithic, full-stack, serverless React apps with zero data-fetching and zero client-side state management",
"description": "Blitz CLI",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"b": "./bin/run",
"version": "oclif-dev readme && git add README.md",
"build": "oclif-dev pack",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"postpack": "rm -f oclif.manifest.json",
"test": "jest --coverage"
},
"author": "Mina Abadir @mabadir",
"main": "lib/index.js",
"bin": {
"blitz": "./bin/run"
},
"types": "lib/index.d.ts",
"files": [
"/bin",
"/lib",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
"dependencies": {
"@oclif/command": "^1.5.19",
"@oclif/config": "^1.14.0",
"@oclif/plugin-help": "^2.2.3",
"@oclif/plugin-not-found": "^1.2.3",
"yeoman-environment": "^2.8.0",
"yeoman-generator": "^4.5.0"
},
"devDependencies": {
"@oclif/dev-cli": "^1.22.2",
"@oclif/test": "^1.2.5",
"@types/yeoman-environment": "^2.3.2",
"@types/yeoman-generator": "^3.1.4",
"chai": "^4.2.0",
"globby": "^11.0.0",
"ts-node": "^8.6.2"
},
"oclif": {
"commands": "./lib/commands",
"bin": "blitz",
"plugins": [
"@oclif/plugin-help",
"@oclif/plugin-not-found"
]
},
"engines": {
"yarn": "^1.19.1",
"node": ">=12.16.1"
},
"keywords": [
"blitz",
"cli"
],
"repository": {
"type": "git",
"url": "https://github.com/blitz-js/blitz"
},
"author": {
"name": "Brandon Bayer",
"email": "b@bayer.ws",
"url": "https://twitter.com/flybayer"
},
"contributors": [
{
"name": "Michael Edelman",
"email": "michael@fabulas.io",
"url": "https://twitter.com/edelman215"
}
],
"main": "dist/index.js",
"module": "dist/testtsdx.esm.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
}
}
44 changes: 44 additions & 0 deletions packages/cli/src/commands/new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {Command, flags} from '@oclif/command'
import yeoman = require('yeoman-environment')
const debug = require('debug')('blitz:new')

export interface Flags {
ts: boolean
yarn: boolean
}

export default class New extends Command {
static description = 'Create a new Blitz project'

static args = [
{
name: 'path',
required: false,
description: 'path to the new project, defaults to the current directory',
},
]

static flags = {
help: flags.help({char: 'h'}),
ts: flags.boolean({
char: 't',
description: 'generate a TypeScript project',
default: true,
allowNo: true,
}),
yarn: flags.boolean({description: 'use Yarn as the package manager', default: true}),
}

async run() {
const {args, flags} = this.parse(New)
debug('args: ', args)
debug('flags: ', flags)
const env = yeoman.createEnv()

env.register(require.resolve('../generators/app'), 'generate:app')
env.run(['generate:app', args.path], flags as Flags, (err: Error | null) => {
if (err) this.error(err) // Maybe tell a bit more...
this.log('App created!') // This needs some sparkles ✨
})
}
}
Loading

0 comments on commit 0c65a32

Please sign in to comment.