@sequencemedia/music-library-parser 1.0.0 → 1.0.4
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/pre-commit +4 -0
- package/README.md +2 -2
- package/build/gulp/pre-commit.mjs +144 -0
- package/gulpfile.mjs +9 -0
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# @sequencemedia/
|
|
1
|
+
# @sequencemedia/music-library-parser
|
|
2
2
|
|
|
3
|
-
JavaScript functions and XSL stylesheets to parse an Apple Music `Library.xml` file and transform it to [`m3u`](https://en.wikipedia.org/wiki/M3U) files, JSON, or
|
|
3
|
+
JavaScript functions and XSL stylesheets to parse an Apple Music `Library.xml` file and transform it to [`m3u`](https://en.wikipedia.org/wiki/M3U) files, JSON, JavaScript, or EcmaScript.
|
|
4
4
|
|
|
5
5
|
Requires [Java](https://www.oracle.com/java/technologies/javase-downloads.html) and [Saxon PE](https://www.saxonica.com/welcome/welcome.xml).
|
|
6
6
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
exec
|
|
5
|
+
} from 'child_process'
|
|
6
|
+
|
|
7
|
+
const log = debug('@sequencemedia/music-library-parser:build:gulp:pre-commit')
|
|
8
|
+
|
|
9
|
+
log('`@sequencemedia/music-library-parser` is awake')
|
|
10
|
+
|
|
11
|
+
const PACKAGE_VERSION_CHANGES = /\-+\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+\++\s+"version":\s+"(\d+\.\d+\.\d+)",+\s+/ /* eslint-disable-line no-useless-escape */
|
|
12
|
+
|
|
13
|
+
const HAS_STAGED_CHANGES = /Changes to be committed/s
|
|
14
|
+
|
|
15
|
+
const NOT_STAGED_CHANGES = /Changes not staged for commit/s
|
|
16
|
+
|
|
17
|
+
const OPTIONS = {
|
|
18
|
+
maxBuffer: 1024 * 500
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const BRANCH = 'master'
|
|
22
|
+
|
|
23
|
+
const trim = (v) => v.split('\n').map((v) => v.trimEnd()).join('\n').trim()
|
|
24
|
+
|
|
25
|
+
function use (key) {
|
|
26
|
+
const log = debug(`@modernpoacher/deps:${key}`)
|
|
27
|
+
|
|
28
|
+
return function use (v) {
|
|
29
|
+
log(trim(v))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getGitRemoteShowOriginHeadBranch () {
|
|
34
|
+
log('getGitRemoteShowOriginHeadBranch')
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
new Promise((resolve, reject) => {
|
|
38
|
+
const command = 'git remote show origin | awk \'/HEAD branch/ {print $NF}\''
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
stdout,
|
|
42
|
+
stderr
|
|
43
|
+
} = exec(command, OPTIONS, (e, v = '') => (!e) ? resolve(trim(v)) : reject(e))
|
|
44
|
+
|
|
45
|
+
stdout.on('data', use('git-remote-show-origin-head-branch'))
|
|
46
|
+
stderr.on('data', use('git-remote-show-origin-head-branch'))
|
|
47
|
+
})
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function hasPackageVersionChanges (branch = BRANCH) {
|
|
52
|
+
log('hasPackageVersionChanges')
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
new Promise((resolve, reject) => {
|
|
56
|
+
exec(`git diff HEAD origin/${branch} package.json`, OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v)) : reject(e))
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function notPackageVersionChanges (branch = BRANCH) {
|
|
62
|
+
log('notPackageVersionChanges')
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
new Promise((resolve, reject) => {
|
|
66
|
+
exec(`git diff HEAD origin/${branch} package.json`, OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) !== true) : reject(e))
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function hasStagedChanges () {
|
|
72
|
+
log('hasStagedChanges')
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
new Promise((resolve, reject) => {
|
|
76
|
+
exec('git status', OPTIONS, (e, v) => (!e) ? resolve(HAS_STAGED_CHANGES.test(v)) : reject(e))
|
|
77
|
+
})
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function notStagedChanges () {
|
|
82
|
+
log('notStagedChanges')
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
new Promise((resolve, reject) => {
|
|
86
|
+
exec('git status', OPTIONS, (e, v) => (!e) ? resolve(NOT_STAGED_CHANGES.test(v)) : reject(e))
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function notPushedChanges (branch = BRANCH) {
|
|
92
|
+
log('notPushedChanges')
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
new Promise((resolve, reject) => {
|
|
96
|
+
exec(`git log origin/${branch}..HEAD`, OPTIONS, (e, v) => (!e) ? resolve(!!v) : reject(e))
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function patchPackageVersion () {
|
|
102
|
+
log('patchPackageVersion')
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
new Promise((resolve, reject) => {
|
|
106
|
+
exec('npm version patch -m %s -n --no-git-tag-version --no-verify', OPTIONS, (e) => (!e) ? resolve() : reject(e))
|
|
107
|
+
})
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function addPackageVersionChanges () {
|
|
112
|
+
log('addPackageVersionChanges')
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
new Promise((resolve, reject) => {
|
|
116
|
+
exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
|
|
117
|
+
})
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default async function preCommit () {
|
|
122
|
+
log('pre-commit')
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
/**
|
|
126
|
+
* Not changes added, exit
|
|
127
|
+
*/
|
|
128
|
+
if (await notStagedChanges()) return
|
|
129
|
+
/**
|
|
130
|
+
* Has changes added, continue
|
|
131
|
+
*/
|
|
132
|
+
if (await hasStagedChanges()) {
|
|
133
|
+
/**
|
|
134
|
+
* Not package version changes, continue
|
|
135
|
+
*/
|
|
136
|
+
if (await notPackageVersionChanges(await getGitRemoteShowOriginHeadBranch())) {
|
|
137
|
+
await patchPackageVersion()
|
|
138
|
+
await addPackageVersionChanges()
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} catch ({ code = 'NONE', message = 'No error message defined' }) {
|
|
142
|
+
log({ code, message })
|
|
143
|
+
}
|
|
144
|
+
}
|
package/gulpfile.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/music-library-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Parse Apple Music Library XML to JSON, JS, ES, or M3U",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"music",
|
|
@@ -34,8 +34,10 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"lint": "eslint . --ext .mjs --ext .cjs",
|
|
36
36
|
"lint:fix": "npm run lint -- --fix",
|
|
37
|
-
"start": "cross-env DEBUG=@sequencemedia/music-library-parser
|
|
38
|
-
"dev": "cross-env DEBUG=@sequencemedia/music-library-parser
|
|
37
|
+
"start": "cross-env DEBUG=@sequencemedia/music-library-parser,@sequencemedia/music-library-parser:* NODE_ENV=production node .",
|
|
38
|
+
"dev": "cross-env DEBUG=@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-parser,@sequencemedia/music-library-parser:* npm run gulp -- pre-commit"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"cross-env": "^7.0.3",
|
|
@@ -55,7 +57,9 @@
|
|
|
55
57
|
"eslint-config-standard": "^16.0.3",
|
|
56
58
|
"eslint-plugin-import": "^2.25.3",
|
|
57
59
|
"eslint-plugin-node": "^11.1.0",
|
|
58
|
-
"eslint-plugin-promise": "5.2.0"
|
|
60
|
+
"eslint-plugin-promise": "5.2.0",
|
|
61
|
+
"gulp": "^4.0.2",
|
|
62
|
+
"husky": "^7.0.4"
|
|
59
63
|
},
|
|
60
64
|
"imports": {
|
|
61
65
|
"#music-library-parser": "./src/js/index.mjs",
|
|
@@ -65,6 +69,7 @@
|
|
|
65
69
|
"#music-library-parser/library/playlists/transform": "./src/js/library/playlists/transform/index.mjs",
|
|
66
70
|
"#music-library-parser/library/tracks": "./src/js/library/tracks/index.mjs",
|
|
67
71
|
"#music-library-parser/library/tracks/transform": "./src/js/library/tracks/transform/index.mjs",
|
|
68
|
-
"#music-library-parser/transform": "./src/js/transform/index.mjs"
|
|
72
|
+
"#music-library-parser/transform": "./src/js/transform/index.mjs",
|
|
73
|
+
"#build/gulp/*": "./build/gulp/*.mjs"
|
|
69
74
|
}
|
|
70
75
|
}
|