Skip to content

Commit

Permalink
Remove co.wrap usage in favor of using async/await directly. (#161)
Browse files Browse the repository at this point in the history
Remove co.wrap usage in favor of using async/await directly.
  • Loading branch information
rwjblue authored Dec 18, 2019
2 parents 08f72f3 + c5fe17a commit b34d1f6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
ecmaVersion: 2017
},
env: {
browser: false,
Expand Down
7 changes: 3 additions & 4 deletions commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const VersionChecker = require('ember-cli-version-checker');

const chalk = require('chalk');
const co = require('co');
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
Expand Down Expand Up @@ -47,7 +46,7 @@ const SHARED = {
return configPath;
},

_setFeature: co.wrap(function *(name, value) {
_setFeature: async function (name, value) {
let feature = FEATURES[name];

if (feature === undefined) {
Expand All @@ -63,7 +62,7 @@ const SHARED = {
}

if (typeof feature.callback === 'function') {
yield feature.callback(this.project, value);
await feature.callback(this.project, value);
}

let config = {};
Expand All @@ -81,7 +80,7 @@ const SHARED = {
let state = value ? 'Enabled' : 'Disabled';

console.log(chalk.green(`${state} ${chalk.bold(name)}. Be sure to commit ${chalk.underline('config/optional-features.json')} to source control!`));
})
}
};

const USAGE = Object.assign({
Expand Down
11 changes: 5 additions & 6 deletions features/application-template-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict';

const chalk = require('chalk');
const co = require('co');
const fs = require('fs');
const inquirer = require('inquirer');
const p = require('util.promisify');
Expand All @@ -14,7 +13,7 @@ module.exports = {
url: 'https://github.com/emberjs/rfcs/pull/280',
default: true,
since: '3.1.0',
callback: co.wrap(function *(project, value) {
callback: async function (project, value) {
if (value !== false) {
return;
}
Expand All @@ -36,7 +35,7 @@ module.exports = {
let absolutePath = path.join(root, templatePath);

try {
originalContent = yield p(fs.readFile)(absolutePath, { encoding: 'UTF-8' });
originalContent = await p(fs.readFile)(absolutePath, { encoding: 'UTF-8' });
} catch(err) {
if (err.code === 'ENOENT') {
return;
Expand All @@ -63,7 +62,7 @@ module.exports = {
To be very conservative, I could add the \`<div class="ember-view">\` wrapper to your application.hbs. (You can always remove it later.)
`);

let response = yield inquirer.prompt({
let response = await inquirer.prompt({
type: 'confirm',
name: 'shouldRewrite',
message: 'Would you like me to do that for you?',
Expand Down Expand Up @@ -102,9 +101,9 @@ module.exports = {

console.log(` ${chalk.yellow('overwrite')} ${templatePath}`);

yield p(fs.writeFile)(templatePath, content.join('\n'), { encoding: 'UTF-8' });
await p(fs.writeFile)(templatePath, content.join('\n'), { encoding: 'UTF-8' });

console.log();
}
})
}
};
17 changes: 8 additions & 9 deletions features/template-only-glimmer-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict';

const chalk = require('chalk');
const co = require('co');
const fs = require('fs');
const inquirer = require('inquirer');
const glob = require('glob');
Expand All @@ -26,7 +25,7 @@ module.exports = {
url: 'https://github.com/emberjs/rfcs/pull/278',
default: false,
since: '3.1.0',
callback: co.wrap(function *(project, value) {
callback: async function (project, value) {
if (value !== true) {
return;
}
Expand Down Expand Up @@ -54,7 +53,7 @@ module.exports = {

// Handle "Classic" layout
let templatesRoot = path.join(root, 'app/templates/components');
let templateCandidates = yield p(glob)('**/*.hbs', { cwd: templatesRoot });
let templateCandidates = await p(glob)('**/*.hbs', { cwd: templatesRoot });

templateCandidates.forEach(template => {
let templatePath = path.join('app/templates/components', template);
Expand All @@ -72,7 +71,7 @@ module.exports = {
// Handle "Pods" layout without prefix

let componentsRoot = path.join(root, 'app/components');
templateCandidates = yield p(glob)('**/template.hbs', { cwd: componentsRoot });
templateCandidates = await p(glob)('**/template.hbs', { cwd: componentsRoot });

templateCandidates.forEach(template => {
let templatePath = path.join('app/components', template);
Expand All @@ -90,7 +89,7 @@ module.exports = {
// Handle "Pods" layout *with* prefix

componentsRoot = path.join(root, `app/${podsFolder}/components`);
templateCandidates = yield p(glob)('**/template.hbs', { cwd: componentsRoot });
templateCandidates = await p(glob)('**/template.hbs', { cwd: componentsRoot });

templateCandidates.forEach(template => {
let templatePath = path.join(`app/${podsFolder}/components`, template);
Expand Down Expand Up @@ -138,7 +137,7 @@ module.exports = {
`);
}

let response = yield inquirer.prompt({
let response = await inquirer.prompt({
type: 'confirm',
name: 'shouldGenerate',
message: 'Would you like me to generate these component files for you?',
Expand All @@ -152,11 +151,11 @@ module.exports = {
let componentPath = components[i];
console.log(` ${chalk.green('create')} ${componentPath}`);
let absolutePath = path.join(project.root, componentPath);
yield p(mkdirp)(path.dirname(absolutePath));
yield p(fs.writeFile)(absolutePath, ComponentFile, { encoding: 'UTF-8' });
await p(mkdirp)(path.dirname(absolutePath));
await p(fs.writeFile)(absolutePath, ComponentFile, { encoding: 'UTF-8' });
}

console.log();
}
})
}
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"dependencies": {
"chalk": "^3.0.0",
"co": "^4.6.0",
"ember-cli-version-checker": "^3.1.3",
"glob": "^7.1.6",
"inquirer": "^7.0.1",
Expand Down
Loading

0 comments on commit b34d1f6

Please sign in to comment.