Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 6a1a379

Browse files
committed
Linting
License: MIT Signed-off-by: Adam Uhlir <[email protected]>
1 parent d9311b0 commit 6a1a379

File tree

8 files changed

+44
-42
lines changed

8 files changed

+44
-42
lines changed

src/cli.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const log = require('debug')('js-ipfs-repo-migrations:cli')
99

1010
const commands = require('./commands')
1111

12-
13-
function print(msg, newline) {
12+
function print (msg, newline) {
1413
if (newline === undefined) {
1514
newline = true
1615
}
@@ -22,11 +21,11 @@ function print(msg, newline) {
2221
process.stdout.write(msg)
2322
}
2423

25-
async function main(args) {
24+
async function main (args) {
2625
const cli = yargs()
2726
.option('repo-path', {
2827
desc: 'Path to the IPFS repo',
29-
type: 'string',
28+
type: 'string'
3029
})
3130
.command(commands.migrate)
3231
.command(commands.revert)
@@ -49,7 +48,7 @@ async function main(args) {
4948
let exitCode = 0
5049

5150
try {
52-
const {data} = await new YargsPromise(cli).parse(args)
51+
const { data } = await new YargsPromise(cli).parse(args)
5352
if (data) print(data)
5453
} catch (err) {
5554
log(err)

src/commands.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const os = require('os')
44
const path = require('path')
55
const fs = require('fs')
66
const process = require('process')
7-
const util = require('util');
7+
const util = require('util')
88

99
const writeFile = util.promisify(fs.writeFile)
1010
const mkdir = util.promisify(fs.mkdir)
11-
const exec = util.promisify(require('child_process').exec);
11+
const exec = util.promisify(require('child_process').exec)
1212

1313
const chalk = require('chalk')
1414

@@ -17,28 +17,28 @@ const migrator = require('./index')
1717
const templates = require('./migration-templates')
1818
const migrations = require('../migrations')
1919

20-
function asyncClosure(fnc) {
21-
return function asyncWrapper({resolve, ...options}) {
20+
function asyncClosure (fnc) {
21+
return function asyncWrapper ({ resolve, ...options }) {
2222
resolve(fnc(options))
2323
}
2424
}
2525

26-
function reportingClosure(action) {
26+
function reportingClosure (action) {
2727
return (migration, currentlyMigrated, totalToMigrate) =>
2828
process.stdout.write(`${chalk.green(`[${currentlyMigrated}/${totalToMigrate}]`)} Successfully ${action} ${chalk.bold(migration.version)}: ${migration.description}\n`)
2929
}
3030

31-
async function migrate({repoPath, ver, dry}) {
31+
async function migrate ({ repoPath, ver, dry }) {
3232
repoPath = repoPath || process.env.IPFS_PATH || path.join(os.homedir(), '.jsipfs')
3333
await migrator.migrate(repoPath, ver, reportingClosure(dry ? 'loaded migration' : 'migrated to version'), dry)
3434
}
3535

36-
async function revert({repoPath, ver, dry}) {
36+
async function revert ({ repoPath, ver, dry }) {
3737
repoPath = repoPath || process.env.IPFS_PATH || path.join(os.homedir(), '.jsipfs')
3838
await migrator.revert(repoPath, ver, reportingClosure(dry ? 'loaded migration' : 'reverted to version'), dry)
3939
}
4040

41-
async function status({repoPath}) {
41+
async function status ({ repoPath }) {
4242
repoPath = repoPath || process.env.IPFS_PATH || path.join(os.homedir(), '.jsipfs')
4343

4444
const version = await repoVersion.getVersion(repoPath)
@@ -49,17 +49,17 @@ async function status({repoPath}) {
4949
return `${statusString}\nCurrent repo version: ${version}\nLast migration's version: ${lastMigrationVersion}`
5050
}
5151

52-
async function getAuthor() {
52+
async function getAuthor () {
5353
try {
54-
const name = (await exec('git config --get user.name'))['stdout']
55-
const email = (await exec('git config --get user.email'))['stdout']
54+
const name = (await exec('git config --get user.name')).stdout
55+
const email = (await exec('git config --get user.email')).stdout
5656
return `${name.replace('\n', '')} <${email.replace('\n', '')}>`
5757
} catch (e) {
5858
return ''
5959
}
6060
}
6161

62-
async function add({repoPath, empty}) {
62+
async function add ({ repoPath, empty }) {
6363
const newMigrationVersion = migrator.getLatestMigrationVersion() + 1
6464
const newMigrationFolder = path.join(__dirname, '..', 'migrations', 'migration-' + newMigrationVersion)
6565

@@ -71,7 +71,7 @@ async function add({repoPath, empty}) {
7171
}
7272
const migrationsIndexJsContent = templates.migrationsIndexJs
7373
.replace('{{imports}}', migrationsImport.join('\n'))
74-
;await writeFile(path.join(newMigrationFolder, '..', 'index.js'), migrationsIndexJsContent)
74+
await writeFile(path.join(newMigrationFolder, '..', 'index.js'), migrationsIndexJsContent)
7575

7676
if (empty) return
7777

@@ -80,11 +80,11 @@ async function add({repoPath, empty}) {
8080
const packageJsonContent = templates.packageJson
8181
.replace(/{{version}}/gi, newMigrationVersion)
8282
.replace(/{{author}}/gi, await getAuthor())
83-
;await writeFile(path.join(newMigrationFolder, 'package.json'), packageJsonContent)
83+
await writeFile(path.join(newMigrationFolder, 'package.json'), packageJsonContent)
8484

8585
const indexJsContent = templates.indexJs
8686
.replace(/{{version}}/gi, newMigrationVersion)
87-
;await writeFile(path.join(newMigrationFolder, 'index.js'), indexJsContent)
87+
await writeFile(path.join(newMigrationFolder, 'index.js'), indexJsContent)
8888
}
8989

9090
module.exports = {
@@ -114,12 +114,12 @@ module.exports = {
114114
.positional('ver', {
115115
describe: 'version to revert to (inclusive)',
116116
type: 'number'
117-
}),
117+
})
118118
},
119119
status: {
120120
command: 'status',
121121
describe: 'Display status of IPFS repo',
122-
handler: asyncClosure(status),
122+
handler: asyncClosure(status)
123123
},
124124
add: {
125125
command: 'add',
@@ -130,5 +130,5 @@ module.exports = {
130130
describe: 'Creates empty migration',
131131
type: 'boolean'
132132
})
133-
},
133+
}
134134
}

src/index.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const debug = require('debug')
99

1010
const log = debug('js-ipfs-repo-migrations:migrator')
1111

12-
1312
/**
1413
* Returns the version of latest migration.
1514
*
1615
* @returns {int}
1716
*/
18-
function getLatestMigrationVersion() {
17+
function getLatestMigrationVersion () {
1918
return migrations[migrations.length - 1].version
2019
}
20+
2121
exports.getLatestMigrationVersion = getLatestMigrationVersion
2222

2323
/**
@@ -32,7 +32,7 @@ exports.getLatestMigrationVersion = getLatestMigrationVersion
3232
* @param {boolean|undefined} isDryRun - Allows to simulate the execution of the migrations without any effect.
3333
* @returns {Promise<void>}
3434
*/
35-
async function migrate(path, toVersion, progressCb, isDryRun) {
35+
async function migrate (path, toVersion, progressCb, isDryRun) {
3636
if (toVersion && (!Number.isInteger(toVersion) || toVersion <= 0)) {
3737
throw new Error('Version has to be positive integer!')
3838
}
@@ -47,7 +47,8 @@ async function migrate(path, toVersion, progressCb, isDryRun) {
4747
log('Nothing to migrate, skipping migrations.')
4848
return
4949
}
50-
let counter = 0, totalMigrations = toVersion - currentVersion
50+
let counter = 0
51+
let totalMigrations = toVersion - currentVersion
5152
for (let migration of migrations) {
5253
if (toVersion !== undefined && migration.version > toVersion) {
5354
break
@@ -74,6 +75,7 @@ async function migrate(path, toVersion, progressCb, isDryRun) {
7475

7576
if (!isDryRun) await lock.close()
7677
}
78+
7779
exports.migrate = migrate
7880

7981
/**
@@ -88,7 +90,7 @@ exports.migrate = migrate
8890
* @param {boolean|undefined} isDryRun - Allows to simulate the execution of the reversion without any effect.
8991
* @returns {Promise<void>}
9092
*/
91-
async function revert(path, toVersion, progressCb, isDryRun) {
93+
async function revert (path, toVersion, progressCb, isDryRun) {
9294
if (!toVersion) {
9395
throw new Error('When reverting migrations, you have to specify to which version to revert!')
9496
}
@@ -103,14 +105,15 @@ async function revert(path, toVersion, progressCb, isDryRun) {
103105
return
104106
}
105107

106-
let {reversible, problematicMigration} = verifyReversibility(currentVersion, toVersion)
108+
let { reversible, problematicMigration } = verifyReversibility(currentVersion, toVersion)
107109
if (!reversible) {
108110
throw new errors.NonReversibleMigration(`Migration version ${problematicMigration} is not possible to revert! Cancelling reversion.`)
109111
}
110112

111113
let lock
112114
if (!isDryRun) lock = await repoLock.lock(currentVersion, path)
113-
let counter = 0, totalMigrations = currentVersion - toVersion
115+
let counter = 0
116+
let totalMigrations = currentVersion - toVersion
114117
const reversedMigrationArray = migrations.reverse()
115118
for (let migration of reversedMigrationArray) {
116119
if (migration.version <= toVersion) {
@@ -138,6 +141,7 @@ async function revert(path, toVersion, progressCb, isDryRun) {
138141

139142
if (!isDryRun) await lock.close()
140143
}
144+
141145
exports.revert = revert
142146

143147
/**
@@ -147,17 +151,17 @@ exports.revert = revert
147151
* @param {int} toVersion
148152
* @returns {object}
149153
*/
150-
function verifyReversibility(fromVersion, toVersion) {
154+
function verifyReversibility (fromVersion, toVersion) {
151155
const reversedMigrationArray = migrations.reverse()
152156
for (let migration of reversedMigrationArray) {
153157
if (migration.version <= toVersion) {
154158
break
155159
}
156160

157161
if (migration.version <= fromVersion && !migration.reversible) {
158-
return {reversible: false, version: migration.version}
162+
return { reversible: false, version: migration.version }
159163
}
160164
}
161165

162-
return {reversible: true, version: undefined}
166+
return { reversible: true, version: undefined }
163167
}

src/option-browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
'use strict'
2-
exports = true
2+
module.exports = true

src/option-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
'use strict'
2-
exports = false
2+
module.exports = false

src/repo/lock-memory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const LOCKS = {}
1414
* @param {string} dir
1515
* @returns {Promise<Object>}
1616
*/
17-
exports.lock = async function lock(version, dir) {
17+
exports.lock = async function lock (version, dir) {
1818
const file = dir + '/' + lockFile
1919
log('locking %s', file)
2020

@@ -24,7 +24,7 @@ exports.lock = async function lock(version, dir) {
2424

2525
LOCKS[file] = true
2626
return {
27-
close() {
27+
close () {
2828
if (LOCKS[file]) {
2929
log('releasing lock %s', file)
3030
delete LOCKS[file]

src/repo/lock.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const STALE_TIME = 20000
2626
* @returns {Promise<Object>}
2727
*/
2828
exports.lock = async (version, dir) => {
29-
3029
const file = path.join(dir, lockFile)
3130
log('locking %s', file)
3231
const release = await lock(dir, { lockfilePath: file, stale: STALE_TIME })

src/repo/version.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ exports.getVersion = getVersion
1717
* @param {string} path
1818
* @returns {Promise<int>}
1919
*/
20-
async function getVersion(path) {
21-
const store = new Datastore(path, {extension: '', createIfMissing: false})
20+
async function getVersion (path) {
21+
const store = new Datastore(path, { extension: '', createIfMissing: false })
2222
await store.open()
2323

2424
if (!await store.has(versionKey)) {
@@ -38,8 +38,8 @@ async function getVersion(path) {
3838
* @param {int} version
3939
* @returns {Promise<void>}
4040
*/
41-
async function setVersion(path, version) {
42-
const store = new Datastore(path, {extension: '', createIfMissing: false})
41+
async function setVersion (path, version) {
42+
const store = new Datastore(path, { extension: '', createIfMissing: false })
4343
await store.open()
4444
await store.put(versionKey, Buffer.from(String(version)))
4545
await store.close()

0 commit comments

Comments
 (0)