@tyleretters/discography 0.0.5 → 0.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/README.md +15 -17
- package/dist/discography.d.ts +21 -0
- package/dist/discography.js +2468 -0
- package/dist/discography.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2472 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +15 -3
- package/rollup.config.js +18 -0
- package/src/convert.py +28 -12
- package/{dist/data.json → src/discography.ts} +308 -308
- package/src/{data.yml → discography.yml} +1 -1
- package/src/index.ts +5 -0
- package/src/types.ts +23 -0
- package/tsconfig.json +15 -0
package/rollup.config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const typescript = require("rollup-plugin-typescript2")
|
|
2
|
+
const pkg = require("./package.json")
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
input: 'src/index.ts',
|
|
6
|
+
output: [
|
|
7
|
+
{
|
|
8
|
+
file: pkg.main,
|
|
9
|
+
format: 'cjs',
|
|
10
|
+
exports: 'named',
|
|
11
|
+
sourcemap: true,
|
|
12
|
+
strict: false
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
plugins: [
|
|
16
|
+
typescript()
|
|
17
|
+
],
|
|
18
|
+
}
|
package/src/convert.py
CHANGED
|
@@ -6,22 +6,27 @@ convert the yml to json.
|
|
|
6
6
|
see README.md for more information.
|
|
7
7
|
'''
|
|
8
8
|
|
|
9
|
+
import os
|
|
9
10
|
import yaml
|
|
10
11
|
import json
|
|
11
12
|
import re
|
|
12
13
|
import hashlib
|
|
13
14
|
from datetime import datetime
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return md5_hash.hexdigest()
|
|
16
|
+
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
17
|
+
yml_path = dir_path + "/" + "discography.yml"
|
|
18
|
+
ts_path = dir_path + "/" + "discography.ts"
|
|
19
19
|
|
|
20
20
|
special_maps = {
|
|
21
21
|
"ΑΙΓΑΙΙΣ": "AIGAIIS",
|
|
22
22
|
"nausicaä": "nausicaa"
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
def make_id(str):
|
|
26
|
+
md5_hash = hashlib.md5()
|
|
27
|
+
md5_hash.update(str.encode("utf-8"))
|
|
28
|
+
return md5_hash.hexdigest()
|
|
29
|
+
|
|
25
30
|
def make_slug(str):
|
|
26
31
|
if str in special_maps:
|
|
27
32
|
str = special_maps[str]
|
|
@@ -32,20 +37,22 @@ def make_slug(str):
|
|
|
32
37
|
str = re.sub(r'[^a-zA-Z0-9\s-]', '', str)
|
|
33
38
|
# replace spaces with hyphens
|
|
34
39
|
str = re.sub(r'\s+', '-', str)
|
|
40
|
+
# replace multiple hyphens with single hyphen
|
|
41
|
+
str = re.sub(r'--+', '-', str)
|
|
35
42
|
return str
|
|
36
43
|
|
|
37
44
|
# load data
|
|
38
|
-
with open(
|
|
45
|
+
with open(yml_path, "r") as yml_file:
|
|
39
46
|
data = yaml.safe_load(yml_file)
|
|
40
47
|
|
|
41
48
|
# enrich data
|
|
42
49
|
for release in data:
|
|
43
|
-
# generate a release slug
|
|
44
|
-
release["release_slug"] = make_slug(release["title"])
|
|
45
|
-
|
|
46
50
|
# generate a project slug
|
|
47
51
|
release["project_slug"] = make_slug(release["project"])
|
|
48
52
|
|
|
53
|
+
# generate a release slug
|
|
54
|
+
release["release_slug"] = make_slug(release["title"])
|
|
55
|
+
|
|
49
56
|
# generate an id
|
|
50
57
|
release["id"] = make_id(release["project"] + release["title"])
|
|
51
58
|
|
|
@@ -54,11 +61,20 @@ for release in data:
|
|
|
54
61
|
for track in release["tracks"]:
|
|
55
62
|
|
|
56
63
|
# generate a track slug
|
|
57
|
-
track["track_slug"] = make_slug(track["title"])
|
|
64
|
+
track["track_slug"] = release["project_slug"] + "/" + release["release_slug"] + "/" + make_slug(track["title"])
|
|
58
65
|
|
|
59
66
|
# generate an id (ARTIST + RELEASE + NUMBER + TITLE + LENGTH)
|
|
60
67
|
track["id"] = make_id(release["project"] + release["title"] + str(track["number"]) + track["title"] + track["length"])
|
|
61
68
|
|
|
62
|
-
# write data
|
|
63
|
-
with open(
|
|
64
|
-
json.dump(data, json_file, indent=2)
|
|
69
|
+
# write discography data
|
|
70
|
+
with open(ts_path, "w") as json_file:
|
|
71
|
+
json.dump(data, json_file, indent=2)
|
|
72
|
+
|
|
73
|
+
# make it a js export
|
|
74
|
+
with open(ts_path, "r") as file:
|
|
75
|
+
existing_contents = file.read()
|
|
76
|
+
|
|
77
|
+
with open(ts_path, "w") as file:
|
|
78
|
+
new_string = "export const discography = "
|
|
79
|
+
file.write(new_string)
|
|
80
|
+
file.write(existing_contents)
|