Skip to content

Commit

Permalink
chore(eslint): replaced contentful-backend eslint with standard
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Nov 7, 2019
1 parent 293ddc9 commit 7b9ca70
Show file tree
Hide file tree
Showing 21 changed files with 1,068 additions and 1,012 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@contentful/backend",
"extends": "eslint-config-standard",
"root": true,
"rules": {
"max-len": [
Expand Down
60 changes: 30 additions & 30 deletions bin/commands/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node
// vim: set ft=javascript:

const chalk = require('chalk');
const readline = require('readline');
const path = require('path');
const chalk = require('chalk')
const readline = require('readline')
const path = require('path')

const bootstrap = require('../../lib/bootstrap');
const bootstrap = require('../../lib/bootstrap')

exports.command = 'bootstrap';
exports.command = 'bootstrap'

exports.desc =
'Takes a snapshot of existing space and automatically generate migration scripts';
'Takes a snapshot of existing space and automatically generate migration scripts'

exports.builder = (yargs) => {
yargs
Expand Down Expand Up @@ -49,52 +49,52 @@ exports.builder = (yargs) => {
})
.check((argv) => {
if (argv.a && argv.c.length > 0) {
return 'Arguments \'content-type\' and \'all\' are mutually exclusive';
return 'Arguments \'content-type\' and \'all\' are mutually exclusive'
}
if (!argv.a && argv.c.length === 0) {
return 'At least one of \'all\' or \'content-type\' options must be specified';
return 'At least one of \'all\' or \'content-type\' options must be specified'
}
return true;
});
};
return true
})
}

const isYes = response => response === 'y' || response === 'yes';
const isYes = response => response === 'y' || response === 'yes'

exports.handler = async (args) => {
const {
environmentId,
spaceId,
contentType,
accessToken
} = args;
} = args

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
})

const asyncQuestion = (question) => {
return new Promise((resolve) => {
rl.question(question, (response) => {
resolve(response);
});
});
};
resolve(response)
})
})
}

const migrationsDirectory = path.join('.', 'migrations');
let writeMigrationState = false;
const migrationsDirectory = path.join('.', 'migrations')
let writeMigrationState = false
if (contentType.length > 0) {
const answer = await asyncQuestion(chalk.bold.yellow(`⚠️ Do you want to generate initial migration state for ${contentType}? y/N: `));
writeMigrationState = isYes(answer);
const answer = await asyncQuestion(chalk.bold.yellow(`⚠️ Do you want to generate initial migration state for ${contentType}? y/N: `))
writeMigrationState = isYes(answer)
} else {
const answer = await asyncQuestion(chalk.bold.yellow(`⚠️ Do you want to generate initial migration state for ALL content types? y/N: `));
const answer = await asyncQuestion(chalk.bold.yellow('⚠️ Do you want to generate initial migration state for ALL content types? y/N: '))
if (isYes(answer)) {
console.log(chalk.bold.red('🚨 What you are about to do is destructive!'));
console.log(chalk.bold.red(` It will mutate all migration state for every content type in space ${spaceId}`));
const confirmation = await asyncQuestion(chalk.bold.yellow(`⚠️ Are you sure you want to proceed? y/N: `));
writeMigrationState = isYes(confirmation);
console.log(chalk.bold.red('🚨 What you are about to do is destructive!'))
console.log(chalk.bold.red(` It will mutate all migration state for every content type in space ${spaceId}`))
const confirmation = await asyncQuestion(chalk.bold.yellow('⚠️ Are you sure you want to proceed? y/N: '))
writeMigrationState = isYes(confirmation)
}
}
rl.close();
await bootstrap(spaceId, environmentId, contentType, accessToken, migrationsDirectory, writeMigrationState);
};
rl.close()
await bootstrap(spaceId, environmentId, contentType, accessToken, migrationsDirectory, writeMigrationState)
}
30 changes: 15 additions & 15 deletions bin/commands/create.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node
// vim: set ft=javascript:

const path = require('path');
const chalk = require('chalk');
const log = require('migrate/lib/log');
const generator = require('migrate/lib/template-generator');
const path = require('path')
const chalk = require('chalk')
const log = require('migrate/lib/log')
const generator = require('migrate/lib/template-generator')

exports.command = 'create <name>';
exports.command = 'create <name>'

exports.desc =
'Creates an empty time stamped file in the content-type\'s migrations folder';
'Creates an empty time stamped file in the content-type\'s migrations folder'

exports.builder = (yargs) => {
yargs
Expand All @@ -23,12 +23,12 @@ exports.builder = (yargs) => {
.positional('name', {
describe: 'descriptive name for the migration file',
type: 'string'
});
};
})
}

exports.handler = ({ name, contentType }) => {
const migrationsDirectory = path.join('.', 'migrations', contentType);
const templateFile = path.join(__dirname, '..', '..', 'lib', 'template.js');
const migrationsDirectory = path.join('.', 'migrations', contentType)
const templateFile = path.join(__dirname, '..', '..', 'lib', 'template.js')

generator({
name,
Expand All @@ -38,9 +38,9 @@ exports.handler = ({ name, contentType }) => {
extension: '.js'
}, (error, filename) => {
if (error) {
log(chalk.bold.red(`🚨 Template generation error ${error.message}`));
process.exit(1);
log(chalk.bold.red(`🚨 Template generation error ${error.message}`))
process.exit(1)
}
log('🎉 created', filename);
});
};
log('🎉 created', filename)
})
}
44 changes: 22 additions & 22 deletions bin/commands/down.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node
// vim: set ft=javascript:

