Skip to content

refactor: code style optimizations #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
]
},
"dependencies": {
"@auto-it/released": "^9.40.5",
"@babel/plugin-proposal-decorators": "^7.13.5",
"@babel/plugin-syntax-jsx": "^7.12.13",
"auto": "^9.40.5",
"babel-eslint": "^10.0.2",
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.0",
"lerna": "3.17.0",
"auto": "^9.40.5",
"@auto-it/released": "^9.40.5",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function exportPatterns(config) {
);
});

archive.on('error', function(err) {
archive.on('error', function (err) {
throw new TypeError(
`export: An error occured during zipping the patterns: ${err}`
);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const ask = inquirer.prompt;
* @param {object} options - Options passed in from CLI
* @param {boolean} options.force - Flag whether to force install in existing project directory. May overwrite stuff.
*/
const init = options =>
wrapsAsync(function*() {
const init = (options) =>
wrapsAsync(function* () {
/**
* @property {string} project_root="./" - Path to the project root directory
* @property {string|Symbol} edition - The name of the edition npm package or a Symbol for no install
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/cli-actions/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const buildPatterns = require('../build');
const resolveConfig = require('../resolve-config');
const { error, info, wrapAsync } = require('../utils');

const build = options =>
wrapAsync(function*() {
const build = (options) =>
wrapAsync(function* () {
try {
const config = yield resolveConfig(options.parent.config);
yield buildPatterns(config, options);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/bin/cli-actions/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const writeJsonAsync = require('../utils').writeJsonAsync;
* @desc Handles deactivation of starterkits/plugins
* @param {object} options
*/
const enable = options =>
wrapAsync(function*() {
const enable = (options) =>
wrapAsync(function* () {
const {
parent: { config: configPath },
plugins,
Expand All @@ -24,7 +24,7 @@ const enable = options =>
spinner.succeed(
`⊙ patternlab → Disable following plugins: ${plugins.join(', ')}`
);
plugins.map(plugin => {
plugins.map((plugin) => {
if (_.has(config, `plugins[${plugin}]`)) {
_.set(config, `plugins[${plugin}]['enabled']`, false);
spinner.succeed(
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/bin/cli-actions/enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const writeJsonAsync = require('../utils').writeJsonAsync;
* @desc Handles activation of starterkits/plugins
* @param {object} options
*/
const enable = options =>
wrapAsync(function*() {
const enable = (options) =>
wrapAsync(function* () {
const {
parent: { config: configPath },
plugins,
Expand All @@ -24,7 +24,7 @@ const enable = options =>
spinner.succeed(
`⊙ patternlab → Enable following plugins: ${plugins.join(', ')}`
);
plugins.map(plugin => {
plugins.map((plugin) => {
if (_.has(config, `plugins[${plugin}]`)) {
_.set(config, `plugins[${plugin}]['enabled']`, true);
spinner.succeed(`⊙ patternlab → Enabled following plugin: ${plugin}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/cli-actions/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const archive = require('../archive');
const resolveConfig = require('../resolve-config');
const wrapAsync = require('../utils').wrapAsync;

const _export = options =>
wrapAsync(function*() {
const _export = (options) =>
wrapAsync(function* () {
const config = yield resolveConfig(options.parent.config);
archive(config);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/cli-actions/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const defaultPatternlabConfig = patternlab.getDefaultConfig();
// https://github.com/TehShrike/deepmerge#overwrite-array
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;

const init = options =>
wrapAsync(function*() {
const init = (options) =>
wrapAsync(function* () {
const sourceDir = 'source';
const publicDir = 'public';
const exportDir = 'pattern_exports';
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/bin/cli-actions/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const writeJsonAsync = require('../utils').writeJsonAsync;
* @desc Handles async install and activation of starterkits/plugins
* @param {object} options
*/
const install = options =>
wrapAsync(function*() {
const install = (options) =>
wrapAsync(function* () {
const config = yield resolveConfig(options.parent.config);

const spinner = ora(
Expand All @@ -21,8 +21,8 @@ const install = options =>

if (options.starterkits && Array.isArray(options.starterkits)) {
const starterkits = yield Promise.all(
options.starterkits.map(starterkit =>
wrapAsync(function*() {
options.starterkits.map((starterkit) =>
wrapAsync(function* () {
spinner.text = `⊙ patternlab → Installing starterkit: ${starterkit}`;
return yield installStarterkit(
{
Expand All @@ -42,8 +42,8 @@ const install = options =>
}
if (options.plugins && Array.isArray(options.plugins)) {
const plugins = yield Promise.all(
options.plugins.map(plugin =>
wrapAsync(function*() {
options.plugins.map((plugin) =>
wrapAsync(function* () {
return yield installPlugin(
{
name: plugin,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/bin/cli-actions/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const resolveConfig = require('../resolve-config');
const servePatterns = require('../serve');
const wrapAsync = require('../utils').wrapAsync;

const serve = options =>
wrapAsync(function*() {
const serve = (options) =>
wrapAsync(function* () {
const config = yield resolveConfig(options.parent.config);
servePatterns(config, options);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/inquiries/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const editionSetup = [
value: false,
},
],
default: function() {
default: function () {
return {
name: 'Handlebars',
value: '@pattern-lab/edition-node',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/install-edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
const installEdition = (edition, config, projectDir) => {
const pkg = require(path.resolve(projectDir, 'package.json'));

return wrapAsync(function*() {
return wrapAsync(function* () {
/**
* 1. Trigger edition install
* 2. Copy over the mandatory edition files to sourceDir
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/install-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { checkAndInstallPackage, wrapAsync } = require('./utils');
const { resolveFileInPackage } = require('@pattern-lab/core/src/lib/resolver');

const installPlugin = (plugin, config) =>
wrapAsync(function*() {
wrapAsync(function* () {
const name = plugin.name || plugin;
yield checkAndInstallPackage(name);
// Put the installed plugin in the patternlab-config.json
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/install-starterkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
} = require('@pattern-lab/core/src/lib/resolver');

const installStarterkit = (starterkit, config) =>
wrapAsync(function*() {
wrapAsync(function* () {
const sourceDir = config.paths.source.root;
const name = starterkit.value || starterkit;
yield checkAndInstallPackage(name);
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/bin/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const { error, log } = require('./utils');
const pkg = require('../package.json');

// Register info and error logging
log.on('patternlab.error', err => console.log(err)); // eslint-disable-line
log.on('patternlab.info', msg => console.log(msg)); // eslint-disable-line
log.on('patternlab.error', (err) => console.log(err)); // eslint-disable-line
log.on('patternlab.info', (msg) => console.log(msg)); // eslint-disable-line

// Conditionally register verbose logging
const verboseLogs = () => log.on('patternlab.debug', msg => console.log(msg)); // eslint-disable-line
const verboseLogs = () => log.on('patternlab.debug', (msg) => console.log(msg)); // eslint-disable-line

// Conditionally unregister all logging
const silenceLogs = () => {
Expand All @@ -30,7 +30,7 @@ const silenceLogs = () => {
};

// Split strings into an array
const list = val => val.split(',');
const list = (val) => val.split(',');

/**
* Hook up cli version, usage and options
Expand All @@ -42,7 +42,7 @@ cli
.option(
'-c, --config <path>',
'Specify config file. Default looks up the project dir',
val => val.trim(),
(val) => val.trim(),
path.resolve(process.cwd(), 'patternlab-config.json')
)
.option('-v, --verbose', 'Show verbose console logs', verboseLogs)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const wrapAsync = require('./utils').wrapAsync;
* @return {object|boolean} Returns the config object or false otherwise.
*/
function resolveConfig(configPath) {
return wrapAsync(function*() {
return wrapAsync(function* () {
if (typeof configPath !== 'string') {
error(
'resolveConfig: If configPath is set, it is expected to be of type string.'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const mkdirsAsync = require('./utils').mkdirsAsync;
* @return {void}
*/
const scaffold = (projectDir, sourceDir, publicDir, exportDir) =>
wrapAsync(function*() {
wrapAsync(function* () {
const projectPath = path.join(process.cwd(), projectDir);
if (!fs.existsSync(path.join(projectPath, 'package.json'))) {
fs.ensureDirSync(projectPath);
Expand Down
22 changes: 10 additions & 12 deletions packages/cli/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const error = log.error.bind(log);
* @desc Wraps an generator function to yield out promisified stuff
* @param {function} fn - Takes a generator function
*/
const wrapAsync = fn =>
const wrapAsync = (fn) =>
new Promise((resolve, reject) => {
const generator = fn();
/* eslint-disable */
Expand All @@ -84,9 +84,7 @@ const wrapAsync = fn =>
if (res.done) {
return resolve(v);
}
Promise.resolve(v)
.then(spwn)
.catch(spwn);
Promise.resolve(v).then(spwn).catch(spwn);
})();
/* eslint-enable */
});
Expand Down Expand Up @@ -114,13 +112,13 @@ const asyncGlob = (pattern, opts) =>
* @return {Promise}
*/
const copyWithPattern = (cwd, pattern, dest) =>
wrapAsync(function*() {
wrapAsync(function* () {
const files = yield asyncGlob(pattern, { cwd: cwd });
if (files.length === 0) {
debug('copy: Nothing to copy');
}
// Copy concurrently
const promises = files.map(file =>
const promises = files.map((file) =>
fs.copy(path.join(cwd, file), path.join(dest, file))
);
return yield Promise.all(promises);
Expand All @@ -131,8 +129,8 @@ const copyWithPattern = (cwd, pattern, dest) =>
* @desc Fetches packages from an npm package registry and adds a reference in the package.json under dependencies
* @param {string} packageName - The package name
*/
const fetchPackage = packageName =>
wrapAsync(function*() {
const fetchPackage = (packageName) =>
wrapAsync(function* () {
const useYarn = hasYarn();
const pm = useYarn ? 'yarn' : 'npm';
const installCmd = useYarn ? 'add' : 'install';
Expand All @@ -159,8 +157,8 @@ const fetchPackage = packageName =>
* @param {string} packageName - The package name
* @return {boolean}
*/
const checkAndInstallPackage = packageName =>
wrapAsync(function*() {
const checkAndInstallPackage = (packageName) =>
wrapAsync(function* () {
try {
resolvePackageFolder(packageName);
return true;
Expand All @@ -186,7 +184,7 @@ const noop = () => {};
* @param {object} data
*/
const writeJsonAsync = (filePath, data) =>
wrapAsync(function*() {
wrapAsync(function* () {
yield fs.outputJSON(filePath, data, { spaces: 2 });
});

Expand All @@ -198,7 +196,7 @@ const writeJsonAsync = (filePath, data) =>
* @param {object} fileName - the filePath of the JSON
*/
const getJSONKey = (packageName, key, fileName = 'package.json') =>
wrapAsync(function*() {
wrapAsync(function* () {
yield checkAndInstallPackage(packageName);
const jsonData = yield fs.readJson(
resolveFileInPackage(packageName, fileName)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const build = proxyquire('../bin/build', {
});
const opts = { patternsOnly: true };

tap.test('Build ->', t => {
tap.test('Build ->', (t) => {
t.throws(
() => {
build();
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/cli-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const wrapAsync = require('../bin/utils').wrapAsync;

const projectRoot = getUniqueProjectPath();

tap.test('Init and build ->', t =>
wrapAsync(function*() {
tap.test('Init and build ->', (t) =>
wrapAsync(function* () {
yield spawnCmd([
'init',
'--verbose',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/cli-disable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const wrapAsync = require('../bin/utils').wrapAsync;

const projectRoot = getUniqueProjectPath();

tap.test('Disable ->', t =>
wrapAsync(function*() {
tap.test('Disable ->', (t) =>
wrapAsync(function* () {
yield spawnCmd([
'init',
'--verbose',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/cli-enable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const wrapAsync = require('../bin/utils').wrapAsync;

const projectRoot = getUniqueProjectPath();

tap.test('Enable ->', t =>
wrapAsync(function*() {
tap.test('Enable ->', (t) =>
wrapAsync(function* () {
yield spawnCmd([
'init',
'--verbose',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/cli-export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const wrapAsync = require('../bin/utils').wrapAsync;

const projectRoot = getUniqueProjectPath();

tap.test('Init and export ->', t =>
wrapAsync(function*() {
tap.test('Init and export ->', (t) =>
wrapAsync(function* () {
yield spawnCmd([
'init',
'--verbose',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/cli-init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const wrapAsync = require('../bin/utils').wrapAsync;

const projectRoot = getUniqueProjectPath();

tap.test('Init ->', t =>
wrapAsync(function*() {
tap.test('Init ->', (t) =>
wrapAsync(function* () {
yield spawnCmd([
'init',
'--verbose',
Expand Down
Loading