@mxfb/cli 0.0.66 → 0.0.67
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/cli/assets/list.txt +1 -0
- package/cli/assets/version.txt +1 -1
- package/make-calendar/index.js +3 -3
- package/make-calendar/index.js.map +2 -2
- package/mxfb-projects-sync/assets/main.sh +211 -0
- package/mxfb-projects-sync/index.js +5 -0
- package/mxfb-projects-sync/index.js.map +7 -0
- package/package.json +5 -3
- package/term-glossary/index.js +3 -0
- package/term-glossary/index.js.map +2 -2
- package/tumblr-crawler/index.js +1 -1
- package/tumblr-crawler/index.js.map +3 -3
package/cli/assets/list.txt
CHANGED
package/cli/assets/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.67
|
package/make-calendar/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{endOfYear as D,startOfYear as i,endOfMonth as
|
|
2
|
+
import{endOfYear as D,startOfYear as i,endOfMonth as p,getWeek as u,eachWeekOfInterval as g,endOfWeek as S,format as r,getMonth as o,getDate as c}from"date-fns";var O=parseInt(`${process.argv[2]}`);l(O);function l(_){let s=parseInt(`${_}`),m=i(new Date(s,0,1)),d=D(new Date(s,11,31)),f=g({start:m,end:d},{weekStartsOn:1}).map(t=>{let e=t,n=S(e,{weekStartsOn:1}),a=n.getFullYear(),y=u(e,{weekStartsOn:1});return{year:a,number:y,firstDay:e,lastDay:n}});console.log(`\u2502 ${s} Pos\xE9s Solde Note
|
|
3
3
|
\u2502 date \u2014 sem \u2014 l m m j v s + l cp rtt cp rtt
|
|
4
4
|
\u2502 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014
|
|
5
|
-
\u2502`),
|
|
5
|
+
\u2502`),f.forEach(t=>{let e=o(t.firstDay)!==o(t.lastDay),n=p(t.firstDay),a=c(t.lastDay)===c(n);console.log(`
|
|
6
6
|
\u2502 ${r(t.firstDay,"MMM dd")} \u203A ${r(t.lastDay,"dd")} \u2014 S ${t.number.toString().padStart(2,"0")} \u2014 _ _ _ _ _ + _ _ ___ ___ ___ ___
|
|
7
|
-
`.trim()),(e||
|
|
7
|
+
`.trim()),(e||a)&&console.log("\u2502")})}export{l as default};
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/make-calendar/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n endOfYear,\n startOfYear,\n endOfMonth,\n getWeek,\n eachWeekOfInterval,\n
|
|
5
|
-
"mappings": "AAAA,OACE,aAAAA,EACA,eAAAC,EACA,cAAAC,EACA,WAAAC,EACA,sBAAAC,
|
|
4
|
+
"sourcesContent": ["import {\n endOfYear,\n startOfYear,\n endOfMonth,\n getWeek,\n eachWeekOfInterval,\n endOfWeek,\n format as dateFormat,\n getMonth,\n getDate\n} from 'date-fns'\n\ntype WeekData = {\n year: number\n number: number\n firstDay: Date\n lastDay: Date\n}\n\n// [WIP] use commander\n\nconst year = parseInt(`${process.argv[2]}`)\nmakeCalendar(year)\n\nexport default function makeCalendar (inputYear: number) {\n const year = parseInt(`${inputYear}`)\n const start = startOfYear(new Date(year, 0, 1))\n const end = endOfYear(new Date(year, 11, 31))\n const weeksStartDates = eachWeekOfInterval({ start, end }, { weekStartsOn: 1 })\n const weeks: WeekData[] = weeksStartDates.map(weekStartDate => {\n const firstDay = weekStartDate\n const lastDay = endOfWeek(firstDay, { weekStartsOn: 1 });\n const year = lastDay.getFullYear();\n const number = getWeek(firstDay, { weekStartsOn: 1 })\n return {\n year,\n number,\n firstDay,\n lastDay\n }\n })\n console.log(\n`\u2502 ${year} Pos\u00E9s Solde Note\n\u2502 date \u2014 sem \u2014 l m m j v s + l cp rtt cp rtt \n\u2502 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\u2502`)\n weeks.forEach(weekData => {\n const onTwoMonths = getMonth(weekData.firstDay) !== getMonth(weekData.lastDay)\n const monthEnd = endOfMonth(weekData.firstDay)\n const isMonthEnd = getDate(weekData.lastDay) === getDate(monthEnd)\n console.log(`\n \u2502 ${dateFormat(weekData.firstDay, 'MMM dd')} \u203A ${dateFormat(weekData.lastDay, 'dd')} \u2014 S ${weekData.number.toString().padStart(2, '0')} \u2014 _ _ _ _ _ + _ _ ___ ___ ___ ___\n `.trim())\n if (onTwoMonths || isMonthEnd) console.log('\u2502')\n })\n}\n\n/*`\n62 jours\n \n| Calendrier Pos\u00E9s Solde Note\n| date - sem - l m m j v s + l cp rtt cp rtt \n| ------------------------------------------------------------------------------------------------\n|\n| jan XX \u203A XX - S 01 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jan XX \u203A XX - S 02 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jan XX \u203A XX - S 03 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jan XX \u203A XX - S 04 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jan XX \u203A XX - S 05 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| feb XX \u203A XX - S 06 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| feb XX \u203A XX - S 07 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| feb XX \u203A XX - S 08 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| feb XX \u203A XX - S 09 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| \n| mar XX \u203A XX - S 10 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| mar XX \u203A XX - S 11 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| mar XX \u203A XX - S 12 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| mar XX \u203A XX - S 13 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| apr XX \u203A XX - S 14 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| apr XX \u203A XX - S 15 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| apr XX \u203A XX - S 16 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| apr XX \u203A XX - S 17 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| apr XX \u203A XX - S 18 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| may XX \u203A XX - S 19 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| may XX \u203A XX - S 20 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| may XX \u203A XX - S 21 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| may XX \u203A XX - S 22 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| jun XX \u203A XX - S 23 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jun XX \u203A XX - S 24 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jun XX \u203A XX - S 25 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jun XX \u203A XX - S 26 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| jul XX \u203A XX - S 27 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jul XX \u203A XX - S 28 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jul XX \u203A XX - S 29 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jul XX \u203A XX - S 30 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| jul XX \u203A XX - S 31 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| aug XX \u203A XX - S 32 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| aug XX \u203A XX - S 33 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| aug XX \u203A XX - S 34 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| aug XX \u203A XX - S 35 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| sep XX \u203A XX - S 36 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| sep XX \u203A XX - S 37 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| sep XX \u203A XX - S 38 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| sep XX \u203A XX - S 39 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| sep XX \u203A XX - S 40 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| oct XX \u203A XX - S 41 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| oct XX \u203A XX - S 42 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| oct XX \u203A XX - S 43 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| oct XX \u203A XX - S 44 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| nov XX \u203A XX - S 45 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| nov XX \u203A XX - S 46 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| nov XX \u203A XX - S 47 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| nov XX \u203A XX - S 48 - _ _ _ _ _ _ + _ -10 -10 80 80 \n\n| dec XX \u203A XX - S 49 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| dec XX \u203A XX - S 50 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| dec XX \u203A XX - S 51 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| dec XX \u203A XX - S 52 - _ _ _ _ _ _ + _ -10 -10 80 80 \n| dec XX \u203A XX - S 53 - _ _ _ _ _ _ + _ -10 -10 80 80 \n`*/\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,aAAAA,EACA,eAAAC,EACA,cAAAC,EACA,WAAAC,EACA,sBAAAC,EACA,aAAAC,EACA,UAAUC,EACV,YAAAC,EACA,WAAAC,MACK,WAWP,IAAMC,EAAO,SAAS,GAAG,QAAQ,KAAK,CAAC,CAAC,EAAE,EAC1CC,EAAaD,CAAI,EAEF,SAARC,EAA+BC,EAAmB,CACvD,IAAMF,EAAO,SAAS,GAAGE,CAAS,EAAE,EAC9BC,EAAQX,EAAY,IAAI,KAAKQ,EAAM,EAAG,CAAC,CAAC,EACxCI,EAAMb,EAAU,IAAI,KAAKS,EAAM,GAAI,EAAE,CAAC,EAEtCK,EADkBV,EAAmB,CAAE,MAAAQ,EAAO,IAAAC,CAAI,EAAG,CAAE,aAAc,CAAE,CAAC,EACpC,IAAIE,GAAiB,CAC7D,IAAMC,EAAWD,EACXE,EAAUZ,EAAUW,EAAU,CAAE,aAAc,CAAE,CAAC,EACjDP,EAAOQ,EAAQ,YAAY,EAC3BC,EAASf,EAAQa,EAAU,CAAE,aAAc,CAAE,CAAC,EACpD,MAAO,CACL,KAAAP,EACA,OAAAS,EACA,SAAAF,EACA,QAAAC,CACF,CACF,CAAC,EACD,QAAQ,IACV,UAAKR,CAAI;AAAA;AAAA;AAAA,OAGP,EACAK,EAAM,QAAQK,GAAY,CACxB,IAAMC,EAAcb,EAASY,EAAS,QAAQ,IAAMZ,EAASY,EAAS,OAAO,EACvEE,EAAWnB,EAAWiB,EAAS,QAAQ,EACvCG,EAAad,EAAQW,EAAS,OAAO,IAAMX,EAAQa,CAAQ,EACjE,QAAQ,IAAI;AAAA,eACNf,EAAWa,EAAS,SAAU,QAAQ,CAAC,WAAMb,EAAWa,EAAS,QAAS,IAAI,CAAC,eAAUA,EAAS,OAAO,SAAS,EAAE,SAAS,EAAG,GAAG,CAAC;AAAA,MACxI,KAAK,CAAC,GACJC,GAAeE,IAAY,QAAQ,IAAI,QAAG,CAChD,CAAC,CACH",
|
|
6
6
|
"names": ["endOfYear", "startOfYear", "endOfMonth", "getWeek", "eachWeekOfInterval", "endOfWeek", "dateFormat", "getMonth", "getDate", "year", "makeCalendar", "inputYear", "start", "end", "weeks", "weekStartDate", "firstDay", "lastDay", "number", "weekData", "onTwoMonths", "monthEnd", "isMonthEnd"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
if [ "$#" -ne 2 ]; then
|
|
4
|
+
echo "2 arguments expected Usage: $0 <lemonde_path> <mxfb_path>"
|
|
5
|
+
exit 1
|
|
6
|
+
fi
|
|
7
|
+
|
|
8
|
+
LMDIRPATH="$1"
|
|
9
|
+
MXFBDIRPATH="$2"
|
|
10
|
+
|
|
11
|
+
function bold () {
|
|
12
|
+
echo "\033[1m$1\033[m"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function black_on_white() {
|
|
16
|
+
echo "\033[7m $1 \033[0m"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function throw () {
|
|
20
|
+
if [[ -z "$1" ]]; then
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
echo "$(bold "Error: $1")"
|
|
24
|
+
exit 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function relative () {
|
|
28
|
+
if [[ -z "$1" ]]; then
|
|
29
|
+
throw "Missing arguments. Usage: relative <path>"
|
|
30
|
+
fi
|
|
31
|
+
(cd "$1" && pwd) | sed "s|^$HOME/||"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function prompt_continue () {
|
|
35
|
+
read -p "$(bold "Continue?") (y/n) " cont
|
|
36
|
+
if [[ "$cont" != "y" ]]; then
|
|
37
|
+
echo ""
|
|
38
|
+
echo $(bold "Bye.")
|
|
39
|
+
echo ""
|
|
40
|
+
exit 0
|
|
41
|
+
else
|
|
42
|
+
echo "\n"
|
|
43
|
+
fi
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function git_status () {
|
|
47
|
+
if [[ -z "$1" ]]; then
|
|
48
|
+
throw "Missing arguments. Usage: git_status <path>"
|
|
49
|
+
fi
|
|
50
|
+
echo "$(bold "$(black_on_white "Checking git status in $(relative "$1")...")")"
|
|
51
|
+
echo "\n"
|
|
52
|
+
prompt_continue
|
|
53
|
+
cd $1
|
|
54
|
+
git status
|
|
55
|
+
echo "\n"
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function git_log () {
|
|
59
|
+
if [[ -z "$1" ]]; then
|
|
60
|
+
throw "Missing arguments. Usage: git_status <path>"
|
|
61
|
+
fi
|
|
62
|
+
echo "$(bold "$(black_on_white "Logging git history in $(relative "$1")...")")"
|
|
63
|
+
echo "\n"
|
|
64
|
+
cd $1
|
|
65
|
+
git log
|
|
66
|
+
echo "\n"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function git_pull_master () {
|
|
70
|
+
if [[ -z "$1" ]]; then
|
|
71
|
+
throw "Missing arguments. Usage: git_pull_master <path>"
|
|
72
|
+
fi
|
|
73
|
+
echo "$(bold "$(black_on_white "Pulling origin/master in $(relative "$1")...")")"
|
|
74
|
+
echo "\n"
|
|
75
|
+
prompt_continue
|
|
76
|
+
cd $1
|
|
77
|
+
git pull origin master
|
|
78
|
+
echo "\n"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function git_push_master () {
|
|
82
|
+
if [[ -z "$1" ]]; then
|
|
83
|
+
throw "Missing arguments. Usage: git_push_master <path>"
|
|
84
|
+
fi
|
|
85
|
+
echo "$(bold "$(black_on_white "Pushing origin/master in $(relative "$1")...")")"
|
|
86
|
+
echo "\n"
|
|
87
|
+
prompt_continue
|
|
88
|
+
cd $1
|
|
89
|
+
git push origin master
|
|
90
|
+
echo "\n"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function git_fetch_upstream_master () {
|
|
94
|
+
if [[ -z "$1" ]]; then
|
|
95
|
+
throw "Missing arguments. Usage: git_fetch_upstream_master <path>"
|
|
96
|
+
fi
|
|
97
|
+
echo "$(bold "$(black_on_white "Fetching upstream/master in $(relative "$1")...")")"
|
|
98
|
+
echo "\n"
|
|
99
|
+
prompt_continue
|
|
100
|
+
cd $1
|
|
101
|
+
git fetch upstream master
|
|
102
|
+
echo "\n"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function git_merge_upstream_master () {
|
|
106
|
+
if [[ -z "$1" ]]; then
|
|
107
|
+
throw "Missing arguments. Usage: git_merge_upstream_master <path>"
|
|
108
|
+
fi
|
|
109
|
+
echo "$(bold "$(black_on_white "Merging upstream/master in $(relative "$1")..")")"
|
|
110
|
+
echo "\n"
|
|
111
|
+
prompt_continue
|
|
112
|
+
cd $1
|
|
113
|
+
git merge upstream/master
|
|
114
|
+
echo "\n"
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function npm_install () {
|
|
118
|
+
if [[ -z "$1" ]]; then
|
|
119
|
+
throw "Missing arguments. Usage: npm_instann <path>"
|
|
120
|
+
fi
|
|
121
|
+
echo "$(bold "$(black_on_white "Installing NPM dependencies in $(relative "$1")..")")"
|
|
122
|
+
echo "\n"
|
|
123
|
+
prompt_continue
|
|
124
|
+
cd $1
|
|
125
|
+
npm install
|
|
126
|
+
echo "\n"
|
|
127
|
+
if [[ -n "$2" ]]; then
|
|
128
|
+
echo "installing $2"
|
|
129
|
+
npm install "$2"
|
|
130
|
+
echo "\n"
|
|
131
|
+
fi
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function build () {
|
|
135
|
+
if [[ -z "$1" || -z "$2" ]]; then
|
|
136
|
+
throw "Missing arguments. Usage: build <path> <build_command>"
|
|
137
|
+
fi
|
|
138
|
+
echo "$(bold "$(black_on_white "Building $(relative "$1")..")")"
|
|
139
|
+
echo "\n"
|
|
140
|
+
prompt_continue
|
|
141
|
+
cd $1
|
|
142
|
+
npm run $2
|
|
143
|
+
echo "\n"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function publish () {
|
|
147
|
+
if [[ -z "$1" ]]; then
|
|
148
|
+
throw "Missing arguments. Usage: npm_instann <path>"
|
|
149
|
+
fi
|
|
150
|
+
cd $1
|
|
151
|
+
read -p "$(bold "$(black_on_white "Do you want to publish to NPM ?")") (y/n) " cont
|
|
152
|
+
echo "\n"
|
|
153
|
+
if [[ "$cont" == "y" ]]; then
|
|
154
|
+
read -p "Enter OTP : " otp
|
|
155
|
+
if [[ "$otp" == "-" ]]; then
|
|
156
|
+
echo "\n"
|
|
157
|
+
return
|
|
158
|
+
fi
|
|
159
|
+
if [[ ${#otp} -eq 6 ]]; then
|
|
160
|
+
OTP=$otp npm publish
|
|
161
|
+
git_push_master "$1"
|
|
162
|
+
echo "\n"
|
|
163
|
+
else
|
|
164
|
+
throw "Invalid OTP. OTP must be 6 characters long."
|
|
165
|
+
fi
|
|
166
|
+
fi
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# INIT
|
|
170
|
+
echo "\n"
|
|
171
|
+
|
|
172
|
+
# LM TOOLS
|
|
173
|
+
git_status "$LMDIRPATH/lm-tools"
|
|
174
|
+
git_pull_master "$LMDIRPATH/lm-tools"
|
|
175
|
+
npm_install "$LMDIRPATH/lm-tools"
|
|
176
|
+
build "$LMDIRPATH/lm-tools" "build:src"
|
|
177
|
+
git_status "$LMDIRPATH/lm-tools"
|
|
178
|
+
publish "$LMDIRPATH/lm-tools"
|
|
179
|
+
|
|
180
|
+
# LM CLI
|
|
181
|
+
git_status "$LMDIRPATH/lm-cli"
|
|
182
|
+
git_pull_master "$LMDIRPATH/lm-cli"
|
|
183
|
+
npm_install "$LMDIRPATH/lm-cli" "@design-edito/tools@latest"
|
|
184
|
+
build "$LMDIRPATH/lm-cli" "build:src"
|
|
185
|
+
git_status "$LMDIRPATH/lm-cli"
|
|
186
|
+
publish "$LMDIRPATH/lm-cli"
|
|
187
|
+
|
|
188
|
+
# MXFB TOOLS
|
|
189
|
+
git_status "$MXFBDIRPATH/tools"
|
|
190
|
+
git_pull_master "$MXFBDIRPATH/tools"
|
|
191
|
+
git_fetch_upstream_master "$MXFBDIRPATH/tools"
|
|
192
|
+
git_merge_upstream_master "$MXFBDIRPATH/tools"
|
|
193
|
+
git_status "$MXFBDIRPATH/tools"
|
|
194
|
+
git_push_master "$MXFBDIRPATH/tools"
|
|
195
|
+
npm_install "$MXFBDIRPATH/tools"
|
|
196
|
+
build "$MXFBDIRPATH/tools" "build:src"
|
|
197
|
+
publish "$MXFBDIRPATH/tools"
|
|
198
|
+
|
|
199
|
+
# MXFB CLI
|
|
200
|
+
git_status "$MXFBDIRPATH/cli"
|
|
201
|
+
git_pull_master "$MXFBDIRPATH/cli"
|
|
202
|
+
git_fetch_upstream_master "$MXFBDIRPATH/cli"
|
|
203
|
+
git_merge_upstream_master "$MXFBDIRPATH/cli"
|
|
204
|
+
git_status "$MXFBDIRPATH/cli"
|
|
205
|
+
git_push_master "$MXFBDIRPATH/cli"
|
|
206
|
+
npm_install "$MXFBDIRPATH/cli" "@mxfb/tools@latest"
|
|
207
|
+
build "$MXFBDIRPATH/cli" "build:src"
|
|
208
|
+
publish "$MXFBDIRPATH/cli"
|
|
209
|
+
|
|
210
|
+
# END
|
|
211
|
+
echo "$(bold "Everything done. Bye.")\n"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import a from"node:process";import b from"node:url";import m from"node:path";import y from"node:os";import{program as g}from"commander";import s from"prompts";import{getConfig as P,updateConfig as w}from"@mxfb/tools/utils/node/mxfb-cli-config/index.js";import{spawn as _}from"node:child_process";var M=b.fileURLToPath(import.meta.url),v=m.dirname(M),d=a.cwd();g.name("@mxfb/mxfb-projects-sync").description("Keep in sync the different git repos for mxfb/tools & mxfb/cli").argument("[lmpath]","Path for Le Monde folder").argument("[mxfbpath]","Path for Mxfb folder").action(async(o,f,$)=>{let i=await P(!0);if(i instanceof Error)throw i;let{mxfb_projects_sync:{lm_path:p,mxfb_path:c}={}}=i,e="";if(o!==void 0)e=n(`${o}`);else{let{promptsLmPath:t}=await s({type:"text",name:"promptsLmPath",message:`Path to Le Monde directory (absolute or relative to ${d})`,initial:p??""});e=n(`${t}`)}let r="";if(f!==void 0)r=n(`${f}`);else{let{promptsMxfbPath:t}=await s({type:"text",name:"promptsMxfbPath",message:`Path to Mxfb directory (absolute or relative to ${d})`,initial:c??""});r=n(`${t}`)}console.log("Le Monde:",e),console.log("Mxfb: ",r);let{pathsAreOk:u}=await s({type:"confirm",name:"pathsAreOk",message:"Continue using those paths?"});if(u!==!0&&(console.log(`
|
|
3
|
+
Bye.
|
|
4
|
+
`),a.exit(0)),e!==p||r!==c){let{savePaths:t}=await s({type:"confirm",name:"savePaths",message:"Do you want to save those paths for the next time ?"});if(t===!0){let l=await w(x=>({...x,mxfb_projects_sync:{lm_path:e,mxfb_path:r}}),!0);if(l instanceof Error)throw l;console.log("Saved.")}}let h=_("sh",[m.join(v,"./assets/main.sh"),e,r],{stdio:"inherit"});h.on("error",t=>console.error(`Error: ${t.message}`)),h.on("close",t=>console.error(`main.sh exited with code ${t}`))});g.parse(a.argv);function n(o){return o.startsWith("~/")?m.join(y.homedir(),o.slice(2)):o}
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/mxfb-projects-sync/index.ts"],
|
|
4
|
+
"sourcesContent": ["import process from 'node:process'\nimport url from 'node:url'\nimport path from 'node:path'\nimport os from 'node:os'\nimport { program } from 'commander'\nimport prompts from 'prompts'\nimport { getConfig, updateConfig } from '@mxfb/tools/utils/node/mxfb-cli-config/index.js'\nimport { spawn } from 'node:child_process'\n\nconst __filename = url.fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\nconst CWD = process.cwd()\n\nprogram\n .name('@mxfb/mxfb-projects-sync')\n .description('Keep in sync the different git repos for mxfb/tools & mxfb/cli')\n .argument('[lmpath]', 'Path for Le Monde folder')\n .argument('[mxfbpath]', 'Path for Mxfb folder')\n .action(async (_lmpath, _mxfbpath, options) => {\n const config = await getConfig(true)\n if (config instanceof Error) throw config\n const { mxfb_projects_sync: {\n lm_path: configLmPath,\n mxfb_path: configMxfbPath\n } = {} } = config\n \n let lmPath: string = ''\n if (_lmpath !== undefined) { lmPath = resolveHome(`${_lmpath}`) }\n else {\n const { promptsLmPath } = await prompts({\n type: 'text',\n name: 'promptsLmPath',\n message: `Path to Le Monde directory (absolute or relative to ${CWD})`,\n initial: configLmPath ?? ''\n })\n lmPath = resolveHome(`${promptsLmPath}`)\n }\n \n let mxfbPath: string = ''\n if (_mxfbpath !== undefined) { mxfbPath = resolveHome(`${_mxfbpath}`) }\n else {\n const { promptsMxfbPath } = await prompts({\n type: 'text',\n name: 'promptsMxfbPath',\n message: `Path to Mxfb directory (absolute or relative to ${CWD})`,\n initial: configMxfbPath ?? ''\n })\n mxfbPath = resolveHome(`${promptsMxfbPath}`)\n }\n\n console.log('Le Monde:', lmPath)\n console.log('Mxfb: ', mxfbPath)\n const { pathsAreOk } = await prompts({\n type: 'confirm',\n name: 'pathsAreOk',\n message: 'Continue using those paths?'\n })\n if (pathsAreOk !== true) {\n console.log('\\nBye.\\n')\n process.exit(0)\n }\n if (lmPath !== configLmPath || mxfbPath !== configMxfbPath) {\n const { savePaths } = await prompts({\n type: 'confirm',\n name: 'savePaths',\n message: 'Do you want to save those paths for the next time ?'\n })\n if (savePaths === true) {\n const updated = await updateConfig(curr => ({\n ...curr,\n mxfb_projects_sync: {\n lm_path: lmPath,\n mxfb_path: mxfbPath\n }\n }), true)\n if (updated instanceof Error) throw updated\n console.log('Saved.')\n }\n }\n \n const shellScriptExecution = spawn('sh', [path.join(__dirname, './assets/main.sh'), lmPath, mxfbPath], { stdio: 'inherit' })\n shellScriptExecution.on('error', err => console.error(`Error: ${err.message}`))\n shellScriptExecution.on('close', code => console.error(`main.sh exited with code ${code}`))\n })\n\nprogram.parse(process.argv)\n\nfunction resolveHome (filePath: string) {\n if (filePath.startsWith('~/')) return path.join(os.homedir(), filePath.slice(2))\n return filePath\n}\n\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAOC,MAAS,WAChB,OAAOC,MAAU,YACjB,OAAOC,MAAQ,UACf,OAAS,WAAAC,MAAe,YACxB,OAAOC,MAAa,UACpB,OAAS,aAAAC,EAAW,gBAAAC,MAAoB,kDACxC,OAAS,SAAAC,MAAa,qBAEtB,IAAMC,EAAaR,EAAI,cAAc,YAAY,GAAG,EAC9CS,EAAYR,EAAK,QAAQO,CAAU,EACnCE,EAAMX,EAAQ,IAAI,EAExBI,EACG,KAAK,0BAA0B,EAC/B,YAAY,gEAAgE,EAC5E,SAAS,WAAY,0BAA0B,EAC/C,SAAS,aAAc,sBAAsB,EAC7C,OAAO,MAAOQ,EAASC,EAAWC,IAAY,CAC7C,IAAMC,EAAS,MAAMT,EAAU,EAAI,EACnC,GAAIS,aAAkB,MAAO,MAAMA,EACnC,GAAM,CAAE,mBAAoB,CAC1B,QAASC,EACT,UAAWC,CACb,EAAI,CAAC,CAAE,EAAIF,EAEPG,EAAiB,GACrB,GAAIN,IAAY,OAAaM,EAASC,EAAY,GAAGP,CAAO,EAAE,MACzD,CACH,G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AAE,CAAC,EAC9ED,EAAqB,GAAG,QAASE,GAAQ,QAAQ,MAAM,4BAA4BA,CAAI,EAAE,CAAC,CAC5F,CAAC,EAEHzB,EAAQ,MAAMJ,EAAQ,IAAI,EAE1B,SAASmB,EAAaW,EAAkB,CACtC,OAAIA,EAAS,WAAW,IAAI,EAAU5B,EAAK,KAAKC,EAAG,QAAQ,EAAG2B,EAAS,MAAM,CAAC,CAAC,EACxEA,CACT",
|
|
6
|
+
"names": ["process", "url", "path", "os", "program", "prompts", "getConfig", "updateConfig", "spawn", "__filename", "__dirname", "CWD", "_lmpath", "_mxfbpath", "options", "config", "configLmPath", "configMxfbPath", "lmPath", "resolveHome", "promptsLmPath", "mxfbPath", "promptsMxfbPath", "pathsAreOk", "savePaths", "updated", "curr", "shellScriptExecution", "err", "code", "filePath"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxfb/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.67",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Maxime Fabas",
|
|
6
6
|
"license": "ISC",
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"cli": "./cli/index.js",
|
|
16
16
|
"make-calendar": "./make-calendar/index.js",
|
|
17
17
|
"make-template": "./make-template/index.js",
|
|
18
|
-
"
|
|
18
|
+
"mxfb-projects-sync": "./mxfb-projects-sync/index.js",
|
|
19
19
|
"tree": "./tree/index.js",
|
|
20
|
+
"term-glossary": "./term-glossary/index.js",
|
|
20
21
|
"tumblr-crawler": "./tumblr-crawler/index.js"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@mxfb/tools": "^0.0.
|
|
24
|
+
"@mxfb/tools": "^0.0.43",
|
|
24
25
|
"commander": "^12.0.0",
|
|
25
26
|
"date-fns": "^3.6.0",
|
|
26
27
|
"jsdom": "^24.0.0",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"@types/jsdom": "^21.1.6",
|
|
32
33
|
"@types/node": "^20.11.30",
|
|
33
34
|
"@types/prompts": "^2.4.9",
|
|
35
|
+
"@types/puppeteer": "^7.0.4",
|
|
34
36
|
"@types/semver": "^7.5.8",
|
|
35
37
|
"esbuild": "^0.20.2",
|
|
36
38
|
"semver": "^7.6.0",
|
package/term-glossary/index.js
CHANGED
|
@@ -21,11 +21,14 @@ console.log(`: <<'END'
|
|
|
21
21
|
git push origin master
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
<<<<<<< HEAD
|
|
25
|
+
=======
|
|
24
26
|
2. Processes & IP
|
|
25
27
|
|
|
26
28
|
lsof -i :<port> # Liste les process utilisant le port <port>
|
|
27
29
|
ps aux | grep <processName> # Liste les process en cours en filtrant sur le nom
|
|
28
30
|
|
|
31
|
+
>>>>>>> origin/master
|
|
29
32
|
END
|
|
30
33
|
|
|
31
34
|
`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/term-glossary/index.ts"],
|
|
4
|
-
"sourcesContent": ["// [WIP] use commander\n\nconsole.log(`: <<'END'\n\n\u2039 TERM GLOSSARY \u203A\n\n1. git & GitHub\n\n 1.1 Forking\n\n 1.1.1 Creating the fork\n \n 1.1.2 Comparing\n\n git fetch upstream # r\u00E9cup upstream \u00E0 jour\n git status # Affiche le diff avec upstream/master\n git log HEAD..upstream/master # log les commits de upstream/master\n\n 1.1.3 Updating\n\n git merge upstream/master # r\u00E9cup\u00E8re upstream/master dans origin/master\n git push origin master\n\n\n2. Processes & IP\n\n lsof -i :<port> # Liste les process utilisant le port <port>\n ps aux | grep <processName> # Liste les process en cours en filtrant sur le nom\n\nEND\n\n`)\n"],
|
|
5
|
-
"mappings": "AAEA,QAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["// [WIP] use commander\n\nconsole.log(`: <<'END'\n\n\u2039 TERM GLOSSARY \u203A\n\n1. git & GitHub\n\n 1.1 Forking\n\n 1.1.1 Creating the fork\n \n 1.1.2 Comparing\n\n git fetch upstream # r\u00E9cup upstream \u00E0 jour\n git status # Affiche le diff avec upstream/master\n git log HEAD..upstream/master # log les commits de upstream/master\n\n 1.1.3 Updating\n\n git merge upstream/master # r\u00E9cup\u00E8re upstream/master dans origin/master\n git push origin master\n\n\n<<<<<<< HEAD\n=======\n2. Processes & IP\n\n lsof -i :<port> # Liste les process utilisant le port <port>\n ps aux | grep <processName> # Liste les process en cours en filtrant sur le nom\n\n>>>>>>> origin/master\nEND\n\n`)\n"],
|
|
5
|
+
"mappings": "AAEA,QAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAgCX",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/tumblr-crawler/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import w from"node:process";import d from"node:path";import{promises as p}from"node:fs";import b from"prompts";import{
|
|
2
|
+
import w from"node:process";import d from"node:path";import{promises as p}from"node:fs";import b from"prompts";import{program as g}from"commander";import{JSDOM as S}from"jsdom";import{parse as _}from"date-fns";import C from"@mxfb/tools/utils/agnostic/wait/index.js";import I from"@mxfb/tools/utils/agnostic/round-numbers/index.js";g.name("@mxfb/tumblr-crawler").description("Crawls a Tumblr blog");g.command("fetch").description("Fetch all pages DOM content").argument("url","Root URL of the tumblr blog").action(async e=>{let{outputPath:t}=await b({type:"text",name:"outputPath",message:"Please select an output path for the data files",initial:`${w.cwd()}/.tmblrcrwlr`}),a=e.trim(),o=[a];/^https?:\/\//i.test(a)||(a.startsWith("://")?o.unshift("https"):o.unshift("https://"));let r=new URL(o.join("")).toString().replace(/\/+$/igm,"");console.log("you wanna crawl",r);let s=await q(r,t),i=JSON.stringify(s,null,2),u=d.join(t,"shallow.json");console.log(`outputting fetched data (${s.length}) pages`),await p.mkdir(t,{recursive:!0}),await p.writeFile(u,i,{encoding:"utf-8"}),console.log("Wrote data at",u)});g.command("extract-posts").description("Axtracts post data from the outputs of tumblr-crawler fetch <url>").action(async()=>{let{shallowJsonPath:e}=await b({type:"text",name:"shallowJsonPath",message:"Please enter a shallow.json file path",initial:`${w.cwd()}/.tmblrcrwlr/shallow.json`}),t=await p.readFile(e,{encoding:"utf-8"}),a=JSON.parse(t),o=await F(a),n=Object.fromEntries(o),r=JSON.stringify(n,null,2),s=d.join(d.dirname(e),"extracted.json");await p.writeFile(s,r,{encoding:"utf-8"})});g.command("output").description("Fills missing post data").action(async()=>{let{extractedJsonPath:e}=await b({type:"text",name:"extractedJsonPath",message:"Please enter a extracted.json file path",initial:`${w.cwd()}/.tmblrcrwlr/extracted.json`}),t=await p.readFile(e,{encoding:"utf-8"}),a=JSON.parse(t),o=[];Object.entries(a).forEach(([s,i])=>{let{id:u,date:c,url:l,youtube_id:m,youtube_title:h,post_content:y}=i,f=c!==null?_(c,"EEE. MMMM d, yyyy '@' h:mm a",new Date).toISOString():null;o.push({publishOn:f,publishOnRaw:c,songTitle:y,youtubeId:m,youtubeTitle:h,postUrl:l,postId:u})});let n=JSON.stringify(o,null,2),r=d.join(d.dirname(e),"output.json");await p.writeFile(r,n,{encoding:"utf-8"})});g.parse(w.argv);async function q(e,t,a=0){let o=new Map,n=0+a;try{for(;;){n++;let s=`${e}/page/${n}`;if(n>200)break;console.log(s,"...");let i=await A(n,e);if(i===void 0){o.set(n,{isValid:!1,domString:"",dom:null,url:s});break}let{isValid:u,dom:c}=await $(i);if(o.set(n,{isValid:u,domString:i,dom:c,url:s}),!u)break;let l=Math.random()*2e3+2e3;console.log(`Waiting before new request... (${I(l/1e3,1)}s)
|
|
3
3
|
|
|
4
4
|
`),await C(l)}}catch(s){console.log("Something went wrong while crawling..."),console.log(s)}let r=[];return o.forEach((s,i)=>{r.push({number:i,url:s.url,content:s.domString,isValid:s.isValid})}),r}async function A(e,t){if(!Number.isInteger(e)||e<=0)throw new Error(`Page number must be a non-zero positive integer. Found: ${e}`);return await(await fetch(`${t}/page/${e}`)).text()}async function $(e){let t=new S(e),{window:{document:a}}=t,o=a.querySelector("#page");if(o===null)return{isValid:!1,dom:t};let n=o.querySelector("#content");return n===null?{isValid:!1,dom:t}:n.querySelectorAll("article.post").length===0?{isValid:!1,dom:t}:{isValid:!0,dom:t}}async function F(e){let t=new Map;for(let a of e)(await R(a))?.forEach((n,r)=>t.set(r,n));return t}async function R(e){let t=new Map,{number:a,url:o,content:n,isValid:r}=e;if(!r)return;let s=new S(n),{window:{document:i}}=s,u=i.querySelector("#page");if(u===null)return;let c=u.querySelectorAll("article.post");if(c.length!==0){for(let l of Array.from(c)){let m=l.getAttribute("id")?.split("post-").at(1);if(m===void 0)continue;let h=Array.from(l.classList).find(V=>V.trim().match(/^type\-/igm))?.replace(/^type\-/igm,""),f=l.querySelector(".post-panel .media")?.querySelector('iframe[src^="https://www.youtube.com/embed/"]')??null,J=f?.getAttribute("src")?.split("https://www.youtube.com/embed/").at(1)?.split("?").at(0),x=f?.getAttribute("title")??void 0,O=l.querySelector(".post-panel .copy")?.textContent?.trim(),P=l.querySelector(".post-panel .meta .meta-list"),D=P?.querySelector(".date a"),j=P?.querySelector(".permalink a"),M=D?.getAttribute("title"),E=j?.getAttribute("href");t.set(m,{id:m,url:E??null,date:M??null,type:h??null,post_element_outerhtml:l.outerHTML,youtube_id:J??null,youtube_title:x??null,post_content:O??null})}return t}}
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/tumblr-crawler/index.ts"],
|
|
4
|
-
"sourcesContent": ["import process from 'node:process'\nimport path from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport prompts from 'prompts'\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAOC,MAAU,YACjB,OAAS,YAAYC,MAAU,UAC/B,OAAOC,MAAa,UACpB,OAAS,
|
|
6
|
-
"names": ["process", "path", "fs", "prompts", "
|
|
4
|
+
"sourcesContent": ["import process from 'node:process'\nimport path from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport prompts from 'prompts'\nimport { program } from 'commander'\nimport { JSDOM } from 'jsdom'\nimport { parse as dateParse } from 'date-fns'\nimport wait from '@mxfb/tools/utils/agnostic/wait/index.js'\nimport roundNumbers from '@mxfb/tools/utils/agnostic/round-numbers/index.js'\nimport { beforeForcedExit, beforeExit } from '@mxfb/tools/utils/node/process-exit/index.js'\n\n// const browser = await puppeteer.launch()\n// beforeExit(async () => browser.close())\n// beforeForcedExit(async () => browser.close())\n\nprogram\n .name('@mxfb/tumblr-crawler')\n .description('Crawls a Tumblr blog')\n\nprogram\n .command('fetch')\n .description('Fetch all pages DOM content')\n .argument('url', 'Root URL of the tumblr blog')\n .action(async inputUrl => {\n const { outputPath } = await prompts({\n type: 'text',\n name: 'outputPath',\n message: 'Please select an output path for the data files',\n initial: `${process.cwd()}/.tmblrcrwlr`\n }) as { outputPath: string }\n const trimmedInput = inputUrl.trim()\n const urlChunks = [trimmedInput]\n if (!/^https?:\\/\\//i.test(trimmedInput)) {\n if (trimmedInput.startsWith('://')) urlChunks.unshift('https')\n else urlChunks.unshift('https://')\n }\n const url = new URL(urlChunks.join(''))\n const stringifiedUrl = url.toString().replace(/\\/+$/igm, '')\n console.log('you wanna crawl', stringifiedUrl)\n const shallowJson = await fetchPagesDom(stringifiedUrl, outputPath)\n const shallowJsonContent = JSON.stringify(shallowJson, null, 2)\n const outputShallowJsonPath = path.join(outputPath, `shallow.json`)\n console.log(`outputting fetched data (${shallowJson.length}) pages`)\n await fs.mkdir(outputPath, { recursive: true })\n await fs.writeFile(outputShallowJsonPath, shallowJsonContent, { encoding: 'utf-8' })\n console.log('Wrote data at', outputShallowJsonPath)\n // await browser.close()\n })\n\nprogram\n .command('extract-posts')\n .description('Axtracts post data from the outputs of tumblr-crawler fetch <url>')\n .action(async () => {\n const { shallowJsonPath } = await prompts({\n type: 'text',\n name: 'shallowJsonPath',\n message: 'Please enter a shallow.json file path',\n initial: `${process.cwd()}/.tmblrcrwlr/shallow.json`\n })\n const shallowJsonContent = await fs.readFile(shallowJsonPath, { encoding: 'utf-8' })\n const shallowJsonObj = JSON.parse(shallowJsonContent) as ShallowJson\n const extractedPages = await extractPages(shallowJsonObj)\n const postsDataObj = Object.fromEntries(extractedPages)\n const postsDataContent = JSON.stringify(postsDataObj, null, 2)\n const extractedPath = path.join(path.dirname(shallowJsonPath), 'extracted.json')\n await fs.writeFile(extractedPath, postsDataContent, { encoding: 'utf-8' })\n // await browser.close()\n })\n\ntype OutputPostData = {\n publishOn: string | null,\n publishOnRaw: string | null,\n songTitle: string | null,\n youtubeId: string | null,\n youtubeTitle: string | null,\n postUrl: string | null,\n postId: string | null\n}\n\nprogram\n .command('output')\n .description('Fills missing post data')\n .action(async () => {\n const { extractedJsonPath } = await prompts({\n type: 'text',\n name: 'extractedJsonPath',\n message: 'Please enter a extracted.json file path',\n initial: `${process.cwd()}/.tmblrcrwlr/extracted.json`\n })\n const extractedJsonContent = await fs.readFile(extractedJsonPath, { encoding: 'utf-8' })\n const extractedJsonObj = JSON.parse(extractedJsonContent) as Record<string, PostData>\n const output: OutputPostData[] = []\n Object.entries(extractedJsonObj).forEach(([_id, postData]) => {\n const { id, date, url, youtube_id, youtube_title, post_content } = postData\n const dt = date !== null ? dateParse(date, 'EEE. MMMM d, yyyy \\'@\\' h:mm a', new Date()).toISOString() : null\n output.push({\n publishOn: dt,\n publishOnRaw: date,\n songTitle: post_content,\n youtubeId: youtube_id,\n youtubeTitle: youtube_title,\n postUrl: url,\n postId: id\n })\n })\n const jsonOutput = JSON.stringify(output, null, 2)\n const outputPath = path.join(path.dirname(extractedJsonPath), 'output.json')\n await fs.writeFile(outputPath, jsonOutput, { encoding: 'utf-8' })\n })\n \nprogram.parse(process.argv)\n\ntype PageData = {\n isValid: boolean\n domString: string\n dom: JSDOM | null\n url: string\n}\n\ntype ShallowJson = Array<{\n number: number\n url: string\n content: string\n isValid: boolean\n}>\n\nasync function fetchPagesDom (rootUrl: string, outputPath: string, startOffset: number = 0) {\n const pagesMap = new Map<number, PageData>()\n let pagePos = 0 + startOffset\n try {\n while (true) {\n pagePos ++\n const url = `${rootUrl}/page/${pagePos}`\n if (pagePos > 200) break;\n console.log(url, '...')\n const domString = await fetchPostsPageContent(pagePos, rootUrl)\n if (domString === undefined) {\n pagesMap.set(pagePos, { isValid: false, domString: '', dom: null, url })\n break;\n }\n const { isValid, dom } = await validatePageContent(domString)\n pagesMap.set(pagePos, { isValid, domString, dom, url })\n if (!isValid) break;\n const delay = (Math.random() * 2000) + 2000\n console.log(`Waiting before new request... (${roundNumbers(delay / 1000, 1)}s)\\n\\n`)\n await wait(delay)\n }\n } catch (err) {\n console.log('Something went wrong while crawling...')\n console.log(err)\n }\n const shallowJson: ShallowJson = []\n pagesMap.forEach((pageData, pagePos) => {\n shallowJson.push({\n number: pagePos,\n url: pageData.url,\n content: pageData.domString,\n isValid: pageData.isValid\n })\n })\n return shallowJson\n}\n\nasync function fetchPostsPageContent (pagePos: number, rootUrl: string) {\n const isInteger = Number.isInteger(pagePos)\n if (!isInteger || pagePos <= 0) throw new Error(`Page number must be a non-zero positive integer. Found: ${pagePos}`)\n // const page = await browser.newPage()\n // page.goto(`${rootUrl}/page/${pagePos}`, { waitUntil: 'networkidle2' })\n // await page.waitForNavigation()\n // await wait(1000)\n // const content = await page.evaluate(() => {\n // try { return document.documentElement.outerHTML }\n // catch { return undefined }\n // })\n // page.close()\n return await (await fetch(`${rootUrl}/page/${pagePos}`)).text()\n // return content\n}\n\ntype PageValidationResult = {\n isValid: boolean\n dom: JSDOM\n}\n\nasync function validatePageContent (pageContent: string): Promise<PageValidationResult> {\n const dom = new JSDOM(pageContent)\n const { window: { document } } = dom\n const page = document.querySelector('#page')\n if (page === null) return { isValid: false, dom }\n const content = page.querySelector('#content')\n if (content === null) return { isValid: false, dom }\n const posts = content.querySelectorAll('article.post')\n if (posts.length === 0) return { isValid: false, dom }\n return { isValid: true, dom }\n}\n\ntype PostData = {\n id: string\n url: string | null\n date: string | null\n type: string | null\n post_element_outerhtml: string | null\n post_content: string | null\n youtube_id: string | null\n youtube_title: string | null\n}\n\nasync function extractPages (shallowJson: ShallowJson): Promise<Map<string, PostData>> {\n const postsData = new Map<string, PostData>()\n for (const shallowPage of shallowJson) {\n const extractedPage = await analysePage(shallowPage)\n extractedPage?.forEach((postData, postId) => postsData.set(postId, postData))\n }\n return postsData\n}\n\nasync function analysePage (shallowPage: ShallowJson[number]) {\n const postData = new Map<string, PostData>()\n const { number, url, content, isValid } = shallowPage\n if (!isValid) return;\n const dom = new JSDOM(content)\n const { window: { document } } = dom\n const page = document.querySelector('#page')\n if (page === null) return;\n const posts = page.querySelectorAll('article.post')\n if (posts.length === 0) return;\n for (const postElement of Array.from(posts)) {\n const id = postElement.getAttribute('id')?.split('post-').at(1)\n if (id === undefined) continue\n const type = Array\n .from(postElement.classList)\n .find(clss => clss.trim().match(/^type\\-/igm))\n ?.replace(/^type\\-/igm, '')\n const mediaContainer = postElement.querySelector('.post-panel .media')\n const youtubeIframeContainer = mediaContainer?.querySelector('iframe[src^=\"https://www.youtube.com/embed/\"]') ?? null\n const youtubeIframeId = youtubeIframeContainer\n ?.getAttribute('src')\n ?.split('https://www.youtube.com/embed/').at(1)\n ?.split('?').at(0)\n const youtubeIframeTitle = youtubeIframeContainer?.getAttribute('title') ?? undefined\n const postContent = postElement.querySelector('.post-panel .copy')?.textContent?.trim()\n const postMetaListElement = postElement.querySelector('.post-panel .meta .meta-list')\n const postDateElement = postMetaListElement?.querySelector('.date a')\n const postPermalinkElement = postMetaListElement?.querySelector('.permalink a')\n const postDate = postDateElement?.getAttribute('title')\n const postUrl = postPermalinkElement?.getAttribute('href')\n postData.set(id, {\n id,\n url: postUrl ?? null,\n date: postDate ?? null,\n type: type ?? null,\n post_element_outerhtml: postElement.outerHTML,\n youtube_id: youtubeIframeId ?? null,\n youtube_title: youtubeIframeTitle ?? null,\n post_content: postContent ?? null\n })\n }\n return postData\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAOC,MAAU,YACjB,OAAS,YAAYC,MAAU,UAC/B,OAAOC,MAAa,UACpB,OAAS,WAAAC,MAAe,YACxB,OAAS,SAAAC,MAAa,QACtB,OAAS,SAASC,MAAiB,WACnC,OAAOC,MAAU,2CACjB,OAAOC,MAAkB,oDAOzBJ,EACG,KAAK,sBAAsB,EAC3B,YAAY,sBAAsB,EAErCA,EACG,QAAQ,OAAO,EACf,YAAY,6BAA6B,EACzC,SAAS,MAAO,6BAA6B,EAC7C,OAAO,MAAMK,GAAY,CACxB,GAAM,CAAE,WAAAC,CAAW,EAAI,MAAMP,EAAQ,CACnC,KAAM,OACN,KAAM,aACN,QAAS,kDACT,QAAS,GAAGH,EAAQ,IAAI,CAAC,cAC3B,CAAC,EACKW,EAAeF,EAAS,KAAK,EAC7BG,EAAY,CAACD,CAAY,EAC1B,gBAAgB,KAAKA,CAAY,IAChCA,EAAa,WAAW,KAAK,EAAGC,EAAU,QAAQ,OAAO,EACxDA,EAAU,QAAQ,UAAU,GAGnC,IAAMC,EADM,IAAI,IAAID,EAAU,KAAK,EAAE,CAAC,EACX,SAAS,EAAE,QAAQ,UAAW,EAAE,EAC3D,QAAQ,IAAI,kBAAmBC,CAAc,EAC7C,IAAMC,EAAc,MAAMC,EAAcF,EAAgBH,CAAU,EAC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D,EAAY,UACpC,WAAYI,GAAmB,KAC/B,cAAeC,GAAsB,KACrC,aAAcC,GAAe,IAC/B,CAAC,CACH,CACA,OAAOrC,EACT",
|
|
6
|
+
"names": ["process", "path", "fs", "prompts", "program", "JSDOM", "dateParse", "wait", "roundNumbers", "inputUrl", "outputPath", "trimmedInput", "urlChunks", "stringifiedUrl", "shallowJson", "fetchPagesDom", "shallowJsonContent", "outputShallowJsonPath", "shallowJsonPath", "shallowJsonObj", "extractedPages", "extractPages", "postsDataObj", "postsDataContent", "extractedPath", "extractedJsonPath", "extractedJsonContent", "extractedJsonObj", "output", "_id", "postData", "id", "date", "url", "youtube_id", "youtube_title", "post_content", "dt", "jsonOutput", "rootUrl", "startOffset", "pagesMap", "pagePos", "domString", "fetchPostsPageContent", "isValid", "dom", "validatePageContent", "delay", "err", "pageData", "pageContent", "document", "page", "content", "postsData", "shallowPage", "analysePage", "postId", "number", "posts", "postElement", "type", "clss", "youtubeIframeContainer", "youtubeIframeId", "youtubeIframeTitle", "postContent", "postMetaListElement", "postDateElement", "postPermalinkElement", "postDate", "postUrl"]
|
|
7
7
|
}
|