Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added our linting setup and updated dependencies #354

Merged
merged 5 commits into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
34 changes: 26 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
# More details: editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2

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

[*.{json,yml}]
indent_style = space
indent_size = 2
# 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
180 changes: 90 additions & 90 deletions bin/serve.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,130 @@
#!/usr/bin/env node

// Native
const path = require('path')
const https = require('https')
const path = require('path');
const https = require('https');

// Packages
const micro = require('micro')
const args = require('args')
const compress = require('micro-compress')
const detect = require('detect-port')
const { coroutine } = require('bluebird')
const checkForUpdate = require('update-check')
const { red, bold } = require('chalk')
const nodeVersion = require('node-version')
const cert = require('openssl-self-signed-certificate')
const boxen = require('boxen')
const micro = require('micro');
const args = require('args');
const compress = require('micro-compress');
const detect = require('detect-port');
const {coroutine} = require('bluebird');
const checkForUpdate = require('update-check');
const {red, bold} = require('chalk');
const nodeVersion = require('node-version');
const cert = require('openssl-self-signed-certificate');
const boxen = require('boxen');

// Utilities
const pkg = require('../package')
const listening = require('../lib/listening')
const serverHandler = require('../lib/server')
const { options, minimist } = require('../lib/options')
const pkg = require('../package');
const listening = require('../lib/listening');
const serverHandler = require('../lib/server');
const {options, minimist} = require('../lib/options');

// Throw an error if node version is too low
if (nodeVersion.major < 6) {
console.error(
`${red(
'Error!'
)} Serve requires at least version 6 of Node. Please upgrade!`
)
process.exit(1)
console.error(
`${red(
'Error!'
)} Serve requires at least version 6 of Node. Please upgrade!`
);
process.exit(1);
}

// Register the list of options
args.options(options)
args.options(options);

// And initialize `args`
const flags = args.parse(process.argv, { minimist })
const flags = args.parse(process.argv, {minimist});

// Figure out the content directory
const [directory] = args.sub
const [directory] = args.sub;

// Don't log anything to the console if silent mode is enabled
if (flags.silent) {
console.log = () => {}
console.log = () => {};
}

process.env.ASSET_DIR = Math.random()
.toString(36)
.substr(2, 10)
.toString(36)
.substr(2, 10);

let current = process.cwd()
let current = process.cwd();

if (directory) {
current = path.resolve(process.cwd(), directory)
current = path.resolve(process.cwd(), directory);
}

let ignoredFiles = ['.DS_Store', '.git/']
let ignoredFiles = ['.DS_Store', '.git/'];

if (flags.ignore && flags.ignore.length > 0) {
ignoredFiles = ignoredFiles.concat(flags.ignore.split(','))
ignoredFiles = ignoredFiles.concat(flags.ignore.split(','));
}

const handler = coroutine(function*(req, res) {
yield serverHandler(req, res, flags, current, ignoredFiles)
})
const handler = coroutine(function *run(req, res) {
yield serverHandler(req, res, flags, current, ignoredFiles);
});

const httpsOpts = {
key: cert.key,
cert: cert.cert,
passphrase: cert.passphrase
}
key: cert.key,
cert: cert.cert,
passphrase: cert.passphrase
};

const microHttps = fn =>
https.createServer(httpsOpts, (req, res) => micro.run(req, res, fn))
https.createServer(httpsOpts, (req, res) => micro.run(req, res, fn));
const server = flags.ssl
? microHttps(flags.unzipped ? handler : compress(handler))
: micro(flags.unzipped ? handler : compress(handler))
? microHttps(flags.unzipped ? handler : compress(handler))
: micro(flags.unzipped ? handler : compress(handler));

let { port } = flags
let {port} = flags;

detect(port).then(async open => {
const { NODE_ENV } = process.env

if (NODE_ENV !== 'production') {
const update = await checkForUpdate(pkg)

if (update) {
const message = `${bold(
'UPDATE AVAILABLE:'
)} The latest version of \`serve\` is ${update.latest}`
console.log(
boxen(message, {
padding: 1,
borderColor: 'green',
margin: 1
})
)
}
}

let inUse = open !== port

if (inUse) {
port = open

inUse = {
old: flags.port,
open
}
}

const listenArgs = [
server,
current,
inUse,
flags.clipless !== true,
flags.open,
flags.ssl,
flags.local
]

if (flags.local) {
server.listen(port, 'localhost', listening.bind(this, ...listenArgs))
} else {
server.listen(port, listening.bind(this, ...listenArgs))
}
})
const {NODE_ENV} = process.env;

if (NODE_ENV !== 'production') {
const update = await checkForUpdate(pkg);

if (update) {
const message = `${bold(
'UPDATE AVAILABLE:'
)} The latest version of \`serve\` is ${update.latest}`;

console.log(
boxen(message, {
padding: 1,
borderColor: 'green',
margin: 1
})
);
}
}

let inUse = open !== port;

if (inUse) {
port = open;

inUse = {
old: flags.port,
open
};
}

const listenArgs = [
server,
current,
inUse,
flags.clipless !== true,
flags.open,
flags.ssl,
flags.local
];

if (flags.local) {
server.listen(port, 'localhost', listening.bind(this, ...listenArgs));
} else {
server.listen(port, listening.bind(this, ...listenArgs));
}
});
42 changes: 21 additions & 21 deletions lib/api.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// Native
const { spawn } = require('child_process')
const path = require('path')
const {spawn} = require('child_process');
const path = require('path');

// Packages
const dargs = require('dargs')
const dargs = require('dargs');

module.exports = (directory = process.cwd(), options = {}) => {
const scriptPath = path.join(__dirname, '..', 'bin', 'serve.js')
const aliases = { cors: 'C' }
const scriptPath = path.join(__dirname, '..', 'bin', 'serve.js');
const aliases = {cors: 'C'};

options._ = [directory] // Let dargs handle the directory argument
options._ = [directory]; // Let dargs handle the directory argument

// The CLI only understands comma-separated values for ignored files
// So we join the string array with commas
if (options.ignore) {
options.ignore = options.ignore.join(',')
}
// The CLI only understands comma-separated values for ignored files
// So we join the string array with commas
if (options.ignore) {
options.ignore = options.ignore.join(',');
}

const args = [scriptPath, ...dargs(options, { aliases })]
const args = [scriptPath, ...dargs(options, {aliases})];

const cli = spawn('node', args, {
stdio: 'inherit'
})
const cli = spawn('node', args, {
stdio: 'inherit'
});

return {
stop() {
cli.kill()
}
}
}
return {
stop() {
cli.kill();
}
};
};
Loading