Skip to content

Commit

Permalink
拉取内网仓库前端模板
Browse files Browse the repository at this point in the history
  • Loading branch information
zy123123 committed Nov 4, 2020
1 parent 002bdfb commit 8b37f63
Show file tree
Hide file tree
Showing 9 changed files with 898 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[alias]
amend = commit --amend
amendf = commit --amend --no-edit
br = branch
ct = commit
co = checkout
cp = cherry-pick
df = diff
ds = diff --staged
l = log
lg = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
lp = log --pretty=oneline
sa = stash apply
sh = show
ss = stash save
st = status

[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "status"]
added = yellow
changed = green
untracked = cyan
[color "diff"]
meta = yellow
frag = magenta bold
commit = yellow bold
old = red bold
new = green bold
whitespace = red reverse
[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
newHighlight = green bold 22

[user]
email = [email protected]
name = zhangyiming
107 changes: 107 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

examples/
lib/
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# private-cli
私有库搭建CLI脚手架

# 本地环境调试
```
npm link
private init template
```

# 安装
```
npm install -g @private/cli
# 或者
yarn global add @private/cli
```
你可以用这个命令来检查其版本是否正确:
```
private --version
```

# 升级
如需升级全局的 Private CLI 包,请运行:
```
npm update -g @private/cli
# 或者
yarn global upgrade --latest @private/cli
```

# 部署npm
```
npm login 输入你的用户名、密码、邮箱
npm publish 发布
```

# 更新版本号
```
npm version patch
npm version minor
npm version major
```

# 坑位解决
如果npm设置了淘宝镜像,请换回原来的npm下载地址
```
npm config set registry https://registry.npmjs.org
```
查看当前npm源
```
npm config ls
```

# 更新日志:

## 0.0.1
- ✨拉取内网仓库前端模板
44 changes: 44 additions & 0 deletions bin/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
const glob = require('glob')
const program = require('commander')
const inquirer = require("inquirer") //命令行答询
const deleteFolder = require("../libs/file")
program.version(require('../package.json').version)

// 初始化项目
function initMethods() {
program
.command('init <name>')
.description('初始化项目模板')
.action(
require('../libs/index')
)
program.parse(process.argv)
}

const list = glob.sync('*') // 遍历当前目录
if (list.includes("template")) { //template代表你自己项目模板名称
inquirer
.prompt([
{
type: "input",
name: "delJudge",
message: "当前目录已存在模板项目,是否删除重新创建,Yes Or No",
}
])
.then((answers) => {
if (answers.delJudge.toLowerCase() === "yes") {
deleteFolder(`${process.cwd()}/template`)
.then(() => {
initMethods()
})
.catch(() => {
process.exit()
})
} else {
process.exit()
}
})
} else {
initMethods()
}
13 changes: 13 additions & 0 deletions libs/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const download = require('simple-git')
module.exports.clone = async (repo) => {
const ora = require('ora')
const process = ora(`下载.....${repo}`)
process.start()
await
download()
.silent(true)
.clone(repo)
.then(status => { return })
.catch(err => { console.log("err::", err) });
process.succeed()
}
26 changes: 26 additions & 0 deletions libs/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require("fs");
// 根据问答操作文件
const deleteFolder = path => {
let files = [];
return new Promise((resolve, reject) => {
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function (file, index) {
let curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
deleteFolder(curPath);
resolve()
} else {
fs.unlinkSync(curPath);
resolve()
}
});
fs.rmdirSync(path);
resolve()
} else {
reject()
}
})
}

module.exports = deleteFolder;
71 changes: 71 additions & 0 deletions libs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const ora = require('ora')
const open = require('open')
const clear = require('clear')
const chalk = require('chalk')
const inquirer = require("inquirer") //命令行答询
const { promisify } = require('util')
const { clone } = require('./download')
const figlet = promisify(require('figlet'))

//获得命令运行时的路径
const getCwd = () => process.cwd() + '/'
const spawn = async (...args) => {
const { spawn } = require('child_process')
const options = args[args.length - 1]
if (process.platform === 'win32') {
options.shell = true
} else {
return
}
return new Promise(resolve => {
const proc = spawn(...args)
proc.stdout.pipe(process.stdout)
proc.stderr.pipe(process.stderr)
proc.on('close', () => {
resolve()
})
})
}
const log = content => console.log(chalk.green(content))

/**
* 🚀📦🌠
* @param {*} name 获取当前用户初始化项目的名称
*/

module.exports = async name => {
clear()
const data = await figlet('Private CLI')
// log(data)
const USER = 'user'; //填写你自己的用户名
const PASS = 'pass'; //填写你自己的密码
const REPO = '192.168.32.160/web-front/template'; //填写你自己的模板项目git地址
const remote = `http://${USER}:${PASS}@${REPO}`;
log(`开始创建项目:` + name)
await clone(remote)
const process = ora(`开始安装依赖`)
process.start()
await spawn('npm', ['install'], { cwd: `${getCwd()}${name}` })
process.succeed();
log(`
'✔'安装完成:
To get Start:
===========================
cd ${getCwd()}${name}
npm run serve
===========================
`)
inquirer
.prompt([
{
type: "input",
name: "projectPort",
message: "请输入项目运行端口",
// default: "",
}
])
.then((answers) => {
open(`http://localhost:${answers.projectPort}`)
spawn('npm', ['run', 'serve'], { cwd: `${getCwd()}${name}` })
})
}
Loading

0 comments on commit 8b37f63

Please sign in to comment.