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

Commit

Permalink
fix: update add command
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Jul 29, 2019
1 parent 6996b6f commit edc7530
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
18 changes: 1 addition & 17 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const util = require('util')

const writeFile = util.promisify(fs.writeFile)
const mkdir = util.promisify(fs.mkdir)
const exec = util.promisify(require('child_process').exec)

const chalk = require('chalk')

Expand Down Expand Up @@ -88,21 +87,11 @@ async function status ({ repoPath, migrations }) {
return `${statusString}\nCurrent repo version: ${version}\nLatest migration version: ${lastMigrationVersion}`
}

async function getAuthor () {
try {
const name = (await exec('git config --get user.name')).stdout
const email = (await exec('git config --get user.email')).stdout
return `${name.replace('\n', '')} <${email.replace('\n', '')}>`
} catch (e) {
return ''
}
}

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

const migrationsImport = migrations.map((migration) => migration.empty ? ` Object.assign({version: ${migration.version}}, emptyMigration),` : ` require('./migration-${migration.version}'),`)
const migrationsImport = migrations.map((migration) => migration.empty ? ` Object.assign({version: ${parseInt(migration.version)}}, emptyMigration),` : ` require('./migration-${parseInt(migration.version)}'),`)
if (empty) {
migrationsImport.push(` Object.assign({version: ${newMigrationVersion}}, emptyMigration),`)
} else {
Expand All @@ -116,11 +105,6 @@ async function add ({ empty }) {

await mkdir(newMigrationFolder)

const packageJsonContent = templates.packageJson
.replace(/{{version}}/gi, newMigrationVersion)
.replace(/{{author}}/gi, await getAuthor())
await writeFile(path.join(newMigrationFolder, 'package.json'), packageJsonContent)

const indexJsContent = templates.indexJs
.replace(/{{version}}/gi, newMigrationVersion)
await writeFile(path.join(newMigrationFolder, 'index.js'), indexJsContent)
Expand Down
21 changes: 1 addition & 20 deletions src/migration-templates.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
'use strict'

module.exports = {
packageJson: `{
"name": "ipfs-repo-migration-{{version}}",
"version": "0.1.0",
"description": "Migration",
"author": "{{author}}",
"main": "index.js",
"files": [
"index.js",
"node_modules"
],
"engines": {
"node": ">=10.0.0",
"npm": ">=3.0.0"
},
"dependencies": {
},
"license": "MIT"
}`,

indexJs: `'use strict'
const Datastore = require('datastore-fs')
Expand All @@ -41,7 +22,7 @@ async function revert(repoPath, options, isBrowser) {
store.open()
try {
// Your reversion of migration (if supported)
// Your reversion of migration (if supported, if not delete this function!!!)
} finally {
await store.close()
}
Expand Down

0 comments on commit edc7530

Please sign in to comment.