中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

網(wǎng)站推廣工作好做嗎國內(nèi)疫情最新消息

網(wǎng)站推廣工作好做嗎,國內(nèi)疫情最新消息,外貿(mào)免費建設網(wǎng)站制作,昆明比較好的網(wǎng)站開發(fā)公司初始化 新建文件夾初始化命令 npm init -ytsc --initnpm i types/nodenpm i typescript# 處理別名npm i -D tsc-alias -y 表示選項都為yes 安裝ts相關依賴 新建相關文件 bin 文件夾 src文件夾 commands 文件夾 (命令 utils 文件夾 (封裝方法) index.t…

初始化

  • 新建文件夾
  • 初始化命令
  npm init -ytsc --initnpm i @types/nodenpm i typescript# 處理別名npm i -D tsc-alias 

-y 表示選項都為yes
安裝ts相關依賴

在這里插入圖片描述

新建相關文件

  • bin 文件夾

  • src文件夾

    • commands 文件夾 (命令

    • utils 文件夾 (封裝方法)

      • index.ts文件
        export * from "./chalk"
    • index.ts 文件

      #! /usr/bin/env node
      console.log('hello gaogao')
      

      #! /usr/bin/env node
      前后不可有空格
      #!用于指定腳本的解釋程序,開發(fā)npm包這個指令一定要加

  • .gitignore 文件

	#basicnode_modulepackage-lock.json#buildbin
  • .npmrc 文件
	registry=https://mirrors.huaweicloud.com/repository/npm

TS配置

建【tsconfig.json】

{"compilerOptions": {"target": "ES6","module": "commonjs","outDir": "./bin", // 輸出地址 相對路徑"baseUrl": "./","strict": true,"moduleResolution": "node","esModuleInterop": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true,"resolveJsonModule": true,"paths":{"@":["src"],"@utils":["utils"],}},"include": ["./src","src/**/*.ts","src/**/*.d.ts"]
}

修改【package.json】

bin:執(zhí)行的文件或命令
scripts-build 處理ts文件

{"name": "gaogao-cli","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1","build": "tsc && tsc-alias"},"bin": {"gaogao": "/bin/src/index.js"},"keywords": [],"author": "","license": "ISC","dependencies": {"@types/figlet": "^1.7.0","@types/fs-extra": "^11.0.4","@types/inquirer": "^9.0.7","@types/log-symbols": "^3.0.0","@types/node": "^22.13.2","@types/shelljs": "^0.8.15","chalk": "^4.0.0","commander": "^9.0.0","download-git-repo": "^3.0.2","figlet": "^1.8.0","fs-extra": "^10.0.1","inquirer": "^8.2.1","loading-cli": "^1.1.2","log-symbols": "^4.1.0","ora": "^5.4.1","shelljs": "^0.8.5","table": "^6.9.0","typescript": "^5.7.3"},"devDependencies": {"tsc-alias": "^1.8.10"}
}

測試

ts語言需要先build

npm run build

build后bin文件夾下自動新增index.js文件
驗證修改是否生效都需要build

在這里插入圖片描述

cnpm link
gaogao

在這里插入圖片描述

安裝相關工具

安裝固定版本,有些版本會有bug

commander

https://www.npmjs.com/package/commander

  • 處理控制臺命令工具
  • 解析用戶輸入時一些參數(shù)
    • 例如 create 就是利用此工具做解析輔助
cnpm i commander@9.0.0
import {program} from 'commander'
import Pack from "../package.json"
program.version(Pack.version, "-v, --version");
program.parse(process.argv)//nodejs提供的屬性

封裝常用命令

  • commands文件夾下新建create文件夾 文件
import commandCreate from'./create'
// create見 create命令目錄
const commands:any = {'create <project-name>':{description:'create a project',option:[{cmd:'-f,--force',msg:'overwrite target directory if it exists'}],action:commandCreate}
}export default commands
import { Command } from "commander";
import Commands from "@commands";
//index.ts
Object.keys(Commands).forEach((command:any) => {const current:any = program.command(command);if (Commands[command].option && Commands[command].option.length) {let options = current.optionCommands[command].option.forEach((item: { cmd: string; msg: any }) => {current.option(item.cmd, item.msg || "");});}current.action(Commands[command].action);
});

chalk 美化工具

  • 該模塊用于添加顏色和樣式到控制臺輸出

效果見【figlet】

import chalk from 'chalk'
console.log("\r\n" + chalk.greenBright.bold('hello gaogao-cli'))

封裝字體處理

import chalk from 'chalk';
export const Cblue= (text:string) =>chalk.blue(text)
export const Cred= (text:string) =>chalk.red(text)
export const Cgreen= (text:string) =>chalk.green(text)

figlet

https://www.npmjs.com/package/figlet

  • 該模塊用于生成ASCII藝術字

具體字體可以去figlet官網(wǎng)查看

cnpm i figlet@1.5.2 @types/figlet
import chalk from 'chalk'
import figlet from 'figlet'
program.name("gaogao").description("gaogao-cli").usage("<command> [options]")// 用在內(nèi)置的幫助信息之后輸出自定義的額外信息.on("--help", () => {console.log("\r\n" + chalk.greenBright.bold(figlet.textSync("gaogao-cli", {font: "Standard",horizontalLayout: "default",verticalLayout: "default",width: 100,whitespaceBreak: true,})))console.log(`\r\n Run ${chalk.cyanBright(`gaogao-cli <command> --help`)} for detailed usage of given command.`)});

在這里插入圖片描述

inquirer -命令行交互工具

https://www.npmjs.com/package/inquirer

  • 該模塊用于實現(xiàn)交互式命令行界面
    • 例如vue詢問是否單元測試
cnpm i inquirer@8.2.1 @types/inquirer

在這里插入圖片描述

封裝inquirer

- lib文件夾下`新建interactive.ts `文件
import inquirer from 'inquirer';/*** @param {string} message 詢問提示語句* @returns {Object} 根據(jù)name屬性獲取用戶輸入的值{confirm: y/n}*/
export const inquirerConfirm = async (message:string): Promise<object> => {const answer = await inquirer.prompt({type: "confirm",name: "confirm",message,});return answer;
}/*** * @param {string} name 詢問事項* @param {string} message 詢問提示語句* @param {Array} choices 選擇模板列表,默認讀取對象的name屬性* @returns {Object} 根據(jù)name屬性獲取用戶輸入的值{請選擇項目模板: xxxxxx}*/
export const inquirerChoose = async (name:string,message:string, choices:Array<any>): Promise<any> => {const answer = await inquirer.prompt({type: 'list',name,message,choices,});return answer;
}/*** @param {Array} messages  詢問提示語句數(shù)組* @returns {Object} 結果對象*/
export const inquirerInputs = async (messages: Array<any>): Promise<object> => {const questions = messages.map(msg => {return {name: msg.name,type: "input",message: msg.message,}})const answers = await inquirer.prompt(questions);return answers
}

loading-cli

https://www.npmjs.com/package/loading-cli

  • utils 下新建loading文件
  • 在這里插入代碼片
//loading.ts
import loading, { Options, Loading } from "loading-cli";class Load {load: null | Loading;constructor() {this.load = null;}/*** @Descripttion: 開始loading狀態(tài)* @msg: * @param {Options} options* @return {*}*/  start  (options: Options | string) {if(!this.load){typeof options==='object'&&!options.frames&&(options.frames=['<','<','^','>','>','_','_'])this.load = loading(options).start()}else{this.load.start(options as string)}};stop () {this.load && this.load.stop();};succeed(text='success') {this.load && this.load.succeed(text);};warn(text: string) {this.load && this.load.warn(text);};info (text: string){this.load && this.load.info(text);};
}export default new Load();
// index.tsprogram.command("loading").description("View all available templates").action(() => {loading.start({color: "red",text: "begin",});setTimeout(() => {loading.warn("警告");setTimeout(() => {loading.info("提示");setTimeout(() => {loading.stop();}, 2000);}, 2000);}, 2000);})

在這里插入圖片描述

fs

https://url.nodejs.cn/api/fs.html

  • 該模塊用于對文件系統(tǒng)進行更強大的操作。
cnpm i fs-extra.0.1  /fs-extra

封裝文件處理方法

import fs from "fs";import { Cred } from "./chalk";export const readDir = (path: string): Promise<any> =>new Promise((res, rej) => {fs.readdir(path, (err) => {if (!err) res(true);res(false)});});export const mkdir = (path: string): Promise<any> =>new Promise((res, rej) => {fs.mkdir(path, (err) => {if (!err) res("");rej(`${Cred("Can not mak dir")} ${typeof err === "string" ? err : JSON.stringify(err)}`);});});export const rm = (path: string): Promise<any> =>new Promise((res, rej) => {fs.rm(path,{ recursive: true}, (err) => {if (!err) res("");rej(`${Cred("Can not remove dir:"+ path)} ${typeof err === "string" ? err : JSON.stringify(err)}`);});});

其他常用工具

# 安裝ora模塊,該模塊用于顯示動畫加載效果。
cnpm i ora@5.4.1
# 安裝download-git-repo模塊,該模塊用于下載并提取Github/Git(template本地)倉庫中的文件。
cnpm i download-git-repo@3.0.2
# 安裝handlebars模塊,該模塊用于處理模板文件。
cnpm i handlebars@4.7.6
# 安裝log-symbols模塊,該模塊用于在控制臺輸出不同類型的日志符號(√或×)。
cnpm i log-symbols@4.1.0
# 安裝axios模塊,該模塊用于發(fā)起HTTP請求。
cnpm i axios@0.26.1
# 安裝gitee-repo模塊,該模塊用于從Gitee倉庫中下載模板文件。
cnpm i gitee-repo@0.0.2
# 命令行界面表格內(nèi)容顯示
cnpm i table
# 基于nodejs的shell命令工具
cnpm i shelljs @types/shelljs 
# 在控制臺輸出不同類型的日志符號(√或×)
cnpm i log-symbols@4.1.0 @types/log-symbols

配置模版文件

  • lib文件夾下新建constants.ts 文件
//constants.ts
/*** 項目模板列表*/
export const templates = [{name: "vue-template",value: "direct:https://gitee.com/賬號/vue-template.git",desc: "基于vite的自定義vue項目模板",},
];/*** 項目信息*/
export const messages = [{name: "name",message: "請輸入項目名稱:",},{name: "description",message: "請輸入項目描述:",},
];
//index.ts
import { table } from 'table';import { templates } from '../lib/constants'// 查看模板列表
program
.command("ls")
.description("View all available templates")
.action(() => {const data = templates.map(item => [chalk.greenBright(item.name), chalk.white(item.value), chalk.white(item.desc)]);data.unshift([chalk.white("Template name"), chalk.white("Template address"), chalk.white("Template description")]);console.log(table(data));
})
gaogao ls

在這里插入圖片描述

create命令

create

  • commands文件夾下新建create文件夾 文件
    在這里插入圖片描述
import fs from "fs-extra";
import ora from "ora";
import inquirer from "inquirer";
import path from "path";
import { exec } from "child_process";
import {readDir,mkdir,rm,Cred,readFile,copyFolder,loading,inquirerChoose
} from "@utils";
import { TempLatesRepo, TempLatesName, templates } from "../../constant/repo";
export default async function (projectName: any, options: any) {const cwd = process.cwd();const targetDirectory = path.join(cwd, projectName);if (fs.existsSync(targetDirectory)) {if (options.force) {// 存在force配置項,直接覆蓋await fs.remove(targetDirectory);} else {// 不存在force配置    項,詢問是否覆蓋let { isOverwrite } = await inquirerChoose("isOverwrite","Target directory exists,Please choose an action.",[{name: "Overwrite",value: true,},{name: "Cancel",value: false,},]);if (!isOverwrite) {console.log("Cancel");return;} else {loading.start(`Removing ${projectName},please wait a minute`);await fs.remove(targetDirectory);loading.stop();}}}const spinner = ora("Creating a project......").start();try {await mkdir(targetDirectory);const TemplatePath = `${process.cwd()}/${TempLatesName}`;if (await readDir(TemplatePath)) {spinner.fail(Cred(`${TempLatesName} is existed!Please remove it`));process.abort();}spinner.stop()//下載模版git//TempLatesRepo  模版git地址exec(`git clone ${TempLatesRepo}`, async (err) => {if(err){spinner.fail(Cred("can not clone this repo,please try again later!"));spinner.fail(Cred(typeof err === "string" ? err : JSON.stringify(err)));process.abort();}const project =await readFile( `${TemplatePath}/project.json`)//讀取模版工程中project.json文件。存放模版listconst question = [{type: "list",message: "Please select a project template:",name: "template",choices: JSON.parse(project),// string[]},];const { template } = await inquirer.prompt(question);const newPath = targetDirectory;const oldPath = TemplatePath + "/" + template;loading.start("Template generation...");await copyFolder(oldPath, newPath);// 刪除克隆模板await rm(TemplatePath);loading.stop()});} catch (err) {console.log(Cred("Project creation failure"));spinner.fail(Cred(typeof err === "string" ? err : JSON.stringify(err)));process.abort();}
}

在這里插入圖片描述

  • 創(chuàng)建項目
    在這里插入圖片描述
  • 選擇模版
    在這里插入圖片描述
http://www.risenshineclean.com/news/6420.html

相關文章:

  • 怎么做阿里巴巴官網(wǎng)站模板建站教程
  • 深圳學校網(wǎng)站建設報價北京疫情最新新聞
  • 政府網(wǎng)站規(guī)范化建設廣告關鍵詞有哪些
  • 攜程做旅游的網(wǎng)站商城系統(tǒng)開發(fā)
  • 網(wǎng)站建設服務流程優(yōu)化網(wǎng)站結構一般包括
  • 做礦業(yè)的鄭州公司網(wǎng)站網(wǎng)站流量排名查詢工具
  • 做藝人資料卡的網(wǎng)站廣告策劃書
  • 關鍵詞排名優(yōu)化網(wǎng)站建設公司哪家好網(wǎng)站外鏈發(fā)布平臺
  • 做美女圖片網(wǎng)站犯法嗎廣告聯(lián)盟大全
  • 臨海大經(jīng)建設集團網(wǎng)站網(wǎng)站怎么做
  • wordpress下載seo含義
  • 杭州下沙做網(wǎng)站的論壇網(wǎng)站建設全包
  • 網(wǎng)站開發(fā)合同范本下載google網(wǎng)頁版登錄入口
  • 企業(yè)建站公司電話百度關鍵詞快排
  • 用ps做網(wǎng)站頁面seo查詢 站長工具
  • 大型網(wǎng)絡游戲排行榜2021前十名湖南專業(yè)關鍵詞優(yōu)化服務水平
  • 網(wǎng)站ui設計包括哪些原則谷歌seo 外貿(mào)建站
  • 怎么自建導購網(wǎng)站做淘客公司seo排名優(yōu)化
  • 網(wǎng)站開發(fā)語言 微信接口百度快照優(yōu)化培訓班
  • 河北省建設執(zhí)業(yè)資格中心網(wǎng)站網(wǎng)絡營銷推廣技巧
  • 西充縣住房和城鄉(xiāng)規(guī)劃建設局網(wǎng)站google網(wǎng)站增加關鍵詞
  • 哪些網(wǎng)站是做b2b的網(wǎng)站維護一年一般多少錢?
  • 網(wǎng)站建設容易嗎seo自媒體培訓
  • 連云港做網(wǎng)站最好惠州網(wǎng)站制作推廣
  • 專做海島游的網(wǎng)站如何交換友情鏈接
  • 網(wǎng)站建設設計解決方案網(wǎng)推拉新app推廣接單平臺
  • 電腦版qq在線登錄網(wǎng)頁入口百度地圖關鍵詞排名優(yōu)化
  • 南昌自助建站模板今天上海最新新聞事件
  • 網(wǎng)站 建設 成品小程序開發(fā)平臺官網(wǎng)
  • hbuilder做網(wǎng)站頁面背景色鄭州seo公司哪家好