JS로 휴지통 프로그램을 빌드하고 npm pkg로 만들고 게시하십시오.
                                            
                                                
                                                
                                                
                                                
                                                
                                                 21063 단어  bashnpmjavascriptnode
                    
Hi, in this post, we'll create trash program by
JS,
after create it, this program will be npm package.
전제 조건
계속 진행하기 전에 다음이 필요합니다.
갑시다
우리는 만들 것입니다
package.json첫 번째 명령은
npm init$ npm init
이름을 짓겠습니다
manx그래서 당신은 이것을 가지고 있어야합니다 ...
{
  "name": "@your_npm_user_name/your_proj_name",
  "version": "1.0.0",
  "description": "Cli app can move files/folders to the trash without any dangerous",
  "main": "cli.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://Git_Repos_Site/Your_Git_Repo"
  },
  "keywords": [
    "cli-app",
    "cli",
    "trash"
  ],
  "author": "Your_Name",
  "license": "ISC"
}
package-lock.json 를 원하지 않으므로 다음을 입력하십시오.$ touch .npmrc
in
.npmrc
package-lock=false
now we'll install @abdfnx/hac_k & trash
$ npm i @abdfnx/hac_k trash
좋아, 만들자
cli.jsin
cli.js
#!/usr/bin/env node
"use strict";
이제 패키지가 필요합니다.
#!/usr/bin/env node
"use strict";
const hac_k = require("@abdfnx/hac_k");
const manx = require("trash");
좋은, 두 개의 변수도 생성
// Ignore all flags of `rm` program.
const ignoredFlags = ["r", "f", "i", "d", "P", "R", "v", "W"];
const ignoredFlagsConfig = {};
이 변수는 매우 중요하므로
for 루프를 만듭니다.for (const flag of ignoredFlags) {
    ignoredFlagsConfig[flag] = {
        type: "boolean",
    };
}
가장 중요한 변수는
cliconst cli = hac_k(
    `
    Usage
      $ manx <file/folder> […]
    Examples
      # file
      $ manx xcode.tsx layout.tsx edge.tsx
      $ manx '*.tsx' '!xcode.tsx'
      # folder
      $ manx app
    `,
    {
        flags: {
            ...ignoredFlagsConfig,
        },
    }
);
그러나 사용자가 공백을 입력하면
if 문이 필요합니다.if (cli.input.length === 0) {
    console.error("Specify at least one path");
    process.exit(1);
}
끝에 추가
manx(cli.input);
파일의 최종 결과
#!/usr/bin/env node
"use strict";
const hac_k = require("@abdfnx/hac_k");
const manx = require("trash");
// Ignore all flags of `rm` program.
const ignoredFlags = ["r", "f", "i", "d", "P", "R", "v", "W"];
const ignoredFlagsConfig = {};
for (const flag of ignoredFlags) {
    ignoredFlagsConfig[flag] = {
        type: "boolean",
    };
}
const cli = hac_k(
    `
    Usage
      $ manx <file/folder> […]
    Examples
      # file
      $ manx xcode.tsx layout.tsx edge.tsx
      $ manx '*.tsx' '!xcode.tsx'
      # folder
      $ manx app
    `,
    {
        flags: {
            ...ignoredFlagsConfig,
        },
    }
);
if (cli.input.length === 0) {
    console.error("Specify at least one path");
    process.exit(1);
}
manx(cli.input);
좋습니다. 이제 테스트해 보겠습니다.
package.json로 이동하여 bin , engines , files props를 추가하세요.{
  "name": "@your_npm_user_name/your_proj_name",
  "version": "1.0.0",
  "description": "Cli app can move files/folders to the trash without any dangerous",
  "main": "cli.js",
  "bin": {
        "manx": "cli.js"
  },
  "engines": {
        "node": ">=10"
  },
  "files": [
        "cli.js"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://Git_Repos_Site/Your_Git_Repo"
  },
  "keywords": [
    "cli-app",
    "cli",
    "trash"
  ],
  "author": "Your_Name",
  "license": "ISC",
  "dependencies": {
    "@abdfnx/hac_k": "^1.0.2",
    "trash": "^7.0.0"
  }
}
유형
npm link$ npm link
테스트용 파일 및 폴더 추가
$ touch test_file && mkdir test_folder
이제 기다리고 기다리던 순간, 터미널에서
$ manx --help
    Usage
      $ manx <file/folder> […]
    Examples
      # file
      $ manx xcode.tsx layout.tsx edge.tsx
      $ manx '*.tsx' '!xcode.tsx'
      # folder
      $ manx app
$ manx test_file test_folder
축하합니다. 이제 훌륭한 프로그램이 생겼습니다...
npm 게시(선택 사항)
멋진 프로젝트를 npm에 게시하려면 저를 팔로우하세요.
게시하기 전에 일부 파일을 추가하십시오.
.editorconfig , .gitattributes , .gitignore 및 .travis.yml선택 사항이지만 만드는 것이 좋습니다.
.editorconfigroot = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.yml]
indent_style = space
indent_size = 2
.gitattributes* text=auto eol=lf
.gitignorenode_modules
yarn.lock
.travis.ymllanguage: node_js
node_js:
  - '14'
  - '12'
  - '10'
좋아, 입력
$ npm unlink
이제 npm에 로그인해야 합니다.
$ npm login
publish
$ npm publish --access=public
설치하려면 전역적으로 설치해야 합니다.
$ npm i -g YOUR_PKG
npm에서 패키지를 볼 수 있습니다.
방문https://www.npmjs.com/package/YOUR_PKG
여기에 쓰레기 프로그램과 npm 패키지가 있습니다 ...
즐감하시고 다음에 뵙겠습니다.
Reference
이 문제에 관하여(JS로 휴지통 프로그램을 빌드하고 npm pkg로 만들고 게시하십시오.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/abdfnx/build-trash-program-by-js-and-make-it-npm-pkg-publish-it-3pbj텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)