@diuyuy/snippet-generator 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,5 +11,3 @@ To run:
11
11
  ```bash
12
12
  bun run index.ts
13
13
  ```
14
-
15
- This project was created using `bun init` in bun v1.3.5. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
package/dist/index.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
  `),f=JSON.stringify({prefix:y,description:x,body:S},null,2);await g.default.write(f),t.stop(),console.log(`
4
4
  Snippet\uC774 \uC131\uACF5\uC801\uC73C\uB85C \uC0DD\uC131\uB418\uC5C8\uC2B5\uB2C8\uB2E4!`),console.log(`-------
5
5
  `),console.log(f),console.log(m.default.blue.bold(`
6
- Clipboard\uC5D0 \uD14D\uC2A4\uD2B8\uAC00 \uBCF5\uC0AC\uB418\uC5C8\uC2B5\uB2C8\uB2E4!`))}catch(r){throw t.stop(),r}}async function q(){try{let e=await h.async(["**/*"],{ignore:["node_modules/**",".git/**","dist/**"],dot:!0});for(;await w(e),console.log(`
6
+ Clipboard\uC5D0 \uD14D\uC2A4\uD2B8\uAC00 \uBCF5\uC0AC\uB418\uC5C8\uC2B5\uB2C8\uB2E4!`))}catch(r){throw t.stop(),r}}async function q(){try{let e=await(0,h.default)(["**/*"],{ignore:["node_modules/**",".git/**","dist/**"],dot:!0});for(;await w(e),console.log(`
7
7
  ------------
8
8
  `),!!await(0,b.confirm)({message:"\uC0C8\uB85C\uC6B4 \uC2A4\uB2C8\uD3AB\uC744 \uC0DD\uC131\uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?",default:!1}););}catch(e){if(!(e instanceof Error&&e.name==="ExitPromptError"))throw e}}q();
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{confirm as y}from"@inquirer/prompts";import*as f from"fast-glob";import{input as a,search as u}from"@inquirer/prompts";import d from"chalk";import w from"clipboardy";import b from"fs";import h from"ora";async function l(e){let r=h("Generating...");try{let o=await u({message:"\uD30C\uC77C\uC744 \uC120\uD0DD\uD558\uC138\uC694:",source:async t=>t?e.filter(i=>i.toLowerCase().includes(t.toLowerCase())):[]}),n=b.readFileSync(o).toString(),p=await a({message:"prefix:",required:!0}),m=await a({message:"description:",default:""});for(let t=1;;t++){let s=await a({message:`$${t}\uB85C \uC218\uC815\uD560 \uB2E8\uC5B4:`,default:""});if(s==="")break;let i=new RegExp(s,"g");n=n.replace(i,`$${t}`)}r.start();let g=n.split(`
3
- `),c=JSON.stringify({prefix:p,description:m,body:g},null,2);await w.write(c),r.stop(),console.log(`
2
+ import{confirm as h}from"@inquirer/prompts";import y from"fast-glob";import{input as a,search as g}from"@inquirer/prompts";import u from"chalk";import d from"clipboardy";import w from"fs";import b from"ora";async function l(e){let r=b("Generating...");try{let o=await g({message:"\uD30C\uC77C\uC744 \uC120\uD0DD\uD558\uC138\uC694:",source:async t=>t?e.filter(i=>i.toLowerCase().includes(t.toLowerCase())):[]}),n=w.readFileSync(o).toString(),f=await a({message:"prefix:",required:!0}),p=await a({message:"description:",default:""});for(let t=1;;t++){let s=await a({message:`$${t}\uB85C \uC218\uC815\uD560 \uB2E8\uC5B4:`,default:""});if(s==="")break;let i=new RegExp(s,"g");n=n.replace(i,`$${t}`)}r.start();let m=n.split(`
3
+ `),c=JSON.stringify({prefix:f,description:p,body:m},null,2);await d.write(c),r.stop(),console.log(`
4
4
  Snippet\uC774 \uC131\uACF5\uC801\uC73C\uB85C \uC0DD\uC131\uB418\uC5C8\uC2B5\uB2C8\uB2E4!`),console.log(`-------
5
- `),console.log(c),console.log(d.blue.bold(`
6
- Clipboard\uC5D0 \uD14D\uC2A4\uD2B8\uAC00 \uBCF5\uC0AC\uB418\uC5C8\uC2B5\uB2C8\uB2E4!`))}catch(o){throw r.stop(),o}}async function x(){try{let e=await f.async(["**/*"],{ignore:["node_modules/**",".git/**","dist/**"],dot:!0});for(;await l(e),console.log(`
5
+ `),console.log(c),console.log(u.blue.bold(`
6
+ Clipboard\uC5D0 \uD14D\uC2A4\uD2B8\uAC00 \uBCF5\uC0AC\uB418\uC5C8\uC2B5\uB2C8\uB2E4!`))}catch(o){throw r.stop(),o}}async function x(){try{let e=await y(["**/*"],{ignore:["node_modules/**",".git/**","dist/**"],dot:!0});for(;await l(e),console.log(`
7
7
  ------------
8
- `),!!await y({message:"\uC0C8\uB85C\uC6B4 \uC2A4\uB2C8\uD3AB\uC744 \uC0DD\uC131\uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?",default:!1}););}catch(e){if(!(e instanceof Error&&e.name==="ExitPromptError"))throw e}}x();
8
+ `),!!await h({message:"\uC0C8\uB85C\uC6B4 \uC2A4\uB2C8\uD3AB\uC744 \uC0DD\uC131\uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?",default:!1}););}catch(e){if(!(e instanceof Error&&e.name==="ExitPromptError"))throw e}}x();
@@ -24,6 +24,11 @@ export async function generateSnippet(allFiles: string[]) {
24
24
  const buffer = fs.readFileSync(answer);
25
25
  let texts = buffer.toString();
26
26
 
27
+ const name = await input({
28
+ message: "Snippet name:",
29
+ required: true,
30
+ });
31
+
27
32
  const prefix = await input({
28
33
  message: "prefix:",
29
34
  required: true,
@@ -51,7 +56,11 @@ export async function generateSnippet(allFiles: string[]) {
51
56
  spinner.start();
52
57
  const body = texts.split("\n");
53
58
 
54
- const snippet = JSON.stringify({ prefix, description, body }, null, 2);
59
+ const snippet = JSON.stringify(
60
+ { [name]: { prefix, description, body } },
61
+ null,
62
+ 2
63
+ ).slice(1, -1);
55
64
  await clipboard.write(snippet);
56
65
 
57
66
  spinner.stop();
package/index.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { confirm } from "@inquirer/prompts";
4
- import * as fg from "fast-glob";
4
+ import fg from "fast-glob";
5
5
  import { generateSnippet } from "./generate-snippet";
6
6
 
7
7
  async function run() {
8
8
  try {
9
- const allFiles = await fg.async(["**/*"], {
9
+ const allFiles = await fg(["**/*"], {
10
10
  ignore: ["node_modules/**", ".git/**", "dist/**"],
11
11
  dot: true,
12
12
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diuyuy/snippet-generator",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "gsnippet": "./dist/index.js"
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/diuyuy/snippet-generator.git"
11
11
  },
12
12
  "scripts": {
13
- "build": "tsup index.ts --format esm,cjs --dts --clean --minify",
13
+ "build": "tsup index.ts --format esm,cjs --dts --clean --minify --external clipboardy",
14
14
  "test": "echo \"Error: no test specified\" && exit 1"
15
15
  },
16
16
  "module": "index.ts",