music-routes-data 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Data/index.js +8 -2
- package/lib/cli/add.js +2 -2
- package/lib/cli/argv.js +3 -6
- package/package.json +1 -1
package/lib/Data/index.js
CHANGED
|
@@ -68,7 +68,13 @@ function Data (options) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
if (!entry._id) {
|
|
71
|
-
|
|
71
|
+
const lastIndex = data[collection].length - 1
|
|
72
|
+
if (lastIndex === -1) {
|
|
73
|
+
entry._id = '1'
|
|
74
|
+
} else {
|
|
75
|
+
const lastId = data[collection][lastIndex]._id
|
|
76
|
+
entry._id = String(Number(lastId) + 1)
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
if (typeof entry._id !== 'string') {
|
|
@@ -128,7 +134,7 @@ function Data (options) {
|
|
|
128
134
|
try {
|
|
129
135
|
collections.forEach(callback)
|
|
130
136
|
} catch (e) {
|
|
131
|
-
return makeReturnValue(this.StatusEnum.ERROR, e.message
|
|
137
|
+
return makeReturnValue(this.StatusEnum.ERROR, e.message)
|
|
132
138
|
}
|
|
133
139
|
return makeReturnValue(this.StatusEnum.OK, '')
|
|
134
140
|
}
|
package/lib/cli/add.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports = function (data, collection,
|
|
2
|
-
return data.create(collection, {
|
|
1
|
+
module.exports = function (data, collection, names) {
|
|
2
|
+
return data.create(collection, { names: [names] })
|
|
3
3
|
}
|
package/lib/cli/argv.js
CHANGED
|
@@ -12,8 +12,9 @@ module.exports = function (argv) {
|
|
|
12
12
|
let rv = {}
|
|
13
13
|
let inputRv
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const defaultDir = path.join(__dirname, '../../data')
|
|
16
|
+
const outputDir = argv.outputDir || argv.o || defaultDir
|
|
17
|
+
const inputDir = argv.inputDir || argv.i || defaultDir
|
|
17
18
|
|
|
18
19
|
const data = new Data()
|
|
19
20
|
|
|
@@ -21,8 +22,6 @@ module.exports = function (argv) {
|
|
|
21
22
|
if (rv.status === data.StatusEnum.OK) {
|
|
22
23
|
if (outputDir) {
|
|
23
24
|
data.write(outputDir)
|
|
24
|
-
} else {
|
|
25
|
-
that.error('No output directory specified. Your data will not be saved.\nUse -o to specify an output directory.')
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -43,8 +42,6 @@ module.exports = function (argv) {
|
|
|
43
42
|
if (inputRv.status === data.StatusEnum.ERROR) {
|
|
44
43
|
this.exit(1)
|
|
45
44
|
}
|
|
46
|
-
} else {
|
|
47
|
-
this.error('No input directory specified. Operating on empty data set.\nUse -i to specify a data directory.')
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
switch (action) {
|