From 7ea1ba5ba967741acad636764cf024187aa768db Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 13 Feb 2023 21:43:14 +0800 Subject: [PATCH] chore: assets init script Signed-off-by: Innei --- dockerfile | 2 -- package.json | 2 +- scripts/assets-push.sh | 1 + scripts/init-project.mjs | 22 ++++++++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 scripts/init-project.mjs diff --git a/dockerfile b/dockerfile index ac0d2365..d66975ea 100644 --- a/dockerfile +++ b/dockerfile @@ -2,8 +2,6 @@ FROM node:16-alpine as builder WORKDIR /app COPY . . RUN apk add git make g++ alpine-sdk python3 py3-pip unzip -RUN git clone https://github.com/mx-space/assets.git --depth=1 -RUN rm -rf assets/.git RUN npm i -g pnpm RUN pnpm install RUN pnpm bundle diff --git a/package.json b/package.json index ab85482f..34ae300b 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "homepage": "https://github.com/mx-space/core#readme", "issues": "https://github.com/mx-space/core/issues", "scripts": { - "prepare": "husky install", + "prepare": "husky install && node scripts/init-project.mjs", "prebuild": "rimraf dist", "build": "nest build", "build:webpack": "nest build --webpack --webpackPath ./configs/webpack.config.js -c ./configs/nest-cli.webpack.json", diff --git a/scripts/assets-push.sh b/scripts/assets-push.sh index e277110b..b8778531 100644 --- a/scripts/assets-push.sh +++ b/scripts/assets-push.sh @@ -1,5 +1,6 @@ set -e cd assets +rm -rf .git git init git add . git commit -m 'update assets' diff --git a/scripts/init-project.mjs b/scripts/init-project.mjs new file mode 100644 index 00000000..7b9a9d83 --- /dev/null +++ b/scripts/init-project.mjs @@ -0,0 +1,22 @@ +// @ts-check +import fs from 'fs' +import path from 'path' +import { $ } from 'zx' + +async function main() { + const cwd = process.cwd() + const existAsset = fs.existsSync(path.resolve(cwd, 'assets')) + const assetsRepoUrl = `https://github.com/mx-space/assets.git` + if (!existAsset) { + await $`git clone ${assetsRepoUrl}`.catch((err) => { + console.log(err) + console.log('git clone assets repo failed, please check your network') + }) + fs.rmSync(path.resolve(cwd, 'assets', '.git'), { + force: true, + recursive: true, + }) + } +} + +main()