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

refactor: remove bluebird in favor of native apis #279

Merged
merged 3 commits into from
Aug 7, 2016
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
4 changes: 0 additions & 4 deletions decl/bluebird.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"dependencies": {
"ansi-regex": "2.0.0",
"babel-eslint": "6.1.2",
"bluebird": "3.4.1",
"chalk": "1.1.3",
"commander": "2.9.0",
"eslint": "3.2.2",
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require('../../lib/babel-hook');
const path = require('path');
const rollup = require('rollup').rollup;

const fs = require('../../src/packages/fs').default;
const fs = require('../../src/packages/fs');
const dist = path.join(__dirname, '..', '..', 'dist');
const config = require('./config');
const commands = path.join(
Expand All @@ -18,7 +18,7 @@ const commands = path.join(
'commands'
);

fs.readdirAsync(commands)
fs.readdir(commands)
.then(files => {
return Promise.all(
files.map(file => {
Expand Down
89 changes: 38 additions & 51 deletions src/packages/cli/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { green } from 'chalk';

import { CWD } from '../../../constants';

import fs from '../../fs';
import { mkdir, writeFile } from '../../fs';
import template from '../../template';

import exec from '../../../utils/exec';
Expand All @@ -30,101 +30,88 @@ export async function create(name, database) {
const driver = driverFor(database);
const project = `${CWD}/${name}`;

await fs.mkdirAsync(project);
await mkdir(project);

await Promise.all([
fs.mkdirAsync(`${project}/app`),
fs.mkdirAsync(`${project}/config`),
fs.mkdirAsync(`${project}/db`)
mkdir(`${project}/app`),
mkdir(`${project}/config`),
mkdir(`${project}/db`)
]);

await Promise.all([
fs.mkdirAsync(`${project}/app/models`),
fs.mkdirAsync(`${project}/app/serializers`),
fs.mkdirAsync(`${project}/app/controllers`),
fs.mkdirAsync(`${project}/app/middleware`),
fs.mkdirAsync(`${project}/app/utils`),
fs.mkdirAsync(`${project}/config/environments`),
fs.mkdirAsync(`${project}/db/migrate`)
mkdir(`${project}/app/models`),
mkdir(`${project}/app/serializers`),
mkdir(`${project}/app/controllers`),
mkdir(`${project}/app/middleware`),
mkdir(`${project}/app/utils`),
mkdir(`${project}/config/environments`),
mkdir(`${project}/db/migrate`)
]);

await Promise.all([
fs.writeFileAsync(
writeFile(
`${project}/app/index.js`,
appTemplate(name),
'utf8'
appTemplate(name)
),

fs.writeFileAsync(
writeFile(
`${project}/app/routes.js`,
routesTemplate(),
'utf8'
routesTemplate()
),

fs.writeFileAsync(
writeFile(
`${project}/config/environments/development.js`,
configTemplate(name, 'development'),
'utf8'
configTemplate(name, 'development')
),

fs.writeFileAsync(
writeFile(
`${project}/config/environments/test.js`,
configTemplate(name, 'test'),
'utf8'
configTemplate(name, 'test')
),

fs.writeFileAsync(
writeFile(
`${project}/config/environments/production.js`,
configTemplate(name, 'production'),
'utf8'
configTemplate(name, 'production')
),

fs.writeFileAsync(
writeFile(
`${project}/config/database.js`,
dbTemplate(name, driver),
'utf8'
dbTemplate(name, driver)
),

fs.writeFileAsync(
writeFile(
`${project}/db/seed.js`,
seedTemplate(),
'utf8'
seedTemplate()
),

fs.writeFileAsync(
writeFile(
`${project}/README.md`,
readmeTemplate(name),
'utf8'
readmeTemplate(name)
),

fs.writeFileAsync(
writeFile(
`${project}/LICENSE`,
licenseTemplate(),
'utf8'
licenseTemplate()
),

fs.writeFileAsync(
writeFile(
`${project}/package.json`,
pkgJSONTemplate(name, database),
'utf8'
pkgJSONTemplate(name, database)
),

fs.writeFileAsync(
writeFile(
`${project}/.babelrc`,
babelrcTemplate(),
'utf8'
babelrcTemplate()
),

fs.writeFileAsync(
writeFile(
`${project}/.eslintrc.json`,
eslintrcTemplate(),
'utf8'
eslintrcTemplate()
),

fs.writeFileAsync(
writeFile(
`${project}/.gitignore`,
gitignoreTemplate(),
'utf8'
gitignoreTemplate()
)
]);

Expand Down
5 changes: 3 additions & 2 deletions src/packages/cli/commands/dbcreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CWD, NODE_ENV } from '../../../constants';
import fs from '../../fs';

import loader from '../../loader';
import { connect } from '../../database';
import { writeFile } from '../../fs';

/**
* @private
Expand All @@ -18,7 +19,7 @@ export async function dbcreate() {
} = loader(CWD, 'config');

if (driver === 'sqlite3') {
await fs.writeFileAsync(`${CWD}/db/${database}_${NODE_ENV}.sqlite`, '');
await writeFile(`${CWD}/db/${database}_${NODE_ENV}.sqlite`, '');
} else {
const { schema } = connect(CWD, { ...config, driver });
const query = schema.raw(`CREATE DATABASE ${database}`);
Expand Down
5 changes: 3 additions & 2 deletions src/packages/cli/commands/dbrollback.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CWD } from '../../../constants';

import Database from '../../database';
import Logger, { sql } from '../../logger';
import fs from '../../fs';
import loader from '../../loader';
import { readdir } from '../../fs';

/**
* @private
Expand All @@ -23,7 +24,7 @@ export async function dbrollback() {
})
});

const migrationFiles = await fs.readdirAsync(`${CWD}/db/migrate`);
const migrationFiles = await readdir(`${CWD}/db/migrate`);

if (migrationFiles.length) {
let migration;
Expand Down
8 changes: 4 additions & 4 deletions src/packages/cli/commands/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CWD } from '../../../constants';
import { red, green } from 'chalk';
import { pluralize, singularize } from 'inflection';

import fs, { rmrf, exists } from '../../fs';
import { rmrf, exists, readdir, readFile, writeFile } from '../../fs';

/**
* @private
Expand All @@ -20,7 +20,7 @@ export async function destroyType(type, name) {
break;

case 'migration':
migrations = await fs.readdirAsync(`${CWD}/db/migrate`);
migrations = await readdir(`${CWD}/db/migrate`);
name = migrations.find(file => `${name}.js` === file.substr(17));
path = `db/migrate/${name}`;
break;
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function destroy({ type, name }: {
name: string;
}) {
if (type === 'resource') {
const routes = (await fs.readFileAsync(`${CWD}/app/routes.js`, 'utf8'))
const routes = (await readFile(`${CWD}/app/routes.js`, 'utf8'))
.split('\n')
.reduce((lines, line) => {
const pattern = new RegExp(
Expand All @@ -72,7 +72,7 @@ export async function destroy({ type, name }: {
destroyType('controller', name)
]);

await fs.writeFileAsync(`${CWD}/app/routes.js`, routes, 'utf8');
await writeFile(`${CWD}/app/routes.js`, routes);
console.log(`${green('update')} app/routes.js`);
} else if (type === 'model') {
await Promise.all([
Expand Down
15 changes: 8 additions & 7 deletions src/packages/cli/commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { pluralize, singularize } from 'inflection';
import { createInterface } from 'readline';

import { CWD } from '../../../constants';
import fs, { rmrf, exists } from '../../fs';

import { generateTimestamp } from '../../database';
import { rmrf, exists, readdir, readFile, writeFile } from '../../fs';

import modelTemplate from '../templates/model';
import serializerTemplate from '../templates/serializer';
Expand Down Expand Up @@ -105,7 +106,7 @@ export async function generateType(type, name, cwd, attrs = []) {

if (overwrite) {
if (isMigration) {
const migrations = await fs.readdirAsync(`${cwd}/db/migrate`);
const migrations = await readdir(`${cwd}/db/migrate`);
const isModelMigration = type === 'model-migration';

const oldName = migrations.find(file => {
Expand All @@ -120,17 +121,17 @@ export async function generateType(type, name, cwd, attrs = []) {
console.log(`${red('remove')} ${oldPath}`);
}

await fs.writeFileAsync(`${cwd}/${path}`, data, 'utf8');
await writeFile(`${cwd}/${path}`, data);
console.log(`${green('create')} ${path}`);
} else {
await fs.writeFileAsync(`${cwd}/${path}`, data, 'utf8');
await writeFile(`${cwd}/${path}`, data);
console.log(`${yellow('overwrite')} ${path}`);
}
} else {
console.log(`${yellow('skip')} ${path}`);
}
} else {
await fs.writeFileAsync(`${cwd}/${path}`, data, 'utf8');
await writeFile(`${cwd}/${path}`, data);
console.log(`${green('create')} ${path}`);
}

Expand All @@ -152,7 +153,7 @@ export async function generate({
attrs: Array<string>
}) {
if (type === 'resource') {
const routes = (await fs.readFileAsync(`${cwd}/app/routes.js`, 'utf8'))
const routes = (await readFile(`${cwd}/app/routes.js`, 'utf8'))
.split('\n')
.reduce((str, line, index, array) => {
const closeIndex = array.lastIndexOf('}');
Expand All @@ -173,7 +174,7 @@ export async function generate({
await generateType('serializer', name, cwd, attrs);
await generateType('controller', name, cwd, attrs);

await fs.writeFileAsync(`${cwd}/app/routes.js`, routes, 'utf8');
await writeFile(`${cwd}/app/routes.js`, routes);
console.log(`${green('update')} app/routes.js`);
} else if (type === 'model') {
await generateType(type, name, cwd, attrs);
Expand Down
14 changes: 7 additions & 7 deletions src/packages/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import nodeResolve from 'rollup-plugin-node-resolve';
import { rollup } from 'rollup';

import { BACKSLASH } from './constants';
import fs, { rmrf } from '../fs';
import { rmrf, readdir } from '../fs';
import template from '../template';

import createManifest from './utils/create-manifest';
Expand All @@ -33,17 +33,17 @@ export async function compile(dir: string, env: string, {
const sourceMapSupport = path.join(luxNodeModules, 'source-map-support');

const external = await Promise.all([
fs.readdirAsync(nodeModules),
fs.readdirAsync(luxNodeModules),
readdir(nodeModules),
readdir(luxNodeModules)
]).then(([a, b]: [Array<string>, Array<string>]) => {
return a.concat(b).filter(name => name !== 'lux-framework');
});

const assets = await Promise.all([
fs.readdirAsync(path.join(dir, 'app', 'models')),
fs.readdirAsync(path.join(dir, 'app', 'controllers')),
fs.readdirAsync(path.join(dir, 'app', 'serializers')),
fs.readdirAsync(path.join(dir, 'db', 'migrate')),
readdir(path.join(dir, 'app', 'models')),
readdir(path.join(dir, 'app', 'controllers')),
readdir(path.join(dir, 'app', 'serializers')),
readdir(path.join(dir, 'db', 'migrate'))
]).then(([
models,
controllers,
Expand Down
4 changes: 2 additions & 2 deletions src/packages/compiler/utils/create-boot-script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow
import path from 'path';

import fs from '../../fs';
import template from '../../template';
import { writeFile } from '../../fs';

/**
* @private
Expand Down Expand Up @@ -30,5 +30,5 @@ export default async function createBootScript(dir: string, {
data = `'use strict';\n\n${data}`;
}

await fs.writeFileAsync(path.join(dir, 'dist', 'boot.js'), data, 'utf8');
await writeFile(path.join(dir, 'dist', 'boot.js'), data);
}
Loading