const path = require('path');
const runMigrations = require('migrate/lib/migrate');
const log = require('migrate/lib/log');
const load = require('../../lib/load');
const path = require('path')
const runMigrations = require('migrate/lib/migrate')
const log = require('migrate/lib/log')
const load = require('../../lib/load')

exports.command = 'down [file]';
exports.command = 'down [file]'

exports.desc =
'Migrate down to a given migration or just the last one if not specified';
'Migrate down to a given migration or just the last one if not specified'

exports.builder = (yargs) => {
yargs
Expand Down Expand Up @@ -49,8 +49,8 @@ exports.builder = (yargs) => {
.positional('file', {
describe: 'If specified, rollback all migrations scripts down to this one.',
type: 'string'
});
};
})
}

exports.handler = async (args) => {
const {
Expand All @@ -60,33 +60,33 @@ exports.handler = async (args) => {
environmentId,
file,
spaceId
} = args;
} = args

const migrationsDirectory = path.join('.', 'migrations');
const migrationsDirectory = path.join('.', 'migrations')

const processSet = (set) => {
const name = (file) || set.lastRun;
const name = (file) || set.lastRun

runMigrations(set, 'down', name, (error) => {
if (error) {
log('error', error);
process.exit(1);
log('error', error)
process.exit(1)
}

log('migration', 'complete');
process.exit(0);
});
};
log('migration', 'complete')
process.exit(0)
})
}

// Load in migrations
const sets = await load({
migrationsDirectory, spaceId, environmentId, accessToken, dryRun, contentTypes: [contentType]
});
})

sets.forEach(set => set
.then(processSet)
.catch((err) => {
log.error('error', err);
process.exit(1);
}));
};
log.error('error', err)
process.exit(1)
}))
}
14 changes: 7 additions & 7 deletions bin/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
// vim: set ft=javascript:

const { initSpace } = require('../../lib/store');
const { initSpace } = require('../../lib/store')

exports.command = 'init';
exports.command = 'init'

exports.desc =
'Prepares the specified space to allow managed migration scripts.\nThe "Migration" content-type will be created in your contentful space';
'Prepares the specified space to allow managed migration scripts.\nThe "Migration" content-type will be created in your contentful space'

exports.builder = (yargs) => {
yargs
Expand All @@ -31,9 +31,9 @@ exports.builder = (yargs) => {
type: 'string',
requiresArg: true,
default: 'master'
});
};
})
}

exports.handler = async ({ accessToken, spaceId, environmentId }) => {
return initSpace(accessToken, spaceId, environmentId);
};
return initSpace(accessToken, spaceId, environmentId)
}
47 changes: 23 additions & 24 deletions bin/commands/list.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node
// vim: set ft=javascript:

const path = require('path');
const chalk = require('chalk');
const dateFormat = require('dateformat');
const log = require('migrate/lib/log');
const load = require('../../lib/load');
const path = require('path')
const chalk = require('chalk')
const dateFormat = require('dateformat')
const log = require('migrate/lib/log')
const load = require('../../lib/load')

exports.command = 'list';
exports.command = 'list'

exports.desc =
'List all migrations for a given content-type, also indicating whether it was already applied and when';
'List all migrations for a given content-type, also indicating whether it was already applied and when'

exports.builder = (yargs) => {
yargs
Expand Down Expand Up @@ -49,25 +49,25 @@ exports.builder = (yargs) => {
})
.check((argv) => {
if (argv.a && argv.c.length > 0) {
return 'Arguments \'content-type\' and \'all\' are mutually exclusive';
return 'Arguments \'content-type\' and \'all\' are mutually exclusive'
}
if (!argv.a && argv.c.length === 0) {
return 'At least one of \'all\' or \'content-type\' options must be specified';
return 'At least one of \'all\' or \'content-type\' options must be specified'
}
return true;
});
};
return true
})
}

exports.handler = async ({
spaceId, environmentId, contentType, accessToken
}) => {
const migrationsDirectory = path.join('.', 'migrations');
const migrationsDirectory = path.join('.', 'migrations')

const listSet = (set) => {
// eslint-disable-next-line no-console
console.log(chalk.bold.blue('Listing'), set.store.contentTypeID);
console.log(chalk.bold.blue('Listing'), set.store.contentTypeID)
if (set.migrations.length === 0) {
log('list', 'No Migrations');
log('list', 'No Migrations')
}

set.migrations.forEach((migration) => {
Expand All @@ -76,9 +76,9 @@ exports.handler = async ({
? `[${dateFormat(migration.timestamp, 'yyyy-mm-dd HH:mm:ss')}] `
: chalk.bold.yellow('[pending] ')) + chalk.bold.white(migration.title),
migration.description || '<No Description>'
);
});
};
)
})
}

// Load in migrations
const sets = await load({
Expand All @@ -88,13 +88,12 @@ exports.handler = async ({
environmentId,
migrationsDirectory,
spaceId
});
})

sets.forEach(set => set
.then(listSet)
.catch((err) => {
log.error('error', err);
process.exit(1);
}));
};

log.error('error', err)
process.exit(1)
}))
}
Loading

0 comments on commit 7b9ca70

Please sign in to comment.