Skip to content

Commit b3586f0

Browse files
committed
Cleanup migrate-legacy-resources tool
1 parent 8006db3 commit b3586f0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

bin/lib/migrateLegacyResources.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const fs = require('fs')
22
const Path = require('path')
33
const promisify = require('util').promisify
4+
const readdir = promisify(fs.readdir)
5+
const lstat = promisify(fs.lstat)
6+
const rename = promisify(fs.rename)
47

58
/* Converts the old (pre-5.0.0) extensionless files to $-based files _with_ extensions
69
* to make them work in the new resource mapper (post-5.0.0).
@@ -11,9 +14,9 @@ module.exports = function (program) {
1114
program
1215
.command('migrate-legacy-resources')
1316
.option('-p, --path <path>', 'Path to the data folder, defaults to \'data/\'')
14-
.option('-s, --suffix <path>', 'The suffix to add, defaults to \'$.ttl\'')
17+
.option('-s, --suffix <path>', 'The suffix to add to extensionless files, defaults to \'$.ttl\'')
1518
.option('-v, --verbose', 'Path to the data folder')
16-
.description('Migrate extensionless data files pre-5.0.0 to turtle-based data files post-5.0.0')
19+
.description('Migrate the data folder from node-solid-server 4 to node-solid-server 5')
1720
.action(async (opts) => {
1821
const verbose = opts.verbose
1922
const suffix = opts.suffix || '$.ttl'
@@ -31,17 +34,17 @@ module.exports = function (program) {
3134
}
3235

3336
async function migrate (path, suffix, verbose) {
34-
const files = await promisify(fs.readdir)(path)
37+
const files = await readdir(path)
3538
for (const file of files) {
3639
const fullFilePath = Path.join(path, file)
37-
const stat = await promisify(fs.lstat)(fullFilePath)
40+
const stat = await lstat(fullFilePath)
3841
if (stat.isFile()) {
3942
if (shouldMigrateFile(file)) {
4043
const newFullFilePath = getNewFileName(fullFilePath, suffix)
4144
if (verbose) {
4245
console.log(`${fullFilePath}\n => ${newFullFilePath}`)
4346
}
44-
await promisify(fs.rename)(fullFilePath, newFullFilePath)
47+
await rename(fullFilePath, newFullFilePath)
4548
}
4649
} else {
4750
if (shouldMigrateFolder(file)) {
@@ -60,5 +63,5 @@ function shouldMigrateFile (filename) {
6063
}
6164

6265
function shouldMigrateFolder (foldername) {
63-
return foldername.indexOf('.') !== 0
66+
return foldername[0] !== '.'
6467
}

0 commit comments

Comments
 (0)