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
37 changes: 37 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:latest

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "yarn.lock" }}

# run tests!
- run: yarn test
37 changes: 37 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
root = true

[*]
indent_style = tab
indent_size = 4
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

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

[{*.py,*.asm}]
indent_style = space

[*.py]
indent_size = 4

[*.asm]
indent_size = 8

[*.md]
trim_trailing_whitespace = false

# Ideal settings - some plugins might support these.
[*.js]
quote_type = single

[{*.c,*.cc,*.h,*.hh,*.cpp,*.hpp,*.m,*.mm,*.mpp,*.js,*.java,*.go,*.rs,*.php,*.ng,*.jsx,*.ts,*.d,*.cs,*.swift}]
curly_bracket_next_line = false
spaces_around_operators = true
spaces_around_brackets = outside
# close enough to 1TB
indent_brace_style = K&R
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

File renamed without changes.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

This command line interface provides a belt full of tools that make building microservices using [micro](https://github.com/zeit/micro) a breeze! It's only meant to be used in development, **not in production** (that's where [micro](https://github.com/zeit/micro) comes in).

[![Build Status](https://travis-ci.org/zeit/micro-dev.svg?branch=master)](https://travis-ci.org/zeit/micro-dev)
[![CircleCI](https://circleci.com/gh/zeit/micro-dev.svg?style=shield)](https://circleci.com/gh/zeit/micro-dev)
[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/micro)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

## Features

Expand Down Expand Up @@ -70,5 +69,5 @@ Inside the project where you want to test your clone of the package, you can now

## Authors

- Leo Lamprecht ([@notquiteleo](https://twitter.com/notquiteleo)) - [ZEIT](https://zeit.co)
- Tim Neutkens ([@timneutkens](https://twitter.com/timneutkens))
- Leo Lamprecht ([@notquiteleo](https://twitter.com/notquiteleo)) - [ZEIT](https://zeit.co)
- Tim Neutkens ([@timneutkens](https://twitter.com/timneutkens)) - [ZEIT](https://zeit.co)
133 changes: 66 additions & 67 deletions bin/micro-dev.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,105 @@
#!/usr/bin/env node

// Native
const { existsSync } = require('fs')
const path = require('path')
const {existsSync} = require('fs');
const path = require('path');

// Packages
const mri = require('mri')
const dotEnv = require('dotenv')
const mri = require('mri');
const dotEnv = require('dotenv');

// Utilities
const generateHelp = require('../lib/help')
const serve = require('../lib/serve')
const { version } = require('../package')
const logError = require('../lib/error')
const generateHelp = require('../lib/help');
const serve = require('../lib/serve');
const {version} = require('../package');
const logError = require('../lib/error');

const flags = mri(process.argv.slice(2), {
default: {
host: '::',
port: 3000,
limit: '1mb',
dotenv: '.env'
},
alias: {
p: 'port',
H: 'host',
c: 'cold',
w: 'watch',
L: 'poll',
s: 'silent',
h: 'help',
v: 'version',
i: 'ignore',
l: 'limit',
d: 'dotenv'
},
unknown(flag) {
console.log(`The option "${flag}" is unknown. Use one of these:`)
console.log(generateHelp())
process.exit(1)
}
})
'default': {
host: '::',
port: 3000,
limit: '1mb',
dotenv: '.env'
},
'alias': {
p: 'port',
H: 'host',
c: 'cold',
w: 'watch',
L: 'poll',
s: 'silent',
h: 'help',
v: 'version',
i: 'ignore',
l: 'limit',
d: 'dotenv'
},
unknown(flag) {
console.log(`The option "${flag}" is unknown. Use one of these:`);
console.log(generateHelp());
process.exit(1);
}
});

// When `-h` or `--help` are used, print out
// the usage information
if (flags.help) {
console.log(generateHelp())
process.exit()
console.log(generateHelp());
process.exit();
}

// Print out the package's version when
// `--version` or `-v` are used
if (flags.version) {
console.log(version)
process.exit()
console.log(version);
process.exit();
}

// Load the `.env` file
dotEnv.config({
path: path.resolve(process.cwd(), flags.dotenv)
})
path: path.resolve(process.cwd(), flags.dotenv)
});

if (flags.cold && (flags.watch || flags.poll)) {
logError(
'The --cold flag is not compatible with --watch or --poll!',
'watch-flags'
)
process.exit(1)
logError(
'The --cold flag is not compatible with --watch or --poll!',
'watch-flags'
);
process.exit(1);
}

let file = flags._[0]
let file = flags._[0];

if (!file) {
try {
// eslint-disable-next-line import/no-dynamic-require
const packageJson = require(path.resolve(process.cwd(), 'package.json'))
file = packageJson.main || 'index.js'
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
logError(
`Could not read \`package.json\`: ${err.message}`,
'invalid-package-json'
)
process.exit(1)
}
}
try {
const packageJson = require(path.resolve(process.cwd(), 'package.json'));
file = packageJson.main || 'index.js';
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
logError(
`Could not read \`package.json\`: ${err.message}`,
'invalid-package-json'
);
process.exit(1);
}
}
}

if (!file) {
logError('No path defined!', 'path-missing')
process.exit(1)
logError('No path defined!', 'path-missing');
process.exit(1);
}

if (file[0] !== '/') {
file = path.resolve(process.cwd(), file)
file = path.resolve(process.cwd(), file);
}

if (!existsSync(file)) {
logError(
`The file or directory "${path.basename(file)}" doesn't exist!`,
'path-not-existent'
)
process.exit(1)
logError(
`The file or directory "${path.basename(file)}" doesn't exist!`,
'path-not-existent'
);
process.exit(1);
}

serve(file, flags)
serve(file, flags);
10 changes: 5 additions & 5 deletions lib/error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Packages
const { red, blue } = require('chalk')
const {red, blue} = require('chalk');

module.exports = (message, errorCode) => {
const repo = errorCode === 'watch-flags' ? 'micro-dev' : 'micro'
const repo = errorCode === 'watch-flags' ? 'micro-dev' : 'micro';

console.error(`${red('Error:')} ${message}`)
console.error(`${blue('How to Fix It:')} https://err.sh/${repo}/${errorCode}`)
}
console.error(`${red('Error:')} ${message}`);
console.error(`${blue('How to Fix It:')} https://err.sh/${repo}/${errorCode}`);
};
14 changes: 7 additions & 7 deletions lib/help.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Packages
const { green: g } = require('chalk')
const {green: g} = require('chalk');

module.exports = () => {
const usage = `\n Usage: ${g('micro-dev')} [path] [options]
const usage = `\n Usage: ${g('micro-dev')} [path] [options]

Options:

Expand All @@ -13,13 +13,13 @@ module.exports = () => {
${g('-w, --watch <dir>')} A directory to watch in addition to [path]
${g('-L, --poll')} Poll for code changes rather than using events
${g(
'-l, --limit'
)} Size limit for JSON parsing (string like '1mb', or bytes)
'-l, --limit'
)} Size limit for JSON parsing (string like '1mb', or bytes)
${g('-i --ignore <dir>')} Ignore watching a file, directory, or glob
${g('-s, --silent')} Disable requests log
${g('-v, --version')} Output the version number
${g('-h, --help')} Show this usage information
`
`;

return usage
}
return usage;
};
Loading