Skip to content

Commit efc97d9

Browse files
committed
🎉
0 parents  commit efc97d9

6 files changed

Lines changed: 814 additions & 0 deletions

File tree

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

bin/cli.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
// import { dirname, basename } from 'node:path';
3+
// import { existsSync, readFile } from "node:fs";
4+
import { resolve } from "node:path";
5+
import { argv } from "node:process";
6+
import url from "node:url";
7+
8+
const candidate= argv.splice(2, 1)[0];
9+
const filepath= candidate.startsWith('/') ? candidate : ( candidate.startsWith('file:///') ? url.fileURLToPath(candidate) : resolve(candidate) );
10+
argv[1]= filepath;
11+
await import(url.pathToFileURL(filepath).toString());

index.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import shelljs from "shelljs";
2+
export const {
3+
ls, find, dirs,
4+
cd, pwd, pushd, popd,
5+
cp, rm, mv, mkdir, ln, touch, tempdir,
6+
chmod,
7+
test, error,
8+
cat, sed, grep, sort, head, tail, uniq,
9+
which,
10+
exit, env, set,
11+
exec,
12+
config
13+
}= shelljs;
14+
15+
import chalk from "chalk";
16+
export { chalk, chalk as s };
17+
18+
import fetch from 'node-fetch';
19+
export { fetch };
20+
21+
import { log } from "node:console";
22+
export function echo(...messages){
23+
log(...messages.map(v=>
24+
v instanceof Error && config.verbose ? v :
25+
( String(v)==="[object Object]" ? v : String(v).replaceAll("\t", " ") )));
26+
}
27+
28+
/**
29+
* Returns object representation of given arguments. Script name is under `_name` key, arguments without `-`/`--` are under `_` key.
30+
* @param {NodeJS.Process.argv} argv
31+
* @param {Record<string, any>} initial Initial values
32+
* @returns {{ _name: string, _: string[] } & Record<string, any>}
33+
* @example
34+
* script arg1 --arg2=val -arg3 val --arg4
35+
* => { _name: "script", _: [ "arg1" ], arg2: "val", arg3: "val", arg4: true }
36+
* */
37+
export function parseArgsMinimal(initial= {}, argv= process.argv){
38+
const out= Object.create(initial);
39+
out._name= argv[1].slice(argv[1].lastIndexOf("/")+1);
40+
out._= [];
41+
const args= argv.slice(2);
42+
for(let i= 0, { length }= args; i<length; i+= 1){
43+
const item= args[i];
44+
if(0===item.indexOf("--")){
45+
const [ name, value= true ]= item.slice(2).split("=");
46+
Reflect.set(out, name, value);
47+
continue;
48+
}
49+
if(0!==item.indexOf("-")){
50+
out._.push(item);
51+
continue;
52+
}
53+
let next= args[i+1];
54+
if(!next || !next.indexOf("-"))
55+
next= true;
56+
Reflect.set(out, item.slice(1), next);
57+
if(next!==true)
58+
i+= 1;
59+
}
60+
if(!out._.length && initial._ && initial._.length)
61+
out._= initial._;
62+
return out;
63+
}
64+
65+
import { createInterface } from 'node:readline';
66+
/**
67+
* Promt user for answer.
68+
* @param {string} query
69+
* @param {{ completions: string[] }} options
70+
* */
71+
export function question(query= "", options= undefined){
72+
query= String(query);
73+
if(!/\s$/.test(query)) query+= "\n"+chalk.greenBright.bold('❯ ');
74+
75+
const rl= createInterface({
76+
input: process.stdin,
77+
output: process.stdout,
78+
terminal: true,
79+
completer: !options || !Array.isArray(options.completions) ? undefined :
80+
function completer(line){
81+
const completions= options.completions;
82+
const hits= completions.filter((c) => c.startsWith(line));
83+
return [hits.length ? hits : completions, line];
84+
},
85+
});
86+
87+
return new Promise(resolve=>
88+
rl.question(query,
89+
answer=> { rl.close(); resolve(answer); }));
90+
}
91+
92+
export async function stdin(){
93+
let buf = '';
94+
process.stdin.setEncoding('utf8');
95+
for await (const chunk of process.stdin)
96+
buf += chunk;
97+
return buf;
98+
}

0 commit comments

Comments
 (0)