1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-04-14 02:09:56 +08:00

chore: update

* feat: update sync ci

* feat: 新增vercel部署ci

* feat: update

* feat: update

* feat: update ci

* feat: update

* feat: update ci

* feat: add vercel script

* feat: 新增vercel部署ci

* feat: update

* feat: update

* feat: update ci

* feat: update

* feat: update ci

* feat: add vercel script

* feat: update

* feat: update

* feat: update json

* feat: update node version

* feat: add version

* ci: 优化版本流程

* feat: 优化脚本

* feat: 新增release发布脚本

* feat: update

* feat: 脚本优化更新

* release v0.0.1-alpha.0

* release v0.0.1-alpha.0

* feat: 修正脚本异常

* chrome: 删除无用脚本和注释,优化ci自动化

* feat: update

* style: 格式化脚本

* chore(release): publish v0.0.1-alpha.1

* ci: add release ci

* style: ci update

* feat: sync

* style: 修复ci提交信息格式

* style: update release

* chore(version): update ci  (#40)

* style: test

* style: 忽略node_modules

* style: 新增read权限测试

---------

Co-authored-by: chu fan <fairy_408@2925.com>

* chore: CI、CD配置文件优化 (#42)

chore: CI、CD配置文件优化

* chore: 新增vercel环境变量 (#43)

chore: 新增vercel环境变量

* style: 修改CI/CD配置,优化缓存 (#44)

style: 修改CI/CD配置,优化缓存

* fix: 修复CI/CD流水线异常

* chore(release): publish v0.0.1-alpha.1

* fix: 修复release CD异常

* ci: 流水线新增缓存机制,优化依赖安装脚本

* perf: 升级依赖版本,支持锁定node18.18

* chore(release): publish v0.0.1-alpha.2

* chore: 流水线运行平台改为macos-latest

* fix: 修复持续交付vercel异常

* chore(release): publish v0.0.1-alpha.3

* fix: 修复Github Release异常

---------

Co-authored-by: 喜欢芝士的妹妹 <fairy0115@2925.com>
Co-authored-by: chufan <fairy_408@2925.com>
This commit is contained in:
mmdapl
2023-09-28 16:46:08 +08:00
committed by GitHub
41 changed files with 5422 additions and 2462 deletions

164
.github/workflows/CD.yaml vendored Normal file
View File

@@ -0,0 +1,164 @@
## CD交付流水线
## - 部署到Github Pages
## - 部署到Vercel托管平台
## - 发布新的Github Release
## 参考资料https://v2.vuepress.vuejs.org/zh/guide/deployment.html#github-pages
name: CD
on:
push:
branches:
- master
- next
workflow_dispatch:
## vercel 环境变量
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
jobs:
install-init:
name: "依赖安装初始化"
runs-on: macos-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
## 部署到Github-Pages
deploy-github:
name: "部署到Github-Pages"
needs: install-init
runs-on: macos-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore Dependencies From cache
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
# 运行构建脚本
- name: Build VuePress Site
run: ls -a && ./scripts/bundle build_proxy
- name: Deploy To GitHub Page
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: pages/github
build_dir: docs/.vuepress/dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
## 部署到vercel平台
deploy-vercel:
name: "部署到Vercel平台"
needs: install-init
runs-on: macos-latest
if: github.repository == '142vip/408CSFamily'
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore Dependencies From Cache
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Pull Vercel Environment Information
run: vercel -v && vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
## 注意安装pnpm
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
## 版本发布
release:
name: "创建Github发布"
runs-on: macos-latest
needs: install-init
## 主库master、next且执行release更新时执行
if: github.repository == '142vip/408CSFamily' && startsWith(github.event.head_commit.message, 'chore(release):')
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
### 打成压缩包
- name: Create Zip Package
run: |
zip -r 408CSFamily.zip . \
-x "node_modules/*"
# 提取版本号
- name: Get New Version Number
id: extract_version
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
# 创建发布版本
- name: Create New Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.extract_version.outputs.version }}
release_name: v${{ steps.extract_version.outputs.version }}
body: |
Release ${{ steps.extract_version.outputs.version }}
### Features
### Bug Fixes
## 更新资源
- name: Upload Resource Assets
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./408CSFamily.zip
asset_name: 408CSFamily.zip
asset_content_type: application/zip

118
.github/workflows/CI.yml vendored Normal file
View File

@@ -0,0 +1,118 @@
## 代码CI快速集成流水线lint、fix、build
name: CI
## 触发条件
on:
pull_request:
branches:
- 'master'
- 'next'
- '!pages/**'
push:
branches:
- master
- next
# 手动触发部署
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
jobs:
install-init:
name: "依赖安装初始化"
runs-on: macos-latest
permissions:
actions: read
pull-requests: read
steps:
- name: checkout code
uses: actions/checkout@v3
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0
cache: 'pnpm'
- run: pnpm i --frozen-lockfile --registry https://registry.npmmirror.com
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
Base-Build:
name: "基础编译构建"
runs-on: macos-latest
needs: install-init
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore Dependencies From Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Code LintFix
run: ./scripts/lint --fix
- name: Build Site
run: ./scripts/bundle build
- name: Build Site With Proxy
run: ./scripts/bundle build_proxy
Build-Docker-Image:
name: "构建Docker镜像"
runs-on: macos-latest
needs: install-init
## 主库且tag更新时执行
if: github.repository == '142vip/408CSFamily' && startsWith(github.ref, 'refs/tags/v')
permissions:
actions: read
pull-requests: read
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
- name: Login Docker
run: |
docker version
echo "-----------Docker Login-----------"
docker login \
--username=${{ env.UserName }} \
--password=${{ secrets.DOCKER_PASSWORD }} \
${{env.REGISTRY}}
- name: Restore Dependencies From Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
## 构建支持domain
- name: Build To Dist
run: ./scripts/bundle build_proxy
- name: Push Docker Image
run: ./scripts/bundle image_faster

View File

@@ -1,40 +0,0 @@
# 构建Docker镜像
name: Code-CI
## 触发条件
on:
# 手动触发部署
workflow_dispatch:
pull_request:
branches:
- 'master'
- 'next'
- '!pages/**'
jobs:
Code-CI:
runs-on: ubuntu-latest
# if: github.repository == '142vip/408CSFamily'
permissions:
actions: read
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14.20.1
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Code Eslint Fix
run: pnpm lintfix
- name: Build Site
run: pnpm build

View File

@@ -1,55 +0,0 @@
# 构建Docker镜像
name: Docker-Image
## 触发条件
on:
# push:
# branches:
# - master
# - next
# Publish semver tags as releases.
# tags: [ 'v*.*.*' ]
# 手动触发部署
workflow_dispatch:
# pull_request:
# branches:
# - master
# - next
## 环境变量
env:
REGISTRY: registry.cn-hangzhou.aliyuncs.com
UserName: mmdapl
jobs:
Docker-Image:
name: "构建Docker镜像"
runs-on: ubuntu-latest
if: github.repository == '142vip/408CSFamily'
permissions:
actions: read
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login Docker
run: |
docker version
echo "-----------Docker Login-----------"
docker login --username=${{ env.UserName }} --password=${{ secrets.DOCKER_PASSWORD }} ${{env.REGISTRY}}
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14.20.1
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Build And Push Docker image
run: PROXY_DOMAIN=true pnpm image:faster

View File

@@ -1,81 +0,0 @@
# 部署到服务器
name: Deploy-ESC
on:
push: # 推送的时候触发
branches:
- master
workflow_dispatch:
env:
REGISTRY: registry.cn-hangzhou.aliyuncs.com
UserName: mmdapl
jobs:
Docker-Image:
name: "构建Docker镜像"
runs-on: ubuntu-latest
if: github.repository == '142vip/408CSFamily'
permissions:
actions: read
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login Docker
run: |
docker version
echo "-----------Docker Login-----------"
docker login --username=${{ env.UserName }} --password=${{ secrets.DOCKER_PASSWORD }} ${{env.REGISTRY}}
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14.20.1
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Build And Push Docker image
run: pnpm faster-image
Deploy-ESC:
needs: Docker-Image
name: "部署到ESC"
runs-on: ubuntu-latest
if: github.repository == '142vip/408CSFamily'
permissions:
actions: read
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get Current Version
id: version
uses: ashley-taylor/read-json-property-action@v1.0
with:
path: ./package.json
property: version
# 拉取镜像,更新服务
- name: Pull Image And Update ESC
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
port: ${{ secrets.SERVER_PORT }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
docker images
echo "-----------正在运行的服务--------"
docker ps
cd /service_env/ && git reset --hard && git pull origin main
bash ./scripts/book_doc.deploy.sh 408 ${{steps.version.outputs.value}}

View File

@@ -1,43 +0,0 @@
## 参考资料https://v2.vuepress.vuejs.org/zh/guide/deployment.html#github-pages
name: gh-deploy
on:
push:
branches:
- master
- next
workflow_dispatch:
jobs:
deploy-github:
name: "部署到Github"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14.20.1
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
# 运行构建脚本
- name: Build VuePress Site
run:
PROXY_DOMAIN=true pnpm build
- name: Deploy to GitHub Page
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: pages/github
build_dir: docs/.vuepress/dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@@ -72,3 +72,4 @@ templete
/docs/.vuepress/.temp/
/docs/.vuepress/.cache/
/.husky/
.vercel

4
.npmrc
View File

@@ -1,2 +1,4 @@
## 锁定版本
engine-strict = true
shamefully-hoist=true
registry=https://registry.npmmirror.com
registry=https://registry.npmmirror.com

19
.travis.yml Normal file
View File

@@ -0,0 +1,19 @@
# 参考链接: https://docs.travis-ci.com/user/languages/javascript-with-nodejs/
language: node_js
node_js:
- 16
# 环境变量
#env:
# - EMBER_VERSION=default
# - EMBER_VERSION=release
# - EMBER_VERSION=beta
# - EMBER_VERSION=canary
# 安装依赖前先安装pnpm
before_install:
- "npm install -g npm@7"
install:
- pnpm i
script:
- pnpm lintfix
- pnpm build

24
.versionrc.js Normal file
View File

@@ -0,0 +1,24 @@
// commit-and-tag-version 配置参考https://github.com/conventional-changelog/standard-version
module.exports={
"header": "# Release history\n\nAll notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.\n\n<!-- #region recent-beta -->\n",
"releaseCommitMessageFormat": "chore(release): publish v{{currentTag}}",
"types": [
{ "type": "feat", "section": "Features" },
{ "type": "feature", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "perf", "section": "Performance Improvements" },
{ "type": "revert", "section": "Reverts" },
{ "type": "docs", "section": "Documentation", "hidden": true },
{ "type": "style", "section": "Styles", "hidden": true },
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
{ "type": "refactor", "section": "Code Refactoring", "hidden": true },
{ "type": "test", "section": "Tests", "hidden": true },
{ "type": "build", "section": "Build System", "hidden": true },
{ "type": "ci", "section": "Continuous Integration", "hidden": true }
],
"skip": {
"bump": true,
"commit": true,
"tag": true
}
}

50
CHANGELOG.md Normal file
View File

@@ -0,0 +1,50 @@
# Release history
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
<!-- #region recent-beta -->
## [0.0.1-alpha.3](https://github.com/mmdapl/408CSFamily/compare/v0.0.1-alpha.2...v0.0.1-alpha.3) (2023-09-28)
### Bug Fixes
* 修复持续交付vercel异常 ([57473e5](https://github.com/mmdapl/408CSFamily/commit/57473e5e491a0133a2b5494c3b9e7e65b990dd23))
## [0.0.1-alpha.2](https://github.com/mmdapl/408CSFamily/compare/v0.0.1-alpha.1...v0.0.1-alpha.2) (2023-09-28)
### Bug Fixes
* 修复release CD异常 ([7ce3714](https://github.com/mmdapl/408CSFamily/commit/7ce3714f9bcfbcad40ef9df462a343b37742273a))
### Performance Improvements
* 升级依赖版本,支持锁定node18.18 ([a1dfbaf](https://github.com/mmdapl/408CSFamily/commit/a1dfbaf1d3c22ff5844d5c976e24b35d2578a62e))
## [0.0.1-alpha.1](https://github.com/mmdapl/408CSFamily/compare/v0.0.1-alpha.0...v0.0.1-alpha.1) (2023-09-08)
### Features
* add vercel script ([a354acc](https://github.com/mmdapl/408CSFamily/commit/a354acced9f9485e0aa2634ac227ab97657de14d))
* add version ([09d6f2c](https://github.com/mmdapl/408CSFamily/commit/09d6f2ce315dc02b02f6ed6a468b614bb5f22810))
* docs update ([e4299a8](https://github.com/mmdapl/408CSFamily/commit/e4299a8bddfe78a583b082822011442478dfb6ff))
* sync ([cbd014c](https://github.com/mmdapl/408CSFamily/commit/cbd014c163e93eed947509739c7a1b356b37f872))
* update ([8673a64](https://github.com/mmdapl/408CSFamily/commit/8673a64409d646195122835828ffe14be265c97a))
* update ci ([372dc79](https://github.com/mmdapl/408CSFamily/commit/372dc792c7861a879ff686747fb8c76bd70f4761))
* update node version ([507ff83](https://github.com/mmdapl/408CSFamily/commit/507ff838f71ab2360e49ef422f6fe969a36882a8))
* update sync ci ([c357991](https://github.com/mmdapl/408CSFamily/commit/c357991e49a1513f67b92167426c57d68c711c14))
* 优化脚本 ([e3d5fba](https://github.com/mmdapl/408CSFamily/commit/e3d5fbad7814d0cb652484e0eb5acbdcbe2d940b))
* 修正脚本异常 ([c003e11](https://github.com/mmdapl/408CSFamily/commit/c003e11b8044bfdf1ff7151f04f9c03fea777095))
* 文档更新 ([0d947c7](https://github.com/mmdapl/408CSFamily/commit/0d947c74c20dbdf170cc49f0281ff4b196b6b206))
* 新增release发布脚本 ([d94f30a](https://github.com/mmdapl/408CSFamily/commit/d94f30aa20063cd1c8bd9b08f63acf484fe2e698))
* 新增scripts脚本说明 ([32d42f7](https://github.com/mmdapl/408CSFamily/commit/32d42f77bb5103760794994c0481d7d9b632d1d4))
* 新增vercel部署ci ([bc59fea](https://github.com/mmdapl/408CSFamily/commit/bc59fea739b0e20497ac86daf06a2bdbb11f8cf5))
* 脚本优化更新 ([c072b3d](https://github.com/mmdapl/408CSFamily/commit/c072b3d3a4ae70d542a59b52babb1d67b4102230))
### Bug Fixes
* 修复CI/CD流水线异常 ([edf222f](https://github.com/mmdapl/408CSFamily/commit/edf222f297dbe57782f46fd6d38dd7c92d59e3fe))

View File

@@ -7,7 +7,7 @@
#
# 注意vite构建需要支持node14以上安装node16较为稳妥
FROM registry.cn-hangzhou.aliyuncs.com/142vip/node:16.12.0-alpine AS build_base
FROM registry.cn-hangzhou.aliyuncs.com/142vip/node:18.18.0-alpine AS build_base
ARG CONTAINER_BUILD
WORKDIR /apps
COPY . .
@@ -16,10 +16,9 @@ RUN echo $CONTAINER_BUILD
## 基于容器自动构建
RUN if [ "$CONTAINER_BUILD" = "true" ]; then \
npm i pnpm@7 -g && pnpm i -D && pnpm build; \
npm i pnpm@7 -g && pnpm i -D && ./scripts/bundle build; \
fi;
FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:1.23.0-alpine
ARG APP_VERSION

View File

@@ -23,7 +23,7 @@ void BinaryInsertSort(ElemType Arr[],int n){
}
// 跳出循环需要lowIndex>heightIndex
// 说明待插入位置的角标在heightIndex之后为 heightIndex+1,此时需要将heightIndexi之间的所有元素后移
// 说明待插入位置的角标在heightIndex之后为 heightIndex+1,此时需要将heightIndexi之间的所有元素后移
for(j=i-1;j>highIndex;--j){
Arr[j+1]=Arr[j]

View File

@@ -7,9 +7,11 @@ function binaryInsertSort(arr, len) {
? len
: arr.length
// 遍历
for (let i = 1; i < len; i++) {
const temp = arr[i]
let lowIndex = 0; let highIndex = i - 1
let lowIndex = 0
let highIndex = i - 1
while (lowIndex <= highIndex) {
// 注意:取整,javascript这里取整会出现空指针
@@ -29,15 +31,14 @@ function binaryInsertSort(arr, len) {
}
arr[highIndex + 1] = temp
}
// 返回经过折半插入排序处理的有序数组
return arr
}
// 测试用例
const dealArr = [5, 2, 7, 3, 18, 8, 12, 1]
console.log('插入排序前:', dealArr)
const sortResult = binaryInsertSort(dealArr, 7)
console.log('插入排序后:', sortResult)

View File

@@ -25,7 +25,6 @@ LinkList CreateListWithStartNode(LinkList &L){
return L;
}
// 单链表尾插法
LinkList CreateListWithEndNode(LinkList &L){

View File

@@ -10,12 +10,12 @@ typedef struct StackNode
{
int data;//结点数据域
struct StackNode* next;//结点指针域
}StackNode,* Linktop;
}StackNode,* LinkTop;
//链栈的数据结构
typedef struct LinkStack
{
Linktop top; //栈顶结点,定义了一个指向上个结构体的指针
LinkTop top; //栈顶结点,定义了一个指向上个结构体的指针
int count;//元素个数
}LinkStack;

View File

@@ -9,9 +9,6 @@ typedef struct {
int front,rear;
} SqQueue;
// 入队算法
// 尾插法Q.data[Q.rear]=x;Q.rear=(Q.rear+1)%Maxsize;Q.tag=1
// 队空条件Q.front== Q.rear且Q.tag==0
@@ -25,8 +22,8 @@ int EnLoopQueue(SqQueue &Q, ElemType x){
return 1;
}
// 出队算法
// 头结点删除x=Q.data[Q.front];Q.front=(Q.front +1)%Maxsize;Q.tag=0
// 队满条件Q.front == Q.rear且Q.tag=1

View File

@@ -1,4 +1,3 @@
/**
* 基于分治法思想,将数组进行快速排序
* @param {Array} arr 待排序的数组
@@ -7,7 +6,7 @@
*/
function QuickSort(arr, low, high) {
// low=high 说明只有一个元素,理解为有序,不做处理
// low>high 说明左右指针已经重合,数组已经遍历完,需要跳出
// low>high 说明左右指针已经重合,数组已经遍历完,需要跳出
if (low < high) {
const pivotIndex = Partition(arr, low, high)
// 处理左侧
@@ -50,7 +49,6 @@ function Partition(arr, low, high) {
const initArr = [2, 18, 6, 25, 19, 4, 8, 3, 7]
console.log(`快速排序处理前:${initArr}`)
const quickSortResult = QuickSort(initArr, 0, 8)
console.log(`快速排序处理后:${quickSortResult}`)

View File

@@ -1,7 +1,5 @@
// 顺序表的基础操作
// 基础结构体
define MaxSize 50;
typedef struct{

View File

@@ -1,13 +1,3 @@
/*
* @Description: 顺序栈的相关操作
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2020-03-07 11:15:04
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-03-13 12:30:18
*/
// 定义栈中元素的最大个数
# define MaxSize 50
@@ -43,7 +33,7 @@ bool Push(SqStack &S,ElemType x){
}else{
// 可进栈,栈顶指针+1再元素入栈
S.data[++S.top]=x;
// 入栈成功
return true;
}
@@ -58,7 +48,7 @@ bool Pop(SqStack &S,ElemType &x){
}else{
// 栈非空,先元素出栈,再进行指针-1
x=S.data[S.top--];
// 出栈成功返回true
return true;
}
@@ -66,15 +56,15 @@ bool Pop(SqStack &S,ElemType &x){
// 读(获取)栈顶元素
bool GetTop(SqStack S,ElemType &x){
if(S.top==-1){
// 栈空,无栈顶元素,返回false
return false;
}else{
// 通过栈顶指针获取栈顶元素赋值给变量x
x=S.data[S.top];
// 读取栈顶元素成功返回true
return true;
}

View File

@@ -6,26 +6,6 @@ export const navbar = [
text: '首页',
link: '/'
},
// {
// text: "算法恶补",
// children: [{
// text: '习题狂刷',
// link: '/manuscripts/algorithm/topic_practice'
// }, {
// text: '刷题笔记',
// link: '/manuscripts/algorithm/algorithm_note'
// }, {
// text: '在线刷题',
// children: [{
// text: '杭电OJ', link: 'http://acm.hdu.edu.cn/'
// },
// {
// text: '牛客网', link: 'https://www.nowcoder.com/'
// }, {
// text: 'LeetCode', link: 'https://leetcode-cn.com/'
// }]
// }]
// },
{
text: "数据结构",
link: "/manuscripts/ds"

View File

@@ -76,6 +76,37 @@ export default {
// 代码块
mdEnhance: {
codetabs: true,
tasklist: true, // 支持任务列表
// 启用 figure
figure: true,
// 启用图片懒加载
imgLazyload: true,
// 启用图片标记
imgMark: true,
// 启用图片大小
imgSize: true,
playground: {
presets: ["ts", "vue"],
},
presentation: ["highlight", "math", "search", "notes", "zoom"],
stylize: [
{
matcher: "Recommended",
replacer: ({tag}) => {
if (tag === "em")
return {
tag: "Badge",
attrs: {type: "tip"},
content: "Recommended",
};
},
},
],
sub: true,
sup: true,
tabs: true,
vPre: true,
vuePlayground: true,
},
copyCode: {
showInMobile: true

View File

@@ -1,42 +1,30 @@
<!--
* @Description: 特殊矩阵的压缩存储
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2021-03-20 16:18:51
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-03-20 17:04:44
-->
## 特殊矩阵的压缩存储
> 这部分知识我个人觉得以了解为主,复习、学习的时候还是要以前面的部分为主!
矩阵在`计算机图形学``工程计算`中占有举足轻重的地位。
### 数组的定义
`数组` 由n(n≥1)个相同类型的数据元素构成的有限序列。
每个数据元素称为一个数组元素同时每个元素受n个线性关系的约束**每个元素在n个线性关系中的序号称为元素的`下标`**称为该数组为n的数组。
每个数据元素称为一个数组元素同时每个元素受n个线性关系的约束**每个元素在n个线性关系中的序号称为元素的`下标`**
称为该数组为n的数组。
数组和线性表的关系:
- 数组是线性表的推广。
- 数组一旦被定义,维数和维界就不再改变。
- 除了结构的初始化和销毁外,数组只会有存取元素和修改元素的操作。
一维数组可以看做是一个线性表
二维数组可以看做元素是线性表的线性表
....
### 矩阵的压缩存储
`压缩存储`:多个值相同的元素只分配一个存储空间,对零元素不分配存储空间---->节省存储空间。
`特殊矩阵`:具有很多相同矩阵元素或零元素,并且这些相同矩阵元素或零元素的分布有一定规律性的矩阵。
@@ -50,18 +38,14 @@
`稀疏矩阵`矩阵元素个数s相对于矩阵中非零元素的个数t来说非常多、差距非常大`s>>t的矩阵`可以叫`稀疏矩阵`
注意:
- 常规方法来存储稀疏矩阵,会想当浪费存储空间,所以稀疏矩阵只需要存储非零元素
- 通常非零元素的分布是没有规律的,除了存储非零元素外,还需要存储元素所在位置的行和列
- 寻相互存储三元组 `<行标,列表,值>`
![](./稀疏矩阵的存储变换.png)
三元组的结点存储了行标(row)、列表(col)、值(value)三种信息,是主要用来存储稀疏矩阵的一种数据结构。
**注意:矩阵压缩存储的目的就是为了节省空间,已经存过的就不存或者少存(经典想法)**

View File

@@ -1,60 +1,53 @@
{
"name": "408CSFamily",
"description": "专业代号408计算机基础知识点合集",
"version": "0.0.1-alpha.1",
"version": "0.0.1-alpha.3",
"packageManager": "pnpm@7.2.1",
"engines": {
"node": "^18.x",
"pnpm": ">=7.2.1"
},
"author": {
"name": "Chu Fan",
"email": "fairy_408@2925.com",
"url": "https://github.com/142vip"
},
"scripts": {
"prepare": "husky install && npx husky add .husky/pre-commit \"npm run lintfix\" && chmod +x .husky/pre-commit",
"prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"./scripts/lint --fix\" && chmod +x .husky/pre-commit",
"dev": "vuepress dev docs",
"build": "vuepress build docs",
"build:proxy": "PROXY_DOMAIN=true vuepress build docs",
"image": "bash scripts/build_image.sh $npm_package_version",
"image:faster": "bash scripts/build_image.sh $npm_package_version faster",
"deploy:ali": "bash scripts/deploy.sh ali $npm_package_version",
"deploy:github": "bash scripts/page_deploy.sh",
"version:alpha": "npm version prerelease --preid alpha",
"version:patch": "npm version patch",
"lint": "eslint --ext .js,.vue,.ts --ignore-path .gitignore .",
"lintfix": "eslint --fix --ext .js,.ts,.vue --ignore-path .gitignore .",
"clean": "find . -name \"node_modules\" -type d -exec rm -rf '{}' +"
"build": "./scripts/bundle build",
"build:proxy": "./scripts/bundle build_proxy",
"deploy:vercel": "vercel --prod",
"clean": "find . -name \"node_modules\" -type d -exec rm -rf '{}' + "
},
"scripts-info": {
"prepare": "安装依赖预执行脚本",
"dev": "本地启动项目",
"build": "构建、打包",
"build:proxy": "构建、打包,支持项目名代理,使用第三方托管平台",
"image": "容器打包、构建镜像",
"image:faster": "本地build后快速构建镜像",
"deploy:ali": "部署到阿里云服务器",
"deploy:github": "部署到github平台集成ci",
"version:alpha": "alpha测试版号更新基于next分之操作",
"version:patch": "稳定版号更新基于master分支操作",
"lint": "eslint校验代码指出异常",
"lintfix": "格式化代码,自动化处理异常",
"clean": "快速删除本地依赖"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"@vuepress/client": "2.0.0-beta.61",
"@vuepress/utils": "2.0.0-beta.61",
"eslint": "^8.35.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@vuepress/client": "^2.0.0-beta.61",
"@vuepress/utils": "^2.0.0-beta.61",
"bumpp": "^9.2.0",
"commit-and-tag-version": "11.2.3",
"enquirer": "^2.4.1",
"eslint": "^8.49.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.9.0",
"eslint-plugin-vue": "^9.17.0",
"husky": "^8.0.3",
"shelljs": "^0.8.5",
"typescript": "^3.9.10",
"vue": "^3.2.47",
"vuepress": "2.0.0-beta.61",
"vuepress-plugin-search-pro": "2.0.0-beta.185",
"vuepress-theme-hope": "2.0.0-beta.185"
"vercel": "^32.2.0",
"vue": "^3.3.4",
"vuepress": "^2.0.0-beta.61",
"vuepress-plugin-search-pro": "^2.0.0-beta.185",
"vuepress-theme-hope": "^2.0.0-beta.185",
"webpack": "^5.0.0"
},
"license": "MIT"
}

6183
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

58
scripts/.exec Executable file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env node
/**
* 脚本执行器执行shell命令
*/
const {join} = require('path')
const cwd = join(__dirname, '..')
process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}`
const {exec,exit} = require('shelljs');
/**
* 监听进程
* - 退出进程
*/
process.on('exit', () => {
exit()
})
/**
* 执行shell指令
* @param commands
*/
exports.execShell = async commands => {
let runCommands=[]
if(typeof commands ==='string'){
runCommands.push(commands)
}
// 批量执行
if(Array.isArray(commands)){
runCommands=commands
}
for (let index=0;index<runCommands.length;index++) {
const command=runCommands[index]
const count=index+1
console.log(`>>>command(${count}):\n${command} \n<<<command(${count})--start === \n`)
// await syncExec(command)
const execResult=await exec(command)
console.log(`\n<<<command(${count})--ending === `)
// 指令异常,不执行后续指令
if(execResult.code!==0){
break;
}
}
}
/**
* 脚本基础设置
*/
exports.BaseSetting={
successLogger:"\033[36m",
errorLogger:"\033[1;31m",
warnLogger:"\033[1;33m",
// 定义时间
currentTime:'$(date "+%Y-%m-%d %H:%M:%S")'
}

View File

@@ -1,4 +0,0 @@
#!/bin/bash
## 登录阿里云hub
docker login --username=mmdapl registry.cn-hangzhou.aliyuncs.com

View File

@@ -1,85 +0,0 @@
#!/bin/bash
## 功能本地前后端项目构建、打包镜像上传docker仓库
## 参考https://blog.csdn.net/Dontla/article/details/125210694
## 使用示例bash xxx.sh 版本号 faster[可选]
## - bash build_image.sh 0.0.1 faster
## 作者:储凡
##
## 日志颜色定义
readonly successLogger="\033[36m"
readonly errorLogger="\033[1;31m"
## 定义时间
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
## 项目名称
readonly projectName="408CSFamily"
## 仓库地址
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
## 版本号
version=${1}
## 是否先本地构建执行npm run build操作
isFaster=${2}
## 镜像名称
imageTagName=${repoAddress}:${projectName}-${version}
## 预检查
prepare_check(){
if test -z "${version}";then
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空。参考版本: 0.0.x"
exit 0
fi
}
## 运行命令
run(){
echo -e "${successLogger}---------------- shell ${projectName} start ---------------- "
if [ "${isFaster}" == "faster" ];then
## 本地构建、快速制作镜像
pnpm build && docker build \
--build-arg APP_VERSION="${version}" \
--build-arg CONTAINER_BUILD=false \
-t "${imageTagName}" .
else
## ci流程容器构建打包
docker build \
--build-arg APP_VERSION="${version}" \
--build-arg CONTAINER_BUILD=true \
-t "${imageTagName}" .
echo 12312
echo docker build \
--build-arg APP_VERSION="${version}" \
--build-arg CONTAINER_BUILD=true \
-t "${imageTagName}" .
fi
echo -e "${successLogger}---------------- shell ${projectName} end ---------------- "
push_docker_image
}
## 推送镜像
push_docker_image(){
if [[ "$(docker images -q "${imageTagName}" 2> /dev/null)" != "" ]];
then
## 推送
docker push "${imageTagName}"
echo -e "${successLogger}---------------- 上传镜像成功,删除本地镜像 ---------------- "
docker rmi "${imageTagName}"
else
echo -e "${errorLogger}${currentTime}[镜像] ${imageTagName}不存在"
fi
exit 0
}
prepare_check
run

138
scripts/bundle Executable file
View File

@@ -0,0 +1,138 @@
#!/usr/bin/env node
/**
*
* 将应用程序打包成可部署的包、文件、镜像
* 例如:
* - ./scripts/bundle build 基础部署打包
* - ./scripts/bundle build_proxy 用于三方平台部署打包
* - ./scripts/bundle image 构建容器镜像
* - ./scripts/bundle image_faster 本地build快速构建容器镜像
* - ./scripts/bundle xxx 其他参数默认执行build命令
* - ./scripts/bundle 交互式选择执行的命令
*/
const { execShell } = require('./.exec')
const { Select } = require('enquirer')
const packageVersion = require('../package.json').version
const projectName = '408CSFamily'
// 仓库地址
const repoAddress = 'registry.cn-hangzhou.aliyuncs.com/142vip/doc_book'
// 镜像地址
const imageName = `${repoAddress}:${projectName}-${packageVersion}`
/**
* 获取构建镜像的脚本
* @param containerBuild
* @param preBuild
* @param needProxy
* @returns {string[]}
*/
function getBuildImageScript({ containerBuild, preBuild, needProxy = false }) {
// 基础构建脚本
let baseBuildScript = ''
if (preBuild) {
baseBuildScript = needProxy ? './scripts/bundle build_proxy' : './scripts/bundle build'
}
return [
// 构建镜像
`
${baseBuildScript}
docker build \
--build-arg APP_VERSION=${packageVersion} \
--build-arg CONTAINER_BUILD=${containerBuild} \
-t ${imageName} .
`,
// 推送镜像
`
if [[ "$(docker images -q ${imageName} 2> /dev/null)" != "" ]];then
## 推送
docker push ${imageName}
echo "---------------- 上传镜像成功,删除本地镜像 ---------------- "
docker rmi ${imageName}
exit 0;
else
echo "镜像: ${imageName} , 不存在"
exit 1;
fi
`
]
}
/**
* 支持的脚本命令
*/
const SupportScripts = {
build: 'vuepress build docs',
build_proxy: 'PROXY_DOMAIN=true vuepress build docs',
image: getBuildImageScript({
containerBuild: true,
needProxy: false
}),
image_proxy: getBuildImageScript({
containerBuild: true,
needProxy: true
}),
// 直接从本地拿dist文件生成镜像
image_faster: getBuildImageScript({
containerBuild: false,
needProxy: false
})
}
async function getScriptCommand() {
const scriptName = process.argv[2]
let scriptCommand = SupportScripts.build
if (scriptName == null) {
const prompt = new Select({
header: '======================== 408CSFamily Cli For Building ========================',
footer: '======================== 408CSFamily Cli For Building ========================',
name: 'color',
message: 'What script will you want to run ',
choices: [
{
message: 'build',
name: SupportScripts.build,
value: '#00ffff'
},
{
message: 'build for fixing proxy',
name: SupportScripts.build_proxy,
value: '#000000'
},
{
message: 'build to docker image',
name: SupportScripts.image,
value: '#0000ff'
},
{
message: 'build to docker image with proxy',
name: SupportScripts.image_proxy,
value: '#0000ff'
},
{
message: 'build to docker image faster',
name: SupportScripts.image_faster,
value: '#0000ff'
}
]
})
scriptCommand = await prompt.run()
} else {
// 命中支持的脚本
if (Object.keys(SupportScripts).includes(scriptName)) { scriptCommand = SupportScripts[scriptName] }
}
return scriptCommand
}
;(async() => {
const scriptCommand = await getScriptCommand()
await execShell(scriptCommand)
})()

4
scripts/ci Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
## 下载依赖
pnpm i --frozen-lockfile --registry https://registry.npmmirror.com

89
scripts/deploy Executable file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/env node
/**
*
* 例如:
* - ./scripts/deploy ali
* - ./scripts/deploy github
*/
const { execShell } = require('./.exec')
const packageVersion = require('../package.json').version
const dockerDeployInfo = {
repoAddress: 'registry.cn-hangzhou.aliyuncs.com/142vip/doc_book',
containerName: '408CSFamily',
networkName: 'service_env_net'
}
const imageName = `${dockerDeployInfo.repoAddress}:${dockerDeployInfo.containerName}-${packageVersion}`
// 支持的命令
const SupportScripts = {
Github: `
set -e
./scripts/build proxy && cd docs/.vuepress/dist
git init && git add -A
## 配置信息
git config user.name 'chu fan'
git config user.email 'fairy_408@2925.com'
git config --list
git commit -m "release v${packageVersion}"
## 部署到github pages
git push -f https://github.com/mmdapl/408CSFamily.git master:pages/github
cd -
`,
Ali: [
// 容器存在即删除
`
if docker inspect --format='{{.State.Running}}' ${dockerDeployInfo.containerName} >/dev/null 2>&1;then
docker rm -f ${dockerDeployInfo.containerName}
exit 0;
else
echo "容器:${dockerDeployInfo.containerName},不存在"
exit 1;
fi
`,
// 镜像存在即删除
`
if [[ "$(docker images -q ${imageName} 2> /dev/null)" != "" ]];then
docker rmi ${imageName}
exit 0;
else
echo -e "镜像:${imageName},不存在"
exit 1;
fi
`,
// 运行容器
`
docker run -d --name ${dockerDeployInfo.containerName} \
-p 7000:80 \
--network=${dockerDeployInfo.networkName} \
--restart=unless-stopped \
--ip=172.30.0.100 \
${imageName}
`
]
}
const deployName = process.argv[2]
function getDeployCommand() {
let deployCommand = SupportScripts.Ali
// 部署到阿里云服务器
if (deployName === 'ali') {
deployCommand = SupportScripts.Ali
}
// 部署到Github
if (deployName === 'github') {
deployCommand = SupportScripts.Github
}
return deployCommand
}
// 执行
;(async() => {
const deployCommand = getDeployCommand()
// console.log(deployCommand)
await execShell(deployCommand)
})()

View File

@@ -1,144 +0,0 @@
#!/bin/bash
## 功能:清除容器,删除旧镜像,创建新的容器
## 参考https://blog.csdn.net/Dontla/article/details/125210694
## 作者:储凡
## 使用示例bash xxx.sh 容器名称 镜像地址
##
## 日志颜色定义
readonly successLogger="\033[36m"
readonly errorLogger="\033[1;31m"
readonly warnLogger="\033[1;33m"
## 定义时间
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
readonly containerName="408CSFamily"
readonly networkName="service_env_net"
## 定义参数
operationName=${1}
version=${2}
## 参数检查
prepare_check(){
if test -z "${containerName}"
then
echo -e "${errorLogger}${currentTime}:参数错误 部署平台不能为空."
exit 0
fi
}
## 判断容器存在即删除
## - 一个参数,容器名称
delete_container(){
docker inspect "${1}" -f '{{.Name}}' > /dev/null
if [ $? -eq 0 ] ;then
echo -e "${warnLogger}${currentTime}容器:${1} 存在,现进行删除"
docker rm -f "${1}"
fi
}
## 判断镜像存在,即删除
## - 一个参数,镜像地址
delete_image(){
## 判断版本号
if test -z "${version}";then
echo -e "${errorLogger}${currentTime}:参数错误 镜像版本号不能为空."
exit 0
fi
if [[ "$(docker images -q "${1}" 2> /dev/null)" != "" ]];
then
echo -e "${warnLogger}${currentTime}镜像:${1}存在,现进行删除"
docker rmi "${1}"
fi
}
## 环境初始成功
run(){
if [ "${operationName}" == "gitee" ];then
## 查看所有
deploy_to_gitee
exit 0;
elif [ "${operationName}" == "github" ]; then
deploy_to_github
exit 0;
elif [ "${operationName}" == "ali" ]; then
## 删除容器
delete_container "${containerName}"
## 删除镜像
delete_image "${repoAddress}:${containerName}-${version}"
## 部署
deploy_to_ali
exit 0;
else
echo -e "${errorLogger}${currentTime}当前操作不支持,目前只支持:ali/gitee/github"
exit 0
fi
}
## 部署到阿里服务器
deploy_to_ali(){
echo -e "${successLogger}---------------- deploy ${containerName} ali start ---------------- "
docker run -d --name "${containerName}" \
-p 7000:80 \
--network="${networkName}" \
--restart=unless-stopped \
--ip=172.30.0.100 \
"${repoAddress}:${containerName}-${version}"
echo -e "${successLogger}---------------- deploy ${containerName} ali end ------------------ "
docker ps
}
## 部署到github静态资源托管
deploy_to_github(){
echo -e "${successLogger}---------------- deploy ${containerName} github start ---------------- "
# 当命令以非零状态退出时则退出shell
set -e
# 进入上级目录,并编译
npm run build && cd docs/.vuepress/dist
git init && git add --all
## 如果没有输入commit信息则采用默认
if [ "${commitInfo}" -eq "" ]; then
commitInfo="408CSFamily Init"
fi
git commit -m "refactor:${commitInfo}"
## 配置个人信息
git config user.name "晚上吃芝士+葡萄的妹妹"
git config user.email "fairy0115@2925.com"
git config --list
# if you are deploying to https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f https://github.com/mmdapl/408CSFamily.git master:pages/github
cd -
echo -e "${successLogger}---------------- deploy ${containerName} github end ------------------ "
}
## 部署到gitee静态资源托管
deploy_to_gitee(){
exit 0
}
prepare_check
run

10
scripts/dev Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env node
/**
*
* 本地启动
* 例如:
* - ./scripts/dev
*/
const { execShell } = require('./.exec');
(async() => await execShell('vuepress dev docs'))()

178
scripts/docker Executable file
View File

@@ -0,0 +1,178 @@
#!/usr/bin/env node
/**
* docker cli工具
* 例如:
* - ./scripts/docker container xxx 容器相关
* - ./scripts/network image xxx 镜像相关
* - ./scripts/docker network xxx 网络相关
*/
const { execShell } = require('./.exec')
const scriptName = process.argv[2]
/**
* 网络基础信息
* - 网络名称
* - 子网掩码
* - 网关地址
*/
const dockerNetworkInfo = {
defaultName: 'service_env_net',
subnet: '172.30.0.0/24',
gateway: '172.30.0.1'
}
/**
* docker containers 容器相关指令
*/
const SupportScriptsInContainer = {
run: '',
rm: '',
ps: 'docker ps'
}
/**
* docker images 相关脚本指令
*/
const SupportScriptsInImage = {
rm: 'docker rmi **',
ps: 'docker images'
}
/**
* docker network 相关脚本指令
*/
const SupportScriptsInNetWork = {
ls: 'docker network ls',
create: [
// 创建网关
`
docker network create \
--subnet=${dockerNetworkInfo.subnet} \
--gateway=${dockerNetworkInfo.gateway} \
${dockerNetworkInfo.defaultName}
`,
// 查看创建后基本信息
`
docker network inspect ${dockerNetworkInfo.defaultName}
`
],
rm: [
// 参数校验
`
if test -z "${dockerNetworkInfo.defaultName}";then
echo "参数错误 网络名称不能为空。脚本执行eg bash xxx.sh rm 网络名称"
exit 1;
fi
`,
// 判断网络是否存在
`
docker network ls | grep -w "${dockerNetworkInfo.defaultName}"
if [ $? -eq 1 ] ;then
echo "容器网络:${dockerNetworkInfo.defaultName} 不存在,删除无效"
exit 1;
fi
`,
// 删除网络
`
docker network rm "${dockerNetworkInfo.defaultName}"
`
],
inspect:
`
docker network inspect ${dockerNetworkInfo.defaultName}
`
}
function getContainerCommand() {
const name = process.argv[3]
if (name in SupportScriptsInContainer) {
return SupportScriptsInContainer[name]
}
// 默认查看所有容器
return SupportScriptsInContainer.ps
}
function getImageCommand() {
const name = process.argv[3]
if (name in SupportScriptsInImage) {
return SupportScriptsInImage[name]
}
return SupportScriptsInImage.ps
}
function getNetworkCommand() {
const name = process.argv[3]
if (name in SupportScriptsInNetWork) {
return SupportScriptsInNetWork[scriptName]
}
return SupportScriptsInNetWork.ls
}
// 支持的命令
const SupportScripts = {
ls: 'docker network ls',
create: [
// 创建网关
`
docker network create \
--subnet=${dockerNetworkInfo.subnet} \
--gateway=${dockerNetworkInfo.gateway} \
${dockerNetworkInfo.defaultName}
`,
// 查看创建后基本信息
`
docker network inspect ${dockerNetworkInfo.defaultName}
`
],
rm: [
// 参数校验
`
if test -z "${dockerNetworkInfo.defaultName}";then
echo "参数错误 网络名称不能为空。脚本执行eg bash xxx.sh rm 网络名称"
exit 1;
fi
`,
// 判断网络是否存在
`
docker network ls | grep -w "${dockerNetworkInfo.defaultName}"
if [ $? -eq 1 ] ;then
echo "容器网络:${dockerNetworkInfo.defaultName} 不存在,删除无效"
exit 1;
fi
`,
// 删除网络
`
docker network rm "${dockerNetworkInfo.defaultName}"
`
],
inspect:
`
docker network inspect ${dockerNetworkInfo.defaultName}
`
}
function getCommand() {
const scriptName = process.argv[3]
switch (scriptName) {
case 'network':
return getNetworkCommand()
case 'container':
return getContainerCommand()
case 'image':
return getImageCommand()
}
}
// 执行
;(async() => {
const command = getCommand(scriptName)
await execShell(command)
})()

View File

@@ -1,109 +0,0 @@
#!/bin/bash
## 功能设置docker自定义network并指定网关、IP范围
## 参考https://blog.csdn.net/Dontla/article/details/125210694
## 作者:储凡
## 使用示例bash xxx.sh 容器名称 镜像地址
##
## 日志颜色定义
readonly successLogger="\033[36m"
readonly errorLogger="\033[1;31m"
readonly warnLogger="\033[1;33m"
## 定义时间
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
operationName=${1}
networkName=${2}
## 网络名称
readonly defaultNetworkName="service_env_net"
## 子网范围 [/24 子网掩码]
readonly subnet="172.30.0.0/24"
## 网关
readonly gateway="172.30.0.1"
prepare_check(){
if test -z "$operationName"
then
echo -e "${errorLogger}${currentTime}:参数错误 操作类型不能为空。脚本执行eg bash xxx.sh [ls/init/rm]"
exit 0
fi
}
run(){
if [ "$operationName" == "ls" ];then
## 查看所有
echo -e "${successLogger}---------------- shell ls start ---------------- "
docker network ls
echo -e "${successLogger}---------------- shell ls end ------------------ "
exit 0;
elif [ "$operationName" == "init" ]; then
echo -e "${successLogger}---------------- shell init start ---------------- "
## 初始化
init_network
echo -e "${successLogger}---------------- shell init start ---------------- "
exit 0;
elif [ "$operationName" == "rm" ]; then
## 移除
echo -e "${successLogger}---------------- shell rm start ---------------- "
remove_network
echo -e "${successLogger}---------------- shell rm start ---------------- "
exit 0;
else
echo -e "${errorLogger}当前操作不支持,目前只支持:ls/init/rm"
exit 0
fi
}
## 创建网络
init_network(){
## 查询network -w【全匹配】
docker network ls | grep -w "${defaultNetworkName}"
if [ $? -eq 0 ] ;then
echo -e "${warnLogger}---------------- 容器:${defaultNetworkName} 已存在,无需创建 ---------------- "
docker network ls
exit ;
else
echo -e "${successLogger}---------------- 网络${defaultNetworkName},现进行初始化 ---------------- "
docker network ls
docker network create \
--subnet="${subnet}" \
--gateway="${gateway}" \
"${defaultNetworkName}"
echo -e "${successLogger}---------------- 创建后 ---------------------"
docker network ls
echo -e "${successLogger}---------------- 网络信息 ---------------------"
docker netwrok inspect "${defaultNetworkName}"
fi
}
## 删除网络
remove_network(){
if test -z "$networkName";then
echo -e "${errorLogger}${currentTime}:参数错误 网络名称不能为空。脚本执行eg bash xxx.sh rm 网络名称"
exit 0
fi
## 判断是否存在 -w【全匹配】
docker network ls | grep -w "${networkName}"
if [ $? -eq 1 ] ;then
echo -e "${errorLogger}${currentTime}:容器网络:${networkName} 不存在,删除无效 "
exit 0;
fi
echo -e "${successLogger}----------------删除前---------------------"
docker network ls
docker network rm "${networkName}"
echo -e "${successLogger}----------------删除后---------------------"
docker network ls
}
prepare_check
run

16
scripts/lint Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env node
/**
*
* 格式化代码
* 例如:
* - ./scripts/lint
* - ./scripts/lint --fix
*/
const { execShell } = require('./.exec')
const scriptName = process.argv[2]
const fixed = scriptName != null ? '--fix' : '';
// 可以在--fix后指定目录
(async() => await execShell(`eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .`))()

View File

@@ -1,27 +0,0 @@
#!/usr/bin/env sh
commitInfo=${1}
set -e
npm run build-proxy && cd docs/.vuepress/dist
git init && git add -A
## 如果没有输入commit信息则采用默认
if [ "${commitInfo}" -eq "" ]; then
commitInfo="408CSFamily page init"
fi
## 配置个人信息
git config user.name 'chu fan' && git config user.email 'fairy_408@2925.com' && git config --list
git commit -m "refactor:${commitInfo}"
# git push -f https://github.com/mmdapl/408CSFamily.git main
git push -f https://github.com/mmdapl/408CSFamily.git main:pages/github
cd -

15
scripts/release Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
##
## 版本发布脚本
## 链接https://jstools.dev/version-bump-prompt/
## 使用: ./scripts/release
##
## 利用commit-and-tag-version生成changelog文档并跳过commit、tag操作
readonly generateChangeLog='commit-and-tag-version && git add CHANGELOG.md'
## git提交信息
readonly commitInfo='chore(release): publish v%s'
bumpp --preid alpha --execute="$generateChangeLog" --commit "$commitInfo" --all --tag --push

35
scripts/test Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env node
/**
* 脚本测试
* 链接https://github.com/enquirer/enquirer
*/
// const {execShell} = require("./.exec");
(async() => {
const { AutoComplete } = require('enquirer')
const prompt = new AutoComplete({
name: 'flavor',
message: 'Pick your favorite flavor',
limit: 10,
initial: 2,
choices: [
'Almond',
'Apple',
'Banana',
'Blackberry',
'Blueberry',
'Cherry',
'Chocolate',
'Cinnamon',
'Coconut',
'Cranberry',
'Grape'
]
})
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error)
})()