Skip to content

Commit

Permalink
fix: cli and compilation errors (#649)
Browse files Browse the repository at this point in the history
* fix: cli and compilation errors

* fix: eslint errors
  • Loading branch information
zacharygolba authored Jan 19, 2017
1 parent 06d9fc7 commit d1c5e8d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 54 deletions.
58 changes: 27 additions & 31 deletions src/packages/cli/generator/utils/generate-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@ export async function controller(opts: Generator$opts): Promise<void> {

const namespace = posix.dirname(name);

if (namespace === '.') {
return;
}

const hasParent = await exists(
joinPath(cwd, dir, namespace.split('/'), 'application.js')
);

if (!hasParent) {
await controller({
...opts,
cwd,
name: `${namespace}/application`,
attrs: []
});
if (namespace !== '.') {
const hasParent = await exists(
joinPath(cwd, dir, ...[...namespace.split('/'), 'application.js'])
);

if (!hasParent) {
await controller({
...opts,
cwd,
name: `${namespace}/application`,
attrs: []
});
}
}
}

Expand Down Expand Up @@ -89,21 +87,19 @@ export async function serializer(opts: Generator$opts): Promise<void> {

const namespace = posix.dirname(name);

if (namespace === '.') {
return;
}

const hasParent = await exists(
joinPath(cwd, dir, ...[...namespace.split('/'), 'application.js'])
);

if (!hasParent) {
await serializer({
...opts,
cwd,
name: `${namespace}/application`,
attrs: []
});
if (namespace !== '.') {
const hasParent = await exists(
joinPath(cwd, dir, ...[...namespace.split('/'), 'application.js'])
);

if (!hasParent) {
await serializer({
...opts,
cwd,
name: `${namespace}/application`,
attrs: []
});
}
}
}

Expand Down Expand Up @@ -239,7 +235,7 @@ export async function resource(opts: Generator$opts) {
await controller(opts);
await serializer(opts);

if (posix.dirname(opts.name) === '.') {
if (posix.dirname(opts.name) !== '.') {
log(NAMESPACED_RESOURCE_MESSAGE);
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/packages/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ export async function compile(
path.join(__dirname, '..', 'src', '**')
]
}),
babel({
exclude: 'node_modules/**'
}),
babel(),
lux(path.resolve(path.sep, dir, 'app'))
]
});
Expand Down
8 changes: 4 additions & 4 deletions src/packages/fs/utils/exists.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import { stat, readdir } from '../index';
import tryCatch from '../../../utils/try-catch';

/**
* @private
Expand All @@ -20,7 +19,8 @@ export default async function exists(
return files.some(file => pattern.test(file));
}

const str = path;

return Boolean(await tryCatch(() => stat(str)));
return stat(path).then(
() => true,
() => false
);
}
37 changes: 21 additions & 16 deletions src/packages/fs/utils/rmrf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@
import path from 'path';

import { stat, rmdir, readdir, unlink } from '../index';
import tryCatch from '../../../utils/try-catch';

/**
* @private
*/
async function rmrf(target: string): Promise<boolean> {
const stats = await tryCatch(() => stat(target));
function rmrf(target: string): Promise<boolean> {
return stat(target)
.then(stats => {
if (stats && stats.isDirectory()) {
return readdir(target);
} else if (stats && stats.isFile()) {
return unlink(target).then(() => []);
}

if (stats && stats.isDirectory()) {
let files = await tryCatch(() => readdir(target));
return [];
})
.then(files => (
Promise.all(files.map(file => rmrf(path.join(target, file))))
))
.then(() => rmdir(target))
.catch(err => {
if (err.code === 'ENOENT') {
return Promise.resolve();
}

if (files) {
files = files.map(file => rmrf(path.join(target, file)));

await Promise.all(files);
await rmdir(target);
}
} else if (stats && stats.isFile()) {
await tryCatch(() => unlink(target));
}

return true;
return Promise.reject(err);
})
.then(() => true);
}

export default rmrf;

0 comments on commit d1c5e8d

Please sign in to comment.