Skip to content

Commit

Permalink
Merge pull request #247 from emberjs/add-prettier-enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Aug 27, 2020
2 parents 6fe91cb + ab0903b commit 296829e
Show file tree
Hide file tree
Showing 18 changed files with 761 additions and 420 deletions.
15 changes: 8 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ module.exports = {
plugins: ['node'],
extends: [
'eslint:recommended',
'plugin:node/recommended'
'plugin:node/recommended',
'plugin:prettier/recommended',
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2017
ecmaVersion: 2017,
},
env: {
browser: false,
node: true
node: true,
},
overrides: [
// test files
{
files: ['tests/**/*.js'],
env: {
qunit: true
}
}
]
qunit: true,
},
},
],
};
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
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);
Loading

0 comments on commit 296829e

Please sign in to comment.