xl1 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/jsd1/index.js +1 -1
- package/dist/ls1/index.js +6 -0
- package/package.json +2 -2
package/dist/jsd1/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
#! /usr/bin/env node
|
2
|
-
"use strict";var _chunkKLMDRKHJjs = require('../chunk-KLMDRKHJ.js');require('../chunk-
|
2
|
+
"use strict";var _chunkKLMDRKHJjs = require('../chunk-KLMDRKHJ.js');var _chunkVPQQEJWQjs = require('../chunk-VPQQEJWQ.js');require('../chunk-Y4GMOS4Y.js');require('../chunk-EJUO2FGU.js');require('../chunk-KNGN2YR6.js');var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var x=_chunkNEJSZOZXjs.b.call(void 0, (A,y)=>{var u=_chunkNEJSZOZXjs.a.call(void 0, "fs"),a=_chunkNEJSZOZXjs.a.call(void 0, "path"),k=_chunkNEJSZOZXjs.a.call(void 0, "axios"),$=_chunkNEJSZOZXjs.a.call(void 0, "marked"),j=_chunkNEJSZOZXjs.a.call(void 0, "glob"),W=_chunkNEJSZOZXjs.a.call(void 0, "https");async function v(t,n,p=!1){try{let d=await k({url:t,method:"GET",responseType:"stream",httpsAgent:new W.Agent({rejectUnauthorized:p})}),i=u.createWriteStream(n);return d.data.pipe(i),new Promise((h,m)=>{i.on("finish",h),i.on("error",m)})}catch(d){console.log("download error",t,n,d)}}async function E(t,n,p,d,i){let h=u.readFileSync(p,"utf-8"),m=$.lexer(h),w=o=>{let s=[];return o.forEach(e=>{e.type==="link"&&s.push(e),e.type==="table"&&e.rows.forEach(r=>{r.forEach(c=>{c.tokens&&(s=s.concat(w(c.tokens)))})}),e.tokens&&(s=s.concat(w(e.tokens))),e.items&&e.items.forEach(r=>{s=s.concat(w(r.tokens))})}),s};for(let o of w(m)){let s=[".mp3",".mp4",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".epub",".mobi",".zip",".rar",".7z",".tar",".gz"].find(e=>o.href.endsWith(e)||o.text.endsWith(e));if(o.type==="link"){let e=o.href;e.startsWith("https://github.com")&&e.includes("/blob/")&&(e=e.replace("github.com","raw.githubusercontent.com").replace("/blob/","/"));let r=a.basename(p).replace(".md",""),c=a.join(t,n,r);if(u.existsSync(c)||u.mkdirSync(c,{recursive:!0}),o.href.startsWith("https://www.slideshare.net")){let f=r+"_"+o.text.replace(/[<>:"/\\|?*\n\r]+/g,"_").replace(".pptx","").replace(".pdf","")+"_";_chunkKLMDRKHJjs.a.call(void 0, ).startDownloadSlideShare(o.href,c,f,["pptx","pdf"],!1)}else if(s){let f=r+"_"+o.text.replace(/[<>:"/\\|?*\n\r]+/g,"_").replace(s,"")+"_"+a.basename(decodeURIComponent(e));f.endsWith(s)||(f+=s);let b=a.join(c,f);if(!u.existsSync(b)&&(console.log(`Downloading ${e} to ${b}`),await v(e,b,i),d)){let g=new Date().toISOString(),q=`${n},${r},${f},${e},${g}
|
3
3
|
`;u.appendFileSync(d,q)}}else o.href.startsWith("https://qiita.com/")&&_chunkVPQQEJWQjs.a.call(void 0, ).qiitaDl(o.href,c,r+"_",null,!1)}}}function O(t){let n=t.docsDir||a.join(process.cwd(),"docs"),p=t.downloadDir||a.join(process.cwd(),"download");j.sync(`${n}/**/*.md`).forEach(i=>{let h=a.relative(n,i),m=a.dirname(h);E(p,m,i,t.csv,t.insecure).catch(console.error)})}var z={command:"*",describe:"jsd1",builder:{docs:{alias:"d",describe:"docs directory",demandOption:!1,default:"docs",type:"string"},output:{alias:"o",describe:"output directory",demandOption:!1,default:"download",type:"string"},csv:{alias:"c",describe:"csv log file",demandOption:!1,default:"output.csv",type:"string"},insecure:{alias:"k",describe:"allow insecure server connections",demandOption:!1,default:!1,type:"boolean"}},handler(t){(async()=>O({docsDir:t.docs,downloadDir:t.output,csv:t.csv,insecure:!t.insecure}))()}};y.exports=z});var F=()=>{let t=_chunkNEJSZOZXjs.a.call(void 0, "yargs").scriptName("jsd1");t.command(x());let n=t.parse()};F();
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#! /usr/bin/env node
|
2
|
+
"use strict";var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var w=_chunkNEJSZOZXjs.b.call(void 0, (R,y)=>{var x=_chunkNEJSZOZXjs.a.call(void 0, "sqlite3").verbose(),p=class{constructor(t){this.db=new x.Database(t,e=>{e&&console.error("Error opening database:",e)})}close(){return new Promise((t,e)=>{this.db.close(s=>{s?e(s):t()})})}debug(t,...e){t.debug&&console.log("[SQLite Debug]",...e)}generateCreateTableSql(t,e,s){if(!t||t.length===0)return null;let i=t[0],r=Object.keys(i).map((n,c)=>{let l="TEXT";return s&&n.toLocaleLowerCase()===s.toLocaleLowerCase()?`"${n}" ${l} PRIMARY KEY`:`"${n}" ${l}`});return`CREATE TABLE IF NOT EXISTS "${e}" (${r.join(", ")})`}generateUpsertSql(t,e,s){if(!t||t.length===0)return null;let i=Object.keys(t[0]),r=i.map(()=>"?").join(", "),a=i.slice(1).map(n=>`"${n}"=excluded."${n}"`).join(", ");return`INSERT INTO "${e}" (${i.map(n=>`"${n}"`).join(", ")})
|
3
|
+
VALUES (${r})
|
4
|
+
ON CONFLICT("${s}") DO UPDATE SET ${a}`}generateInsertSql(t,e){if(!t||t.length===0)return null;let s=Object.keys(t[0]),i=s.map(()=>"?").join(", ");return`INSERT INTO "${e}" (${s.map(r=>`"${r}"`).join(", ")})
|
5
|
+
VALUES (${i})`}generateUpdateSql(t,e,s){if(!t||t.length===0)return null;let r=Object.keys(t[0]).filter(a=>a.toLowerCase()!==s.toLowerCase()).map(a=>`"${a}"=?`).join(", ");return`UPDATE "${e}" SET ${r}
|
6
|
+
WHERE "${s}"=?`}async createTable(t,e,s,i){let r=this.generateCreateTableSql(t,e,s);if(!r)throw new Error("No data provided for table creation");return this.debug(i,"Creating table with SQL:",r),new Promise((a,n)=>{this.db.run(r,c=>{c?(this.debug(i,"Error creating table:",c),n(c)):(this.debug(i,"Table created successfully"),a())})})}async addIndex(t,e,s){let i=`CREATE INDEX IF NOT EXISTS idx_${t}_${e} ON "${t}" ("${e}")`;return this.debug(s,"Creating index with SQL:",i),new Promise((r,a)=>{this.db.run(i,n=>{n?(this.debug(s,"Error creating index:",n),a(n)):(this.debug(s,"Index created successfully"),r())})})}async tableExists(t,e){let s="SELECT name FROM sqlite_master WHERE type='table' AND name=?";return this.debug(e,"Checking table existence:",s,[t]),new Promise((i,r)=>{this.db.get(s,[t],(a,n)=>{a?(this.debug(e,"Error checking table existence:",a),r(a)):(this.debug(e,"Table exists:",!!n),i(!!n))})})}async alterTable(t,e,s){this.debug(s,"Checking columns for table:",e);let r=(await this.query(`PRAGMA table_info("${e}");`,[],s)).map(c=>c.name),n=Object.keys(t[0]).filter(c=>!r.includes(c));if(this.debug(s,"Columns to add:",n),n.length>0)for(let c of n){let l=`ALTER TABLE "${e}" ADD COLUMN "${c}" TEXT;`;this.debug(s,"Altering table with SQL:",l),await new Promise((d,h)=>{this.db.run(l,g=>{g?(this.debug(s,"Error altering table:",g),h(g)):(this.debug(s,`Column "${c}" added successfully`),d())})})}}async insert(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i,isAlterTable:r}=e;this.debug(e,"Starting insert operation:",{tableName:s,primaryKey:i,isAlterTable:r});try{await this.tableExists(s,e)?r&&(this.debug(e,"Table exists, checking for alterations"),await this.alterTable(t,s,e)):(this.debug(e,"Table does not exist, creating new table"),await this.createTable(t,s,i,e));let n=this.generateInsertSql(t,s);return this.debug(e,"Generated insert SQL:",n),new Promise((c,l)=>{let d=this.db.prepare(n);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((h,g)=>{let m=Object.values(h);this.debug(e,`Processing row ${g+1}/${t.length}:`),d.run(m)}),d.finalize(),this.db.run("COMMIT",h=>{h?(this.debug(e,"Error committing transaction:",h),l(h)):(this.debug(e,"Transaction committed successfully"),c())})})})}catch(a){throw this.debug(e,"Error in insert:",a),a}}async update(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i}=e;if(!i)throw new Error("Primary key is required for update operation");this.debug(e,"Starting update operation:",{tableName:s,primaryKey:i});try{let r=this.generateUpdateSql(t,s,i);return this.debug(e,"Generated update SQL:",r),new Promise((a,n)=>{let c=this.db.prepare(r);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((l,d)=>{let g=Object.keys(l).filter(m=>m.toLowerCase()!==i.toLowerCase()).map(m=>l[m]);g.push(l[i]),this.debug(e,`Processing row ${d+1}/${t.length}:`),c.run(g)}),c.finalize(),this.db.run("COMMIT",l=>{l?(this.debug(e,"Error committing transaction:",l),n(l)):(this.debug(e,"Transaction committed successfully"),a())})})})}catch(r){throw this.debug(e,"Error in update:",r),r}}async upsert(t,e){if(!t||t.length===0)throw new Error("No data provided");let{tableName:s,primaryKey:i,isAlterTable:r}=e;this.debug(e,"Starting upsert operation:",{tableName:s,primaryKey:i,isAlterTable:r});try{await this.tableExists(s,e)?r&&(this.debug(e,"Table exists, checking for alterations"),await this.alterTable(t,s,e)):(this.debug(e,"Table does not exist, creating new table"),await this.createTable(t,s,i,e)),i&&(this.debug(e,"Creating index for primary key:",i),await this.addIndex(s,i,e));let n=this.generateUpsertSql(t,s,i);return this.debug(e,"Generated upsert SQL:",n),new Promise((c,l)=>{let d=this.db.prepare(n);this.db.serialize(()=>{this.debug(e,"Beginning transaction"),this.db.run("BEGIN TRANSACTION"),t.forEach((h,g)=>{let m=Object.values(h);this.debug(e,`Processing row ${g+1}/${t.length}:`,m.length),d.run(m)}),d.finalize(),this.db.run("COMMIT",h=>{h?(this.debug(e,"Error committing transaction:",h),l(h)):(this.debug(e,"Transaction committed successfully"),c())})})})}catch(a){throw this.debug(e,"Error in upsert:",a),a}}async query(t,e=[],s){return this.debug(s,"Executing query:",t,"with params:",e),new Promise((i,r)=>{this.db.all(t,e,(a,n)=>{a?(this.debug(s,"Error executing query:",a),r(a)):(this.debug(s,"Query results:",n.length),i(n))})})}},q=async(u,t)=>{let{dbPath:e,tableName:s,primaryKey:i,isAlterTable:r}=t,a=new p(e);try{await a.upsert(u,t),console.log(`Data saved to ${s} successfully`)}catch(n){console.error(n)}finally{await a.close()}};y.exports={SqliteUtil:p,sqliteUpsert:q}});var $=_chunkNEJSZOZXjs.b.call(void 0, (v,S)=>{var C=_chunkNEJSZOZXjs.a.call(void 0, "fs"),o=_chunkNEJSZOZXjs.a.call(void 0, "path"),N=_chunkNEJSZOZXjs.a.call(void 0, "glob");function O(u){u=o.resolve(u);let t=[];try{return N.sync(o.join(u,"**"),{ignore:["**/node_modules/**","**/py_modules/**","**/vendor/**","**/.ipynb_checkpoints/**","**/.nuxt/**","**/tmp/**","**/dist/**","**/cache/**","**/.angular/**","**/.cache/**","**/.sfdx/**","**/.sf/**","**/.DS_Store","**/.AppleDouble","**/.LSOverride"]}).forEach(s=>{let i=C.statSync(s);if(i.isFile()){let r={id:s,dir:o.parse(s).dir,fileName:o.parse(s).name,extension:o.parse(s).ext,dir1:o.basename(o.dirname(s)),dir2:o.basename(o.dirname(o.dirname(s))),dir3:o.basename(o.dirname(o.dirname(o.dirname(s)))),dir4:o.basename(o.dirname(o.dirname(o.dirname(o.dirname(s))))),size:i.size};t.push(r)}}),t}catch(e){return console.error("Error reading directory:",e),[]}}S.exports={getFilesInfo:O}});var{sqliteUpsert:A}=w(),{getFilesInfo:L}=$(),E=_chunkNEJSZOZXjs.a.call(void 0, "path"),f={command:"*",describe:"ls1",builder:{input:{alias:"i",describe:"input dir",demandOption:!0,type:"string"},output:{alias:"o",describe:"output",demandOption:!1,type:"string"}},handler(u){(async()=>{let t=L(u.input);u.output&&u.output.endsWith(".db")?A(t,{dbPath:u.output,tableName:E.basename(E.dirname(E.resolve(u.output)))+"_resource",primaryKey:"id",isAlterTable:!0}):console.log(JSON.stringify(t,null,2))})()}},j=()=>{let u=_chunkNEJSZOZXjs.a.call(void 0, "yargs").scriptName("ls1");u.command(f);let t=u.parse()};j();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "xl1",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.3",
|
4
4
|
"description": "just some xlsx script.",
|
5
5
|
"bin": {
|
6
6
|
"bash1": "dist/bash1/index.js",
|
@@ -10,8 +10,8 @@
|
|
10
10
|
"jsh1": "dist/jsh1/index.js",
|
11
11
|
"jsd1": "dist/jsd1/index.js",
|
12
12
|
"jsss": "dist/jsss/index.js",
|
13
|
+
"ls1": "dist/ls1/index.js",
|
13
14
|
"qidl": "dist/qidl/index.js",
|
14
|
-
"scan-dir": "dist/scan-dir/index.js",
|
15
15
|
"ssdl": "dist/ssdl/index.js",
|
16
16
|
"xl1": "dist/xl1/index.js"
|
17
17
|
},
|