Skip to content

Commit

Permalink
fix(cli): move index generation to artifact-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
virkt25 committed May 26, 2018
1 parent de1f6f7 commit 81ed77a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 4 additions & 3 deletions packages/cli/generators/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ArtifactGenerator = require('../../lib/artifact-generator');
const debug = require('../../lib/debug')('controller-generator');
const inspect = require('util').inspect;
const path = require('path');
const chalk = require('chalk');
const utils = require('../../lib/utils');

// Exportable constants
Expand Down Expand Up @@ -221,8 +222,8 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
return;
}

end() {
super.end();
async end() {
await super.end();
if (this.shouldExit()) return false;
// logs a message if there is no file conflict
if (
Expand All @@ -235,7 +236,7 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
'Controller %s is now created in src/controllers/',
this.artifactInfo.name,
);
super.updateIndexFile();
this.log();
}
}
};
24 changes: 15 additions & 9 deletions packages/cli/lib/artifact-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
const BaseGenerator = require('./base-generator');
const debug = require('./debug')('artifact-generator');
const utils = require('./utils');
const index = require('./make-index');
const makeIndex = require('./make-index');
const path = require('path');
const chalk = require('chalk');
const StatusConflicter = utils.StatusConflicter;

module.exports = class ArtifactGenerator extends BaseGenerator {
Expand Down Expand Up @@ -105,15 +106,20 @@ module.exports = class ArtifactGenerator extends BaseGenerator {
);
}

async updateIndexFile() {
await index(this.artifactInfo.outDir, {
prefix: `.${this.artifactInfo.type}`,
async end() {
const success = super.end();
if (!success) return false;

// Update `index.ts`
await makeIndex(this.artifactInfo.outDir, {
prefix: `${this.artifactInfo.type}`,
});
this.log(
`UPDATED ${path.relative(
this.destinationPath(),
this.artifactInfo.outDir,
)}/index.ts`,

const relPath = path.relative(
this.destinationPath(),
this.artifactInfo.outDir,
);
this.log(chalk.green(' update'), `${relPath}/index.ts`);
return true;
}
};

0 comments on commit 81ed77a

Please sign in to comment.