@sequencemedia/music-library 1.0.3 → 1.0.7
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/.husky/post-commit +4 -0
- package/.husky/pre-commit +4 -0
- package/app.mjs +58 -47
- package/build/gulp/common.mjs +141 -0
- package/build/gulp/post-commit.mjs +21 -0
- package/build/gulp/pre-commit.mjs +40 -0
- package/gulpfile.mjs +13 -0
- package/package.json +16 -4
- package/src/common/normalise.mjs +4 -2
- package/src/library/{index.js → index.mjs} +1 -1
- package/src/library/playlists/{index.js → index.mjs} +2 -2
- package/src/library/playlists/transform/{index.js → index.mjs} +1 -1
- package/src/library/tracks/{index.js → index.mjs} +2 -2
- package/src/library/tracks/transform/{index.js → index.mjs} +1 -1
- package/src/library/transform/{index.js → index.mjs} +1 -1
package/app.mjs
CHANGED
|
@@ -22,6 +22,10 @@ const {
|
|
|
22
22
|
}
|
|
23
23
|
} = watch
|
|
24
24
|
|
|
25
|
+
const log = debug('@sequencemedia/music-library')
|
|
26
|
+
|
|
27
|
+
log('`music-library` is awake')
|
|
28
|
+
|
|
25
29
|
const NAME = 'ml.App'
|
|
26
30
|
process.title = NAME
|
|
27
31
|
|
|
@@ -61,16 +65,12 @@ async function app () {
|
|
|
61
65
|
return
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
const log = debug('@sequencemedia/music-library')
|
|
65
|
-
const info = debug('@sequencemedia/music-library:info')
|
|
66
|
-
|
|
67
68
|
const {
|
|
68
69
|
pid,
|
|
69
70
|
argv,
|
|
70
71
|
env: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
DESTINATION
|
|
72
|
+
TRACKS = false,
|
|
73
|
+
PLAYLISTS = false
|
|
74
74
|
}
|
|
75
75
|
} = process
|
|
76
76
|
|
|
@@ -80,58 +80,69 @@ async function app () {
|
|
|
80
80
|
version
|
|
81
81
|
} = PACKAGE
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
try {
|
|
84
|
+
commander
|
|
85
|
+
.version(version)
|
|
86
|
+
.exitOverride()
|
|
87
|
+
.requiredOption('-j, --jar [jar]', 'Path to Saxon PE/EE JAR')
|
|
88
|
+
.requiredOption('-x, --xml [xml]', 'Path to iTunes Library XML')
|
|
89
|
+
.requiredOption('-d, --destination [destination]', 'Destination path for M3Us')
|
|
90
|
+
.option('-t, --tracks', 'Parse all tracks')
|
|
91
|
+
.option('-p, --playlists', 'Parse all playlists')
|
|
92
|
+
.parse(argv)
|
|
93
|
+
} catch (e) {
|
|
94
|
+
const {
|
|
95
|
+
code
|
|
96
|
+
} = e
|
|
97
|
+
|
|
98
|
+
const error = debug('@sequencemedia/music-library:commander:error')
|
|
99
|
+
|
|
100
|
+
if (code !== 'commander.missingMandatoryOptionValue') error(e)
|
|
101
|
+
|
|
102
|
+
error(`Halting application "${name}" in process ${pid}.`)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
91
105
|
|
|
92
106
|
const {
|
|
93
|
-
jar
|
|
94
|
-
xml
|
|
95
|
-
destination
|
|
96
|
-
tracks: t =
|
|
97
|
-
playlists: p =
|
|
107
|
+
jar,
|
|
108
|
+
xml,
|
|
109
|
+
destination,
|
|
110
|
+
tracks: t = TRACKS,
|
|
111
|
+
playlists: p = PLAYLISTS
|
|
98
112
|
} = commander.opts()
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
log(`Application "${name}" in process ${pid} watching Library.`)
|
|
114
|
+
log({
|
|
115
|
+
jar,
|
|
116
|
+
xml,
|
|
117
|
+
destination
|
|
118
|
+
})
|
|
106
119
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
library
|
|
111
|
-
.toM3U(jar, xml, destination)
|
|
120
|
+
try {
|
|
121
|
+
const l = (
|
|
122
|
+
(t && p) || (!t && !p)
|
|
112
123
|
)
|
|
113
|
-
} else {
|
|
114
|
-
if (t) {
|
|
115
|
-
log(`Application "${name}" in process ${pid} watching Tracks.`)
|
|
116
124
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
tracks
|
|
121
|
-
.toM3U(jar, xml, destination)
|
|
122
|
-
)
|
|
123
|
-
}
|
|
125
|
+
if (l) {
|
|
126
|
+
log(`Application "${name}" in process ${pid} watching Library.`)
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
await library.toM3U(jar, xml, destination)
|
|
129
|
+
} else {
|
|
130
|
+
if (t) {
|
|
131
|
+
log(`Application "${name}" in process ${pid} watching Tracks.`)
|
|
127
132
|
|
|
128
|
-
|
|
133
|
+
await tracks.toM3U(jar, xml, destination)
|
|
134
|
+
} else {
|
|
135
|
+
if (p) {
|
|
136
|
+
log(`Application "${name}" in process ${pid} watching Playlists.`)
|
|
129
137
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
)
|
|
138
|
+
await playlists.toM3U(jar, xml, destination)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
134
141
|
}
|
|
142
|
+
} catch ({ message }) {
|
|
143
|
+
const error = debug('@sequencemedia/music-library:error')
|
|
144
|
+
|
|
145
|
+
error(message)
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
148
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
exec
|
|
5
|
+
} from 'child_process'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
readFile
|
|
9
|
+
} from 'fs/promises'
|
|
10
|
+
|
|
11
|
+
const log = debug('@sequencemedia/music-library:build:gulp:common')
|
|
12
|
+
|
|
13
|
+
export const PACKAGE_VERSION_CHANGES = /\-+\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+\++\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+/ /* eslint-disable-line no-useless-escape */
|
|
14
|
+
|
|
15
|
+
export const HAS_STAGED_CHANGES = /Changes to be committed/s
|
|
16
|
+
|
|
17
|
+
export const NOT_STAGED_CHANGES = /Changes not staged for commit/s
|
|
18
|
+
|
|
19
|
+
export const OPTIONS = {
|
|
20
|
+
maxBuffer: 1024 * 500
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const BRANCH = 'master'
|
|
24
|
+
|
|
25
|
+
export const trim = (v) => v.split('\n').map((v) => v.trimEnd()).join('\n').trim()
|
|
26
|
+
|
|
27
|
+
export function use (key) {
|
|
28
|
+
const log = debug(`@sequencemedia/music-library:${key}`)
|
|
29
|
+
|
|
30
|
+
return function use (v) {
|
|
31
|
+
log(trim(v))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getGitRemoteShowOriginHeadBranch () {
|
|
36
|
+
log('getGitRemoteShowOriginHeadBranch')
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
new Promise((resolve, reject) => {
|
|
40
|
+
const command = 'git remote show origin | awk \'/HEAD branch/ {print $NF}\''
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
stdout,
|
|
44
|
+
stderr
|
|
45
|
+
} = exec(command, OPTIONS, (e, v = '') => (!e) ? resolve(trim(v)) : reject(e))
|
|
46
|
+
|
|
47
|
+
stdout.on('data', use('git-remote-show-origin-head-branch'))
|
|
48
|
+
stderr.on('data', use('git-remote-show-origin-head-branch'))
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function hasPackageVersionChanges (branch = BRANCH) {
|
|
54
|
+
log('hasPackageVersionChanges')
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
new Promise((resolve, reject) => {
|
|
58
|
+
exec(`git diff HEAD origin/${branch} package.json`, OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v)) : reject(e))
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function notPackageVersionChanges (branch = BRANCH) {
|
|
64
|
+
log('notPackageVersionChanges')
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
new Promise((resolve, reject) => {
|
|
68
|
+
exec(`git diff HEAD origin/${branch} package.json`, OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) !== true) : reject(e))
|
|
69
|
+
})
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function addPackageVersionChanges () {
|
|
74
|
+
log('addPackageVersionChanges')
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
new Promise((resolve, reject) => {
|
|
78
|
+
exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function hasStagedChanges () {
|
|
84
|
+
log('hasStagedChanges')
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
new Promise((resolve, reject) => {
|
|
88
|
+
exec('git status', OPTIONS, (e, v) => (!e) ? resolve(HAS_STAGED_CHANGES.test(v)) : reject(e))
|
|
89
|
+
})
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function notStagedChanges () {
|
|
94
|
+
log('notStagedChanges')
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
new Promise((resolve, reject) => {
|
|
98
|
+
exec('git status', OPTIONS, (e, v) => (!e) ? resolve(NOT_STAGED_CHANGES.test(v)) : reject(e))
|
|
99
|
+
})
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function notPushedChanges (branch = BRANCH) {
|
|
104
|
+
log('notPushedChanges')
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
new Promise((resolve, reject) => {
|
|
108
|
+
exec(`git log origin/${branch}..HEAD`, OPTIONS, (e, v) => (!e) ? resolve(!!v) : reject(e))
|
|
109
|
+
})
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function getPackageVersion () {
|
|
114
|
+
log('getPackageVersion')
|
|
115
|
+
|
|
116
|
+
const {
|
|
117
|
+
version = '0.0.0'
|
|
118
|
+
} = JSON.parse(await readFile('./package.json', 'utf8'))
|
|
119
|
+
|
|
120
|
+
return version
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function patchPackageVersion () {
|
|
124
|
+
log('patchPackageVersion')
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
new Promise((resolve, reject) => {
|
|
128
|
+
exec('npm version patch -m %s -n --no-git-tag-version --no-verify', OPTIONS, (e) => (!e) ? resolve() : reject(e))
|
|
129
|
+
})
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function gitTag (a = '0.0.0', m = `v${a}`) {
|
|
134
|
+
log('gitTag')
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
new Promise((resolve, reject) => {
|
|
138
|
+
exec(`git tag -a v${a} -m "${m}"`, OPTIONS, (e, v) => (!e) ? resolve(v) : reject(e))
|
|
139
|
+
})
|
|
140
|
+
)
|
|
141
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getPackageVersion,
|
|
5
|
+
gitTag
|
|
6
|
+
} from '#build/gulp/common'
|
|
7
|
+
|
|
8
|
+
const log = debug('@sequencemedia/music-library:build:gulp:post-commit')
|
|
9
|
+
const error = debug('@sequencemedia/music-library:build:gulp:post-commit:error')
|
|
10
|
+
|
|
11
|
+
log('`@sequencemedia/music-library` is awake')
|
|
12
|
+
|
|
13
|
+
export default async function postCommit () {
|
|
14
|
+
log('post-commit')
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
await gitTag(await getPackageVersion())
|
|
18
|
+
} catch ({ code = 'NONE', message = 'No error message defined' }) {
|
|
19
|
+
error({ code, message })
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
notStagedChanges,
|
|
5
|
+
hasStagedChanges,
|
|
6
|
+
getGitRemoteShowOriginHeadBranch,
|
|
7
|
+
notPackageVersionChanges,
|
|
8
|
+
patchPackageVersion,
|
|
9
|
+
addPackageVersionChanges
|
|
10
|
+
} from '#build/gulp/common'
|
|
11
|
+
|
|
12
|
+
const log = debug('@sequencemedia/music-library:build:gulp:pre-commit')
|
|
13
|
+
const error = debug('@sequencemedia/music-library:build:gulp:pre-commit:error')
|
|
14
|
+
|
|
15
|
+
log('`@sequencemedia/music-library` is awake')
|
|
16
|
+
|
|
17
|
+
export default async function preCommit () {
|
|
18
|
+
log('pre-commit')
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
/**
|
|
22
|
+
* Not changes added, exit
|
|
23
|
+
*/
|
|
24
|
+
if (await notStagedChanges()) return
|
|
25
|
+
/**
|
|
26
|
+
* Has changes added, continue
|
|
27
|
+
*/
|
|
28
|
+
if (await hasStagedChanges()) {
|
|
29
|
+
/**
|
|
30
|
+
* Not package version changes, continue
|
|
31
|
+
*/
|
|
32
|
+
if (await notPackageVersionChanges(await getGitRemoteShowOriginHeadBranch())) {
|
|
33
|
+
await patchPackageVersion()
|
|
34
|
+
await addPackageVersionChanges()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch ({ code = 'NONE', message = 'No error message defined' }) {
|
|
38
|
+
error({ code, message })
|
|
39
|
+
}
|
|
40
|
+
}
|
package/gulpfile.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import gulp from 'gulp'
|
|
2
|
+
|
|
3
|
+
import preCommit from '#build/gulp/pre-commit'
|
|
4
|
+
import postCommit from '#build/gulp/post-commit'
|
|
5
|
+
|
|
6
|
+
gulp
|
|
7
|
+
.task('pre-commit', preCommit)
|
|
8
|
+
|
|
9
|
+
gulp
|
|
10
|
+
.task('post-commit', postCommit)
|
|
11
|
+
|
|
12
|
+
gulp
|
|
13
|
+
.task('default', gulp.series('pre-commit'))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/music-library",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Watch Apple Music Library XML and parse to JSON, JS, ES, or M3U",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"music",
|
|
@@ -35,7 +35,11 @@
|
|
|
35
35
|
"lint": "eslint . --ext .mjs --ext .cjs",
|
|
36
36
|
"lint:fix": "npm run lint -- --fix",
|
|
37
37
|
"start": "cross-env DEBUG=@sequencemedia/music-library,@sequencemedia/music-library:*,@sequencemedia/music-library-parser,@sequencemedia/music-library-parser:* NODE_ENV=production node .",
|
|
38
|
-
"
|
|
38
|
+
"dev": "cross-env DEBUG=@sequencemedia/music-library,@sequencemedia/music-library:*,@sequencemedia/music-library-parser,@sequencemedia/music-library-parser:* NODE_ENV=development node .",
|
|
39
|
+
"gulp": "gulp --color",
|
|
40
|
+
"pre-commit": "npm run lint && cross-env DEBUG=@sequencemedia/music-library,@sequencemedia/music-library:* npm run gulp -- pre-commit",
|
|
41
|
+
"post-commit": "cross-env DEBUG=@sequencemedia/music-library,@sequencemedia/music-library:* npm run gulp -- post-commit",
|
|
42
|
+
"prepare": "husky install"
|
|
39
43
|
},
|
|
40
44
|
"dependencies": {
|
|
41
45
|
"@sequencemedia/music-library-parser": "1.0.2",
|
|
@@ -59,17 +63,25 @@
|
|
|
59
63
|
"eslint-config-standard": "^16.0.3",
|
|
60
64
|
"eslint-plugin-import": "^2.25.3",
|
|
61
65
|
"eslint-plugin-node": "^11.1.0",
|
|
62
|
-
"eslint-plugin-promise": "5.2.0"
|
|
66
|
+
"eslint-plugin-promise": "5.2.0",
|
|
67
|
+
"gulp": "^4.0.2",
|
|
68
|
+
"husky": "^7.0.4"
|
|
63
69
|
},
|
|
64
70
|
"imports": {
|
|
65
71
|
"#music-library/common/normalise": "./src/common/normalise.mjs",
|
|
66
72
|
"#music-library/library": "./src/library/index.mjs",
|
|
73
|
+
"#music-library/library/transform": "./src/library/transform/index.mjs",
|
|
74
|
+
"#music-library/library/playlists": "./src/library/playlists/index.mjs",
|
|
75
|
+
"#music-library/library/playlists/transform": "./src/library/playlists/transform/index.mjs",
|
|
76
|
+
"#music-library/library/tracks": "./src/library/tracks/index.mjs",
|
|
77
|
+
"#music-library/library/tracks/transform": "./src/library/tracks/transform/index.mjs",
|
|
67
78
|
"#music-library/watch": "./src/watch/index.mjs",
|
|
68
79
|
"#music-library/watch/library": "./src/watch/library/index.mjs",
|
|
69
80
|
"#music-library/watch/library/transform": "./src/watch/library/transform/index.mjs",
|
|
70
81
|
"#music-library/watch/library/playlists": "./src/watch/library/playlists/index.mjs",
|
|
71
82
|
"#music-library/watch/library/playlists/transform": "./src/watch/library/playlists/transform/index.mjs",
|
|
72
83
|
"#music-library/watch/library/tracks": "./src/watch/library/tracks/index.mjs",
|
|
73
|
-
"#music-library/watch/library/tracks/transform": "./src/watch/library/tracks/transform/index.mjs"
|
|
84
|
+
"#music-library/watch/library/tracks/transform": "./src/watch/library/tracks/transform/index.mjs",
|
|
85
|
+
"#build/gulp/*": "./build/gulp/*.mjs"
|
|
74
86
|
}
|
|
75
87
|
}
|
package/src/common/normalise.mjs
CHANGED
|
@@ -2,8 +2,10 @@ import {
|
|
|
2
2
|
homedir
|
|
3
3
|
} from 'os'
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
resolve
|
|
7
|
+
} from 'path'
|
|
6
8
|
|
|
7
|
-
const normalise = (p) =>
|
|
9
|
+
const normalise = (p = '') => resolve(String(p).trim().replace(/^~/, homedir()))
|
|
8
10
|
|
|
9
11
|
export default normalise
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import debug from 'debug'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import musicLibraryParser from '@sequencemedia/music-library-parser'
|
|
4
4
|
|
|
5
5
|
import normalise from '#music-library/common/normalise'
|
|
6
6
|
|
|
@@ -34,4 +34,4 @@ export async function toM3U (jar, xml, destination) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export * as transform from '
|
|
37
|
+
export * as transform from '#music-library/library/playlists/transform'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import debug from 'debug'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import musicLibraryParser from '@sequencemedia/music-library-parser'
|
|
4
4
|
|
|
5
5
|
import normalise from '#music-library/common/normalise'
|
|
6
6
|
|
|
@@ -34,4 +34,4 @@ export async function toM3U (jar, xml, destination) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export * as transform from '
|
|
37
|
+
export * as transform from '#music-library/library/tracks/transform'
|