Skip to content

Commit

Permalink
yarn lint:js --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Aug 27, 2020
1 parent 94717b8 commit ab0903b
Show file tree
Hide file tree
Showing 14 changed files with 717 additions and 413 deletions.
206 changes: 119 additions & 87 deletions commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const USAGE_MESSAGE = strip`
To list all available features, run ${chalk.bold('ember feature:list')}.
To enable a feature, run ${chalk.bold('ember feature:enable some-feature')}.
To disable a feature, run ${chalk.bold('ember feature:disable some-feature')}.
To disable a feature, run ${chalk.bold(
'ember feature:disable some-feature'
)}.
`;

const SHARED = {
Expand All @@ -33,7 +35,7 @@ const SHARED = {

try {
return this.project.resolveSync(configPath);
} catch(err) {
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}
Expand All @@ -50,14 +52,24 @@ const SHARED = {
let feature = FEATURES[name];

if (feature === undefined) {
console.log(chalk.red(`Error: ${chalk.bold(name)} is not a valid feature.\n`));
console.log(
chalk.red(`Error: ${chalk.bold(name)} is not a valid feature.\n`)
);
return LIST_FEATURES.run.apply(this);
}

let configPath = this._ensureConfigFile();
let configJSON = JSON.parse(fs.readFileSync(configPath, { encoding: 'UTF-8' }));
let configJSON = JSON.parse(
fs.readFileSync(configPath, { encoding: 'UTF-8' })
);
if (!this._isFeatureAvailable(feature)) {
console.log(chalk.red(`Error: ${chalk.bold(name)} is only available in Ember ${feature.since} or above.`));
console.log(
chalk.red(
`Error: ${chalk.bold(name)} is only available in Ember ${
feature.since
} or above.`
)
);
return;
}

Expand All @@ -67,114 +79,134 @@ const SHARED = {

let config = {};

Object.keys(FEATURES).forEach(feature => {
Object.keys(FEATURES).forEach((feature) => {
if (feature === name) {
config[feature] = value;
} else if(configJSON[feature] !== undefined) {
} else if (configJSON[feature] !== undefined) {
config[feature] = configJSON[feature];
}
});

fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', { encoding: 'UTF-8' });
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', {
encoding: 'UTF-8',
});

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!`));
}
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({
name: 'feature',
description: 'Prints the USAGE.',
works: 'insideProject',
run() {
console.log(USAGE_MESSAGE);
}
}, SHARED);
const USAGE = Object.assign(
{
name: 'feature',
description: 'Prints the USAGE.',
works: 'insideProject',
run() {
console.log(USAGE_MESSAGE);
},
},
SHARED
);

/* This forces strip`` to start counting the indentaiton */
const INDENT_START = '';

const LIST_FEATURES = Object.assign({
name: 'feature:list',
description: 'List all available features.',
works: 'insideProject',
run() {
console.log(USAGE_MESSAGE);
console.log('Available features:');
const LIST_FEATURES = Object.assign(
{
name: 'feature:list',
description: 'List all available features.',
works: 'insideProject',
run() {
console.log(USAGE_MESSAGE);
console.log('Available features:');

let hasFeatures = false;
let hasFeatures = false;

Object.keys(FEATURES).forEach(key => {
let feature = FEATURES[key];
Object.keys(FEATURES).forEach((key) => {
let feature = FEATURES[key];

if (this._isFeatureAvailable(feature)) {
console.log(strip`
if (this._isFeatureAvailable(feature)) {
console.log(strip`
${INDENT_START}
${chalk.bold(key)} ${chalk.cyan(`(Default: ${feature.default})`)}
${feature.description}
${chalk.gray(`More information: ${chalk.underline(feature.url)}`)}`);

hasFeatures = true;
}
});

if (hasFeatures) {
console.log();
} else {
console.log(chalk.gray(strip`
${chalk.gray(
`More information: ${chalk.underline(feature.url)}`
)}`);

hasFeatures = true;
}
});

if (hasFeatures) {
console.log();
} else {
console.log(
chalk.gray(strip`
${INDENT_START}
No optional features available for your current Ember version.
`));
}
}
}, SHARED);

