@sequencemedia/music-library 1.0.3 → 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.
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run pre-commit
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
- JAR,
72
- XML,
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
- commander
84
- .version(version)
85
- .option('-j, --jar [jar]', 'Path to Saxon PE/EE JAR')
86
- .option('-x, --xml [xml]', 'Path to iTunes Library XML')
87
- .option('-d, --destination [destination]', 'Destination path for M3Us')
88
- .option('-t, --tracks', 'Parse all tracks')
89
- .option('-p, --playlists', 'Parse all playlists')
90
- .parse(argv)
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 = JAR,
94
- xml = XML,
95
- destination = DESTINATION,
96
- tracks: t = false,
97
- playlists: p = false
107
+ jar,
108
+ xml,
109
+ destination,
110
+ tracks: t = TRACKS,
111
+ playlists: p = PLAYLISTS
98
112
  } = commander.opts()
99
113
 
100
- const l = (
101
- (t && p) || (!t && !p)
102
- )
103
-
104
- if (l) {
105
- log(`Application "${name}" in process ${pid} watching Library.`)
114
+ log({
115
+ jar,
116
+ xml,
117
+ destination
118
+ })
106
119
 
107
- info({ jar, xml, destination })
108
-
109
- return (
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
- info({ jar, xml, destination })
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
- if (p) {
126
- log(`Application "${name}" in process ${pid} watching Playlists.`)
128
+ await library.toM3U(jar, xml, destination)
129
+ } else {
130
+ if (t) {
131
+ log(`Application "${name}" in process ${pid} watching Tracks.`)
127
132
 
128
- info({ jar, xml, destination })
133
+ await tracks.toM3U(jar, xml, destination)
134
+ } else {
135
+ if (p) {
136
+ log(`Application "${name}" in process ${pid} watching Playlists.`)
129
137
 
130
- return (
131
- playlists
132
- .toM3U(jar, xml, destination)
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,114 @@
1
+ import debug from 'debug'
2
+
3
+ import {
4
+ exec
5
+ } from 'child_process'
6
+
7
+ const log = debug('@sequencemedia/music-library:build:gulp:pre-commit')
8
+
9
+ log('`@sequencemedia/music-library` 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
+ export function hasPackageVersionChanges () {
22
+ log('hasPackageVersionChanges')
23
+
24
+ return (
25
+ new Promise((resolve, reject) => {
26
+ exec('git diff HEAD origin/main package.json', OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v)) : reject(e))
27
+ })
28
+ )
29
+ }
30
+
31
+ export function notPackageVersionChanges () {
32
+ log('notPackageVersionChanges')
33
+
34
+ return (
35
+ new Promise((resolve, reject) => {
36
+ exec('git diff HEAD origin/main package.json', OPTIONS, (e, v) => (!e) ? resolve(PACKAGE_VERSION_CHANGES.test(v) !== true) : reject(e))
37
+ })
38
+ )
39
+ }
40
+
41
+ export function hasStagedChanges () {
42
+ log('hasStagedChanges')
43
+
44
+ return (
45
+ new Promise((resolve, reject) => {
46
+ exec('git status', OPTIONS, (e, v) => (!e) ? resolve(HAS_STAGED_CHANGES.test(v)) : reject(e))
47
+ })
48
+ )
49
+ }
50
+
51
+ export function notStagedChanges () {
52
+ log('notStagedChanges')
53
+
54
+ return (
55
+ new Promise((resolve, reject) => {
56
+ exec('git status', OPTIONS, (e, v) => (!e) ? resolve(NOT_STAGED_CHANGES.test(v)) : reject(e))
57
+ })
58
+ )
59
+ }
60
+
61
+ export function notPushedChanges () {
62
+ log('notPushedChanges')
63
+
64
+ return (
65
+ new Promise((resolve, reject) => {
66
+ exec('git log origin/main..HEAD', OPTIONS, (e, v) => (!e) ? resolve(!!v) : reject(e))
67
+ })
68
+ )
69
+ }
70
+
71
+ export function patchPackageVersion () {
72
+ log('patchPackageVersion')
73
+
74
+ return (
75
+ new Promise((resolve, reject) => {
76
+ exec('npm version patch -m %s -n --no-git-tag-version --no-verify', OPTIONS, (e) => (!e) ? resolve() : reject(e))
77
+ })
78
+ )
79
+ }
80
+
81
+ export function addPackageVersionChanges () {
82
+ log('addPackageVersionChanges')
83
+
84
+ return (
85
+ new Promise((resolve, reject) => {
86
+ exec('git add package.json package-lock.json', OPTIONS, (e) => (!e) ? resolve() : reject(e))
87
+ })
88
+ )
89
+ }
90
+
91
+ export default async function preCommit () {
92
+ log('pre-commit')
93
+
94
+ try {
95
+ /**
96
+ * Not changes added, exit
97
+ */
98
+ if (await notStagedChanges()) return
99
+ /**
100
+ * Has changes added, continue
101
+ */
102
+ if (await hasStagedChanges()) {
103
+ /**
104
+ * Not package version changes, continue
105
+ */
106
+ if (await notPackageVersionChanges()) {
107
+ await patchPackageVersion()
108
+ await addPackageVersionChanges()
109
+ }
110
+ }
111
+ } catch ({ code = 'NONE', message = 'No error message defined' }) {
112
+ log({ code, message })
113
+ }
114
+ }
package/gulpfile.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import gulp from 'gulp'
2
+
3
+ import preCommit from '#build/gulp/pre-commit'
4
+
5
+ gulp
6
+ .task('pre-commit', preCommit)
7
+
8
+ gulp
9
+ .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",
3
+ "version": "1.0.4",
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,10 @@
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
- "start:dev": "cross-env DEBUG=@sequencemedia/music-library,@sequencemedia/music-library:*,@sequencemedia/music-library-parser,@sequencemedia/music-library-parser:* NODE_ENV=development node ."
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
+ "prepare": "husky install"
39
42
  },
40
43
  "dependencies": {
41
44
  "@sequencemedia/music-library-parser": "1.0.2",
@@ -59,17 +62,25 @@
59
62
  "eslint-config-standard": "^16.0.3",
60
63
  "eslint-plugin-import": "^2.25.3",
61
64
  "eslint-plugin-node": "^11.1.0",
62
- "eslint-plugin-promise": "5.2.0"
65
+ "eslint-plugin-promise": "5.2.0",
66
+ "gulp": "^4.0.2",
67
+ "husky": "^7.0.4"
63
68
  },
64
69
  "imports": {
65
70
  "#music-library/common/normalise": "./src/common/normalise.mjs",
66
71
  "#music-library/library": "./src/library/index.mjs",
72
+ "#music-library/library/transform": "./src/library/transform/index.mjs",
73
+ "#music-library/library/playlists": "./src/library/playlists/index.mjs",
74
+ "#music-library/library/playlists/transform": "./src/library/playlists/transform/index.mjs",
75
+ "#music-library/library/tracks": "./src/library/tracks/index.mjs",
76
+ "#music-library/library/tracks/transform": "./src/library/tracks/transform/index.mjs",
67
77
  "#music-library/watch": "./src/watch/index.mjs",
68
78
  "#music-library/watch/library": "./src/watch/library/index.mjs",
69
79
  "#music-library/watch/library/transform": "./src/watch/library/transform/index.mjs",
70
80
  "#music-library/watch/library/playlists": "./src/watch/library/playlists/index.mjs",
71
81
  "#music-library/watch/library/playlists/transform": "./src/watch/library/playlists/transform/index.mjs",
72
82
  "#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"
83
+ "#music-library/watch/library/tracks/transform": "./src/watch/library/tracks/transform/index.mjs",
84
+ "#build/gulp/*": "./build/gulp/*.mjs"
74
85
  }
75
86
  }
@@ -2,8 +2,10 @@ import {
2
2
  homedir
3
3
  } from 'os'
4
4
 
5
- import path from 'path'
5
+ import {
6
+ resolve
7
+ } from 'path'
6
8
 
7
- const normalise = (p) => path.resolve(p.trim().replace(/^~/, homedir()))
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 * as musicLibraryParser from '@sequencemedia/music-library-parser'
3
+ import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
5
  import normalise from '#music-library/common/normalise'
6
6
 
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug'
2
2
 
3
- import * as musicLibraryParser from '@sequencemedia/music-library-parser'
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 './transform'
37
+ export * as transform from '#music-library/library/playlists/transform'
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug'
2
2
 
3
- import * as musicLibraryParser from '@sequencemedia/music-library-parser'
3
+ import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
5
  import normalise from '#music-library/common/normalise'
6
6
 
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug'
2
2
 
3
- import * as musicLibraryParser from '@sequencemedia/music-library-parser'
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 './transform'
37
+ export * as transform from '#music-library/library/tracks/transform'
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug'
2
2
 
3
- import * as musicLibraryParser from '@sequencemedia/music-library-parser'
3
+ import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
5
  import normalise from '#music-library/common/normalise'
6
6
 
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug'
2
2
 
3
- import * as musicLibraryParser from '@sequencemedia/music-library-parser'
3
+ import musicLibraryParser from '@sequencemedia/music-library-parser'
4
4
 
5
5
  import normalise from '#music-library/common/normalise'
6
6