@mxfb/cli 0.0.64 → 0.0.66
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/version.txt +1 -1
- package/cli/index.js +3 -3
- package/cli/index.js.map +2 -2
- package/make-template/index.js +1 -1
- package/make-template/index.js.map +2 -2
- package/package.json +2 -2
- package/term-glossary/index.js +5 -0
- package/term-glossary/index.js.map +2 -2
- package/tree/index.js +1 -1
- package/tree/index.js.map +2 -2
- package/tumblr-crawler/index.js +2 -2
- package/tumblr-crawler/index.js.map +2 -2
package/cli/assets/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.66
|
package/cli/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
`).map(o=>o.trim())}async function
|
|
4
|
-
`);console.log(i)}async function
|
|
2
|
+
import c from"node:process";import{promises as l}from"node:fs";import u from"node:url";import r from"node:path";import{spawn as h}from"node:child_process";import{program as t}from"commander";var g=u.fileURLToPath(import.meta.url),e=r.dirname(g);t.name("@mxfb/cli").description("The home of @mxfb/cli's project");t.command("list").description("list all the available commands").action(w);t.command("version").description("print current version of the package").action(x);var b=await m();b.forEach(n=>{t.command(n,{hidden:!0}).allowUnknownOption(!0).action(async(...i)=>{let[o,a,s,...p]=c.argv;if(s===void 0)return t.help();if(!(await m()).includes(s))return t.help();let d=r.join(e,"../",s,"index.js");h(d,p,{stdio:"inherit"}).on("error",f=>console.error(`Failed to start subprogram '${s}':`,f))})});t.parse(c.argv);async function m(){let n=r.join(e,"assets/list.txt");return(await l.readFile(n,{encoding:"utf-8"})).split(`
|
|
3
|
+
`).map(o=>o.trim())}async function w(){let i=(await m()).map(o=>{let a=Object.assign(new Array(24).fill(" "),o.split("")).join("");return o==="cli"?`${a} # npx @mxfb/cli help`:`${a} # npx @mxfb/cli ${o} help`}).join(`
|
|
4
|
+
`);console.log(i)}async function x(){let n=r.join(e,"assets/version.txt"),i=await l.readFile(n,{encoding:"utf-8"});console.log(i)}
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/cli/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cli/index.ts"],
|
|
4
|
-
"sourcesContent": ["import process from 'node:process'\nimport { promises as fs } from 'node:fs'\nimport url from 'node:url'\nimport path from 'node:path'\nimport { spawn } from 'node:child_process'\nimport { program } from 'commander'\n\nconst __filename = url.fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\nprogram\n .name('@
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAS,YAAYC,MAAU,UAC/B,OAAOC,MAAS,WAChB,OAAOC,MAAU,YACjB,OAAS,SAAAC,MAAa,qBACtB,OAAS,WAAAC,MAAe,YAExB,IAAMC,EAAaJ,EAAI,cAAc,YAAY,GAAG,EAC9CK,EAAYJ,EAAK,QAAQG,CAAU,EAEzCD,EACG,KAAK,
|
|
4
|
+
"sourcesContent": ["import process from 'node:process'\nimport { promises as fs } from 'node:fs'\nimport url from 'node:url'\nimport path from 'node:path'\nimport { spawn } from 'node:child_process'\nimport { program } from 'commander'\n\nconst __filename = url.fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\nprogram\n .name('@mxfb/cli')\n .description('The home of @mxfb/cli\\'s project')\n \nprogram\n .command('list')\n .description('list all the available commands')\n .action(printCommands)\n\nprogram\n .command('version')\n .description('print current version of the package')\n .action(printVersion)\n\nconst subCommands = await listCommands()\nsubCommands.forEach(subCommand => {\n program\n .command(subCommand, { hidden: true })\n .allowUnknownOption(true)\n .action(async (...args) => {\n const [_nodePath, _thisPath, targetCommand, ...forwardedArgs] = process.argv\n if (targetCommand === undefined) return program.help()\n const commandsList = await listCommands()\n if (!commandsList.includes(targetCommand)) return program.help()\n const subprogramPath = path.join(__dirname, '../', targetCommand, 'index.js')\n const subprocess = spawn(subprogramPath, forwardedArgs, { stdio: 'inherit' })\n subprocess.on('error', err => console.error(`Failed to start subprogram '${targetCommand}':`, err))\n })\n})\n\nprogram.parse(process.argv)\n\nasync function listCommands () {\n const listFilePath = path.join(__dirname, 'assets/list.txt')\n const list = await fs.readFile(listFilePath, { encoding: 'utf-8' })\n return list.split('\\n').map(e => e.trim())\n}\n\nasync function printCommands () {\n const list = await listCommands()\n const output = list\n .map(c => {\n const twentyFourCharName = Object.assign(\n new Array(24).fill(' ') as string[],\n c.split('') as string[]\n ).join('')\n if (c === 'cli') return `${twentyFourCharName} # npx @mxfb/cli help`\n return `${twentyFourCharName} # npx @mxfb/cli ${c} help`\n })\n .join('\\n')\n console.log(output)\n return;\n}\n\nasync function printVersion () {\n const versionFilePath = path.join(__dirname, 'assets/version.txt')\n const version = await fs.readFile(versionFilePath, { encoding: 'utf-8' })\n console.log(version)\n return;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAS,YAAYC,MAAU,UAC/B,OAAOC,MAAS,WAChB,OAAOC,MAAU,YACjB,OAAS,SAAAC,MAAa,qBACtB,OAAS,WAAAC,MAAe,YAExB,IAAMC,EAAaJ,EAAI,cAAc,YAAY,GAAG,EAC9CK,EAAYJ,EAAK,QAAQG,CAAU,EAEzCD,EACG,KAAK,WAAW,EAChB,YAAY,iCAAkC,EAEjDA,EACG,QAAQ,MAAM,EACd,YAAY,iCAAiC,EAC7C,OAAOG,CAAa,EAEvBH,EACG,QAAQ,SAAS,EACjB,YAAY,sCAAsC,EAClD,OAAOI,CAAY,EAEtB,IAAMC,EAAc,MAAMC,EAAa,EACvCD,EAAY,QAAQE,GAAc,CAChCP,EACG,QAAQO,EAAY,CAAE,OAAQ,EAAK,CAAC,EACpC,mBAAmB,EAAI,EACvB,OAAO,SAAUC,IAAS,CACzB,GAAM,CAACC,EAAWC,EAAWC,EAAe,GAAGC,CAAa,EAAIjB,EAAQ,KACxE,GAAIgB,IAAkB,OAAW,OAAOX,EAAQ,KAAK,EAErD,GAAI,EADiB,MAAMM,EAAa,GACtB,SAASK,CAAa,EAAG,OAAOX,EAAQ,KAAK,EAC/D,IAAMa,EAAiBf,EAAK,KAAKI,EAAW,MAAOS,EAAe,UAAU,EACzDZ,EAAMc,EAAgBD,EAAe,CAAE,MAAO,SAAU,CAAC,EACjE,GAAG,QAASE,GAAO,QAAQ,MAAM,+BAA+BH,CAAa,KAAMG,CAAG,CAAC,CACpG,CAAC,CACL,CAAC,EAEDd,EAAQ,MAAML,EAAQ,IAAI,EAE1B,eAAeW,GAAgB,CAC7B,IAAMS,EAAejB,EAAK,KAAKI,EAAW,iBAAiB,EAE3D,OADa,MAAMN,EAAG,SAASmB,EAAc,CAAE,SAAU,OAAQ,CAAC,GACtD,MAAM;AAAA,CAAI,EAAE,IAAIC,GAAKA,EAAE,KAAK,CAAC,CAC3C,CAEA,eAAeb,GAAiB,CAE9B,IAAMc,GADO,MAAMX,EAAa,GAE7B,IAAIY,GAAK,CACR,IAAMC,EAAqB,OAAO,OAChC,IAAI,MAAM,EAAE,EAAE,KAAK,GAAG,EACtBD,EAAE,MAAM,EAAE,CACZ,EAAE,KAAK,EAAE,EACT,OAAIA,IAAM,MAAc,GAAGC,CAAkB,wBACtC,GAAGA,CAAkB,oBAAoBD,CAAC,OACnD,CAAC,EACA,KAAK;AAAA,CAAI,EACZ,QAAQ,IAAID,CAAM,CAEpB,CAEA,eAAeb,GAAgB,CAC7B,IAAMgB,EAAkBtB,EAAK,KAAKI,EAAW,oBAAoB,EAC3DmB,EAAU,MAAMzB,EAAG,SAASwB,EAAiB,CAAE,SAAU,OAAQ,CAAC,EACxE,QAAQ,IAAIC,CAAO,CAErB",
|
|
6
6
|
"names": ["process", "fs", "url", "path", "spawn", "program", "__filename", "__dirname", "printCommands", "printVersion", "subCommands", "listCommands", "subCommand", "args", "_nodePath", "_thisPath", "targetCommand", "forwardedArgs", "subprogramPath", "err", "listFilePath", "e", "output", "c", "twentyFourCharName", "versionFilePath", "version"]
|
|
7
7
|
}
|
package/make-template/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import n from"node:process";import{promises as a,existsSync as
|
|
2
|
+
import n from"node:process";import{promises as a,existsSync as u}from"node:fs";import j from"node:url";import t from"node:path";import{spawn as w}from"node:child_process";import{program as i}from"commander";import y from"prompts";import P from"@mxfb/tools/utils/node/read-write-file/index.js";var k=j.fileURLToPath(import.meta.url),d=t.dirname(k),c=n.cwd();i.name("@mxfb/make-template").description("Generate in cwd a project template");i.command("html").description("make simple html project structure").action(x);i.command("react").description("make react + typescript project structure").action(S);i.parse(n.argv);async function x(){let e=t.join(d,"assets/html");if(!u(e))return console.error(`Could not find the template to copy at ${e}`),n.exit(1);let o=t.join(c,"html-template");await a.cp(e,o,{recursive:!0})}async function S(){let e=t.join(d,"assets/react");if(!u(e))return console.error(`Could not find the template to copy at ${e}`),n.exit(1);let o=t.join(c,"react-template");await a.cp(e,o,{recursive:!0});let{projectName:p}=await y({name:"projectName",message:"Project name ? (for package.json name field)",type:"text"}),g=t.join(o,"package.json");await P(g,r=>{let s=typeof r=="string"?r:r.toString(),f=JSON.parse(s);delete f.name;let h={name:p,...f};return`${JSON.stringify(h,null,2)}
|
|
3
3
|
`},{encoding:"utf-8"});let l=w(`cd ${o} && npm i`,{stdio:"inherit",shell:!0});await new Promise((r,s)=>{l.on("exit",()=>r(!0)),l.on("error",()=>s(!1))});let m=t.join(c,p);await a.rename(o,m),await a.rename(t.join(m,"gitignore"),t.join(m,".gitignore"))}
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/make-template/index.ts"],
|
|
4
|
-
"sourcesContent": ["import process from 'node:process'\nimport { promises as fs, existsSync } from 'node:fs'\nimport url from 'node:url'\nimport path from 'node:path'\nimport { spawn } from 'node:child_process'\nimport { program } from 'commander'\nimport prompts from 'prompts'\nimport readWriteFile from '@
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAS,YAAYC,EAAI,cAAAC,MAAkB,UAC3C,OAAOC,MAAS,WAChB,OAAOC,MAAU,YACjB,OAAS,SAAAC,MAAa,qBACtB,OAAS,WAAAC,MAAe,YACxB,OAAOC,MAAa,UACpB,OAAOC,MAAmB,
|
|
4
|
+
"sourcesContent": ["import process from 'node:process'\nimport { promises as fs, existsSync } from 'node:fs'\nimport url from 'node:url'\nimport path from 'node:path'\nimport { spawn } from 'node:child_process'\nimport { program } from 'commander'\nimport prompts from 'prompts'\nimport readWriteFile from '@mxfb/tools/utils/node/read-write-file/index.js'\n\nconst __filename = url.fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\nconst CWD = process.cwd()\n\nprogram\n .name('@mxfb/make-template')\n .description('Generate in cwd a project template')\n \nprogram\n .command('html')\n .description('make simple html project structure')\n .action(makeHtml)\n\nprogram\n .command('react')\n .description('make react + typescript project structure')\n .action(makeReact)\n\nprogram.parse(process.argv)\n\nasync function makeHtml () {\n const htmlTemplatePath = path.join(__dirname, 'assets/html')\n if (!existsSync(htmlTemplatePath)) {\n console.error(`Could not find the template to copy at ${htmlTemplatePath}`)\n return process.exit(1)\n }\n const targetPath = path.join(CWD, 'html-template')\n await fs.cp(htmlTemplatePath, targetPath, { recursive: true })\n}\n\nasync function makeReact () {\n const htmlTemplatePath = path.join(__dirname, 'assets/react')\n if (!existsSync(htmlTemplatePath)) {\n console.error(`Could not find the template to copy at ${htmlTemplatePath}`)\n return process.exit(1)\n }\n const defaultTargetPath = path.join(CWD, 'react-template')\n \n // Copy\n await fs.cp(htmlTemplatePath, defaultTargetPath, { recursive: true })\n const { projectName } = await prompts({\n name: 'projectName',\n message: 'Project name ? (for package.json name field)',\n type: 'text'\n })\n \n // Custom name\n const packageJsonPath = path.join(defaultTargetPath, 'package.json')\n await readWriteFile(packageJsonPath, rawContent => {\n const content = typeof rawContent === 'string'\n ? rawContent\n : rawContent.toString()\n const contentObj = JSON.parse(content) as Record<string, string>\n delete contentObj.name\n const newContentObj = {\n name: projectName,\n ...contentObj\n }\n return `${JSON.stringify(newContentObj, null, 2)}\\n`\n }, { encoding: 'utf-8' })\n \n // Install deps\n const npmISubprocess = spawn(`cd ${defaultTargetPath} && npm i`, { stdio: 'inherit', shell: true })\n await new Promise((resolve, reject) => {\n npmISubprocess.on('exit', () => resolve(true))\n npmISubprocess.on('error', () => reject(false))\n })\n\n // Rename project\n const targetPath = path.join(CWD, projectName)\n await fs.rename(defaultTargetPath, targetPath)\n\n // Rename gitignore\n await fs.rename(\n path.join(targetPath, 'gitignore'),\n path.join(targetPath, '.gitignore')\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAS,YAAYC,EAAI,cAAAC,MAAkB,UAC3C,OAAOC,MAAS,WAChB,OAAOC,MAAU,YACjB,OAAS,SAAAC,MAAa,qBACtB,OAAS,WAAAC,MAAe,YACxB,OAAOC,MAAa,UACpB,OAAOC,MAAmB,kDAE1B,IAAMC,EAAaN,EAAI,cAAc,YAAY,GAAG,EAC9CO,EAAYN,EAAK,QAAQK,CAAU,EACnCE,EAAMX,EAAQ,IAAI,EAExBM,EACG,KAAK,qBAAqB,EAC1B,YAAY,oCAAoC,EAEnDA,EACG,QAAQ,MAAM,EACd,YAAY,oCAAoC,EAChD,OAAOM,CAAQ,EAElBN,EACG,QAAQ,OAAO,EACf,YAAY,2CAA2C,EACvD,OAAOO,CAAS,EAEnBP,EAAQ,MAAMN,EAAQ,IAAI,EAE1B,eAAeY,GAAY,CACzB,IAAME,EAAmBV,EAAK,KAAKM,EAAW,aAAa,EAC3D,GAAI,CAACR,EAAWY,CAAgB,EAC9B,eAAQ,MAAM,0CAA0CA,CAAgB,EAAE,EACnEd,EAAQ,KAAK,CAAC,EAEvB,IAAMe,EAAaX,EAAK,KAAK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pC,CACF",
|
|
6
6
|
"names": ["process", "fs", "existsSync", "url", "path", "spawn", "program", "prompts", "readWriteFile", "__filename", "__dirname", "CWD", "makeHtml", "makeReact", "htmlTemplatePath", "targetPath", "defaultTargetPath", "projectName", "packageJsonPath", "rawContent", "content", "contentObj", "newContentObj", "npmISubprocess", "resolve", "reject"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxfb/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Maxime Fabas",
|
|
6
6
|
"license": "ISC",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"tumblr-crawler": "./tumblr-crawler/index.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@
|
|
23
|
+
"@mxfb/tools": "^0.0.32",
|
|
24
24
|
"commander": "^12.0.0",
|
|
25
25
|
"date-fns": "^3.6.0",
|
|
26
26
|
"jsdom": "^24.0.0",
|
package/term-glossary/index.js
CHANGED
|
@@ -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\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,
|
|
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,CA6BX",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/tree/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{program as b}from"commander";import w from"@
|
|
2
|
+
import{program as b}from"commander";import w from"@mxfb/tools/utils/node/list-subpaths/index.js";import f from"@mxfb/tools/utils/node/is-in-directory/index.js";var h=process.cwd();b.name("@mxfb/tree").description("List subpaths from the current working directory").argument("[depth]","Depth (optional, defaults to 0)").option("-f, --files [bool]","Include files",i,!0).option("-H, --hidden [bool]","Include hidden files",i,!0).option("-d, --directories [bool]","Include directories",i,!0).option("-s, --symlinks [bool]","Include symlinks",i,!0).option("-F, --follow [bool]","Follow symlinks",i,!1).option("-u, --unique [bool]","Ensures followed symlinks contents don't create duplicates",i,!1).option("-e, --exclude [pattern]","Regexp patterns to exclude from the result").option("-i, --include [pattern]","Regexp patterns to include in the result").action(async(n,e)=>{let r=n!==void 0?parseInt(n):0;if(Number.isNaN(r))return console.error("Depth should be a number"),process.exit(1);let s=(await w(h,{maxDepth:r,files:e.files,hidden:e.hidden,directories:e.directories,symlinks:e.symlinks,followSimlinks:e.follow,dedupeSimlinksContents:e.unique,exclude:m(e.exclude),include:m(e.include),returnRelative:!0})).reduce((u,l)=>{let a=x(l),c={value:l,level:a,children:[]};u.filter(t=>t.level===a-1&&f(l,t.value)).forEach(t=>t.children.push(c));let p=u.filter(t=>t.level===a+1&&f(t.value,l));return c.children.push(...p),[...u,c]},[]);console.log(h),g(s)});b.parse(process.argv);function i(n){let e=`${n}`.trim().toLowerCase();if(e==="true")return!0;if(e==="false")return!1}function m(n){if(typeof n!="string")return;let e=/^\/(.+)\/([a-z]*)$/,r=n.match(e);if(r===null)return;let[,o,s]=r;return new RegExp(o,s)}function x(n){return n.split("/").length-1}function g(n,e=0,r=[]){n.filter(o=>o.level===e).forEach((o,s,u)=>{let l=s===u.length-1,a=l?"\u2514\u2500\u2500":"\u251C\u2500\u2500",{value:c,level:d,children:p}=o,t=c.split("/").slice(d).join("/"),v=new Array(d).fill(null).map((y,k)=>r[k]===!0?" ":"\u2502 ").join("");console.log(`${v}${a} ${t}`),g(p,d+1,[...r,l])})}
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/tree/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/tree/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { program } from 'commander'\nimport listSubpaths from '@
|
|
5
|
-
"mappings": "AAAA,OAAS,WAAAA,MAAe,YACxB,OAAOC,MAAkB,
|
|
4
|
+
"sourcesContent": ["import { program } from 'commander'\nimport listSubpaths from '@mxfb/tools/utils/node/list-subpaths/index.js'\nimport isInDirectory from '@mxfb/tools/utils/node/is-in-directory/index.js'\n\nconst CWD = process.cwd()\n\ntype SubpathData = {\n value: string\n level: number\n children: SubpathData[]\n}\n\nprogram\n .name('@mxfb/tree')\n .description('List subpaths from the current working directory')\n .argument('[depth]', 'Depth (optional, defaults to 0)')\n .option('-f, --files [bool]', 'Include files', parseBoolean, true)\n .option('-H, --hidden [bool]', 'Include hidden files', parseBoolean, true)\n .option('-d, --directories [bool]', 'Include directories', parseBoolean, true)\n .option('-s, --symlinks [bool]', 'Include symlinks', parseBoolean, true)\n .option('-F, --follow [bool]', 'Follow symlinks', parseBoolean, false)\n .option('-u, --unique [bool]', 'Ensures followed symlinks contents don\\'t create duplicates', parseBoolean, false)\n .option('-e, --exclude [pattern]', 'Regexp patterns to exclude from the result')\n .option('-i, --include [pattern]', 'Regexp patterns to include in the result')\n .action(async (_depth, options) => {\n const depth = _depth !== undefined ? parseInt(_depth) : 0\n if (Number.isNaN(depth)) {\n console.error('Depth should be a number')\n return process.exit(1)\n }\n const subpaths = await listSubpaths(CWD, {\n maxDepth: depth,\n files: options.files,\n hidden: options.hidden,\n directories: options.directories,\n symlinks: options.symlinks,\n followSimlinks: options.follow,\n dedupeSimlinksContents: options.unique,\n exclude: makeRegexp(options.exclude),\n include: makeRegexp(options.include),\n returnRelative: true\n })\n const subpathsData = subpaths.reduce<SubpathData[]>((reduced, subpath) => {\n const level = getLevel(subpath)\n const thisSubpathData = {\n value: subpath,\n level,\n children: [] as SubpathData[]\n }\n // Parents\n const parents = reduced.filter(subpathData => subpathData.level === level - 1 && isInDirectory(subpath, subpathData.value))\n parents.forEach(parent => parent.children.push(thisSubpathData))\n // Children\n const children = reduced.filter(subpathData => subpathData.level === level + 1 && isInDirectory(subpathData.value, subpath))\n thisSubpathData.children.push(...children)\n return [...reduced, thisSubpathData]\n }, [])\n console.log(CWD)\n printSubpathData(subpathsData)\n })\n\nprogram.parse(process.argv)\n\nfunction parseBoolean (val: unknown) {\n const strVal = `${val}`.trim().toLowerCase()\n if (strVal === 'true') return true\n if (strVal === 'false') return false\n return undefined\n}\n\nfunction makeRegexp (strRegexp: unknown) {\n if (typeof strRegexp !== 'string') return undefined\n const validRegexpRegexp = /^\\/(.+)\\/([a-z]*)$/\n const inputMatches = strRegexp.match(validRegexpRegexp)\n if (inputMatches === null) return undefined\n const [, pattern, flags] = inputMatches\n return new RegExp(pattern!, flags!)\n}\n\nfunction getLevel (path: string) {\n const chunks = path.split('/')\n return chunks.length - 1\n}\n\nfunction printSubpathData (\n subpathsData: SubpathData[],\n level: number = 0,\n parentsAreLastMap: boolean[] = []) {\n subpathsData\n .filter(subpathData => subpathData.level === level)\n .forEach((subpathsData, pos, filtered) => {\n const isLast = pos === filtered.length - 1\n const indentChar = isLast ? '\u2514\u2500\u2500' : '\u251C\u2500\u2500'\n const { value, level, children } = subpathsData\n const toPrint = value.split('/').slice(level).join('/')\n const indentChars = new Array(level).fill(null).map((e, pos) => {\n if (parentsAreLastMap[pos] === true) return ' '\n else return '\u2502 '\n }).join('')\n console.log(`${indentChars}${indentChar} ${toPrint}`)\n printSubpathData(children, level + 1, [...parentsAreLastMap, isLast])\n })\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,WAAAA,MAAe,YACxB,OAAOC,MAAkB,gDACzB,OAAOC,MAAmB,kDAE1B,IAAMC,EAAM,QAAQ,IAAI,EAQxBH,EACG,KAAK,YAAY,EACjB,YAAY,kDAAkD,EAC9D,SAAS,UAAW,iCAAiC,EACrD,OAAO,qBAAsB,gBAAiBI,EAAc,EAAI,EAChE,OAAO,sBAAuB,uBAAwBA,EAAc,EAAI,EACxE,OAAO,2BAA4B,sBAAuBA,EAAc,EAAI,EAC5E,OAAO,wBAAyB,mBAAoBA,EAAc,EAAI,EACtE,OAAO,sBAAuB,kBAAmBA,EAAc,EAAK,EACpE,OAAO,sBAAuB,6DAA+DA,EAAc,EAAK,EAChH,OAAO,0BAA2B,4CAA4C,EAC9E,OAAO,0BAA2B,0CAA0C,EAC5E,OAAO,MAAOC,EAAQC,IAAY,CACj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B,EACtD,GAAIC,IAAiB,KAAM,OAC3B,GAAM,CAAC,CAAEC,EAASC,CAAK,EAAIF,EAC3B,OAAO,IAAI,OAAOC,EAAUC,CAAM,CACpC,CAEA,SAASZ,EAAUa,EAAc,CAE/B,OADeA,EAAK,MAAM,GAAG,EACf,OAAS,CACzB,CAEA,SAASR,EACPV,EACAI,EAAgB,EAChBe,EAA+B,CAAC,EAAG,CACnCnB,EACG,OAAOO,GAAeA,EAAY,QAAUH,CAAK,EACjD,QAAQ,CAACJ,EAAcoB,EAAKC,IAAa,CACxC,IAAMC,EAASF,IAAQC,EAAS,OAAS,EACnCE,EAAaD,EAAS,qBAAQ,qBAC9B,CAAE,MAAAE,EAAO,MAAApB,EAAO,SAAAK,CAAS,EAAIT,EAC7ByB,EAAUD,EAAM,MAAM,GAAG,EAAE,MAAMpB,CAAK,EAAE,KAAK,GAAG,EAChDsB,EAAc,IAAI,MAAMtB,CAAK,EAAE,KAAK,IAAI,EAAE,IAAI,CAACuB,EAAGP,IAClDD,EAAkBC,CAAG,IAAM,GAAa,OAChC,WACb,EAAE,KAAK,EAAE,EACV,QAAQ,IAAI,GAAGM,CAAW,GAAGH,CAAU,IAAIE,CAAO,EAAE,EACpDf,EAAiBD,EAAUL,EAAQ,EAAG,CAAC,GAAGe,EAAmBG,CAAM,CAAC,CACtE,CAAC,CACL",
|
|
6
6
|
"names": ["program", "listSubpaths", "isInDirectory", "CWD", "parseBoolean", "_depth", "options", "depth", "subpathsData", "makeRegexp", "reduced", "subpath", "level", "getLevel", "thisSubpathData", "subpathData", "parent", "children", "printSubpathData", "val", "strVal", "strRegexp", "validRegexpRegexp", "inputMatches", "pattern", "flags", "path", "parentsAreLastMap", "pos", "filtered", "isLast", "indentChar", "value", "toPrint", "indentChars", "e"]
|
|
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
|
|
2
|
+
import w from"node:process";import d from"node:path";import{promises as p}from"node:fs";import b from"prompts";import{parse as _}from"date-fns";import{program as g}from"commander";import{JSDOM as S}from"jsdom";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
|
-
`),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),
|
|
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 { parse as dateParse, format as dateFormat } from 'date-fns'\nimport { program } from 'commander'\nimport { JSDOM } from 'jsdom'\nimport wait from '@
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAa,eACpB,OAAOC,MAAU,YACjB,OAAS,YAAYC,MAAU,UAC/B,OAAOC,MAAa,UACpB,OAAS,SAASC,MAAuC,WACzD,OAAS,WAAAC,MAAe,YACxB,OAAS,SAAAC,MAAa,QACtB,OAAOC,MAAU,
|
|
4
|
+
"sourcesContent": ["import process from 'node:process'\nimport path from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport prompts from 'prompts'\nimport { parse as dateParse, format as dateFormat } from 'date-fns'\nimport { program } from 'commander'\nimport { JSDOM } from 'jsdom'\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,SAASC,MAAuC,WACzD,OAAS,WAAAC,MAAe,YACxB,OAAS,SAAAC,MAAa,QACtB,OAAOC,MAAU,2CACjB,OAAOC,MAAkB,oDAOzBH,EACG,KAAK,sBAAsB,EAC3B,YAAY,sBAAsB,EAErCA,EACG,QAAQ,OAAO,EACf,YAAY,6BAA6B,EACzC,SAAS,MAAO,6BAA6B,EAC7C,OAAO,MAAMI,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,EAC5DM,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Y,UACpC,WAAYI,GAAmB,KAC/B,cAAeC,GAAsB,KACrC,aAAcC,GAAe,IAC/B,CAAC,CACH,CACA,OAAOrC,EACT",
|
|
6
6
|
"names": ["process", "path", "fs", "prompts", "dateParse", "program", "JSDOM", "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
|
}
|