const ENABLE_FEATURE = Object.assign({
name: 'feature:enable',
description: 'Enable feature.',
works: 'insideProject',
availableOptions: [
{
name: 'run-codemod',
type: Boolean,
description: 'run any associated codemods without prompting'
// intentionally not setting a default, when the value is undefined the
// command will prompt the user
`)
);
}
},
],
anonymousOptions: [
'<feature-name>'
],
run(commandOptions, args) {
return this._setFeature(args[0], true, commandOptions.runCodemod);
}
}, SHARED);

const DISABLE_FEATURE = Object.assign({
name: 'feature:disable',
description: 'Disable feature.',
works: 'insideProject',
availableOptions: [
{
name: 'run-codemod',
type: Boolean,
description: 'run any associated codemods without prompting'
// intentionally not setting a default, when the value is undefined the
// command will prompt the user
},
SHARED
);

const ENABLE_FEATURE = Object.assign(
{
name: 'feature:enable',
description: 'Enable feature.',
works: 'insideProject',
availableOptions: [
{
name: 'run-codemod',
type: Boolean,
description: 'run any associated codemods without prompting',
// intentionally not setting a default, when the value is undefined the
// command will prompt the user
},
],
anonymousOptions: ['<feature-name>'],
run(commandOptions, args) {
return this._setFeature(args[0], true, commandOptions.runCodemod);
},
],
anonymousOptions: [
'<feature-name>'
],
run(commandOptions, args) {
return this._setFeature(args[0], false, commandOptions.runCodemod);
}
}, SHARED);
},
SHARED
);

const DISABLE_FEATURE = Object.assign(
{
name: 'feature:disable',
description: 'Disable feature.',
works: 'insideProject',
availableOptions: [
{
name: 'run-codemod',
type: Boolean,
description: 'run any associated codemods without prompting',
// intentionally not setting a default, when the value is undefined the
// command will prompt the user
},
],
anonymousOptions: ['<feature-name>'],
run(commandOptions, args) {
return this._setFeature(args[0], false, commandOptions.runCodemod);
},
},
SHARED
);

module.exports = {
'feature': USAGE,
feature: USAGE,
'feature:list': LIST_FEATURES,
'feature:enable': ENABLE_FEATURE,
'feature:disable': DISABLE_FEATURE
}
'feature:disable': DISABLE_FEATURE,
};
4 changes: 2 additions & 2 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
module.exports = function (/* environment, appConfig */) {
return {};
};
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
// Add options here
});
Expand Down
13 changes: 8 additions & 5 deletions features.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ const path = require('path');
const FEATURES_PATH = path.resolve(__dirname, './features');
const FEATURES = {};

glob.sync('*.js', { cwd: FEATURES_PATH }).sort().forEach(filename => {
let key = filename.slice(0, -3);
let value = Object.assign({}, require(`./features/${key}`));
glob
.sync('*.js', { cwd: FEATURES_PATH })
.sort()
.forEach((filename) => {
let key = filename.slice(0, -3);
let value = Object.assign({}, require(`./features/${key}`));

FEATURES[key] = Object.freeze(value);
});
FEATURES[key] = Object.freeze(value);
});

module.exports = Object.freeze(FEATURES);
31 changes: 22 additions & 9 deletions features/application-template-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const path = require('path');
const strip = require('../utils').strip;

module.exports = {
description: 'Wrap the top-level application template (application.hbs) with a `<div class="ember-view">` element.',
description:
'Wrap the top-level application template (application.hbs) with a `<div class="ember-view">` element.',
url: 'https://github.com/emberjs/rfcs/pull/280',
default: true,
since: '3.1.0',
Expand All @@ -26,7 +27,13 @@ module.exports = {

if (isPod) {
// TODO
console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n`));
console.log(
chalk.yellow(
`${chalk.bold(
'Note:'
)} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n`
)
);
return;
} else {
templatePath = 'app/templates/application.hbs';
Expand All @@ -35,8 +42,10 @@ module.exports = {
let absolutePath = path.join(root, templatePath);

try {
originalContent = await p(fs.readFile)(absolutePath, { encoding: 'UTF-8' });
} catch(err) {
originalContent = await p(fs.readFile)(absolutePath, {
encoding: 'UTF-8',
});
} catch (err) {
if (err.code === 'ENOENT') {
return;
} else {
Expand All @@ -58,7 +67,9 @@ module.exports = {
- Depending on your choice of \`rootElement\`, your app might not be wrapped inside a block-level element anymore.
For more information, see ${chalk.underline('https://github.com/emberjs/rfcs/pull/280')}.
For more information, see ${chalk.underline(
'https://github.com/emberjs/rfcs/pull/280'
)}.
To be very conservative, I could add the \`<div class="ember-view">\` wrapper to your application.hbs. (You can always remove it later.)
`);
Expand All @@ -67,7 +78,7 @@ module.exports = {
type: 'confirm',
name: 'shouldRewrite',
message: 'Would you like me to do that for you?',
default: false
default: false,
});

console.log();
Expand All @@ -93,7 +104,7 @@ module.exports = {

content.push('<div class="ember-view">');

lines.forEach(line => {
lines.forEach((line) => {
content.push(line === '' ? '' : ` ${line}`);
});

Expand All @@ -105,9 +116,11 @@ module.exports = {

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

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

console.log();
}
}
},
};
5 changes: 3 additions & 2 deletions features/default-async-observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
'use strict';

module.exports = {
description: 'Makes all observers asynchronous (unless manually indicated as synchronous when calling addObserver/observes).',
description:
'Makes all observers asynchronous (unless manually indicated as synchronous when calling addObserver/observes).',
url: 'https://github.com/emberjs/rfcs/pull/494',
default: false,
since: '3.13.0'
since: '3.13.0',
};
Loading

0 comments on commit ab0903b

Please sign in to comment.