This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
下载release.zip,抽取依赖文件放到指定位置
- Loading branch information
Showing
8 changed files
with
221 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ coverage | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
running | ||
release.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# MaaPipelineViewer | ||
|
||
就是用来编辑 pipeline 的小玩意 | ||
|
||
构建 | ||
|
||
```shell | ||
python scripts/build.py | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,119 @@ | ||
import fs from 'fs' | ||
|
||
fs.copyFile( | ||
'./packages/server/assets/config.develop.json', | ||
'./packages/server/config.json' | ||
) | ||
fs.copyFile('./packages/server/assets/init.zip', './packages/server/saves.zip') | ||
fs.mkdir('./packages/server/library/maaframework', { recursive: true }) | ||
fs.mkdir('./packages/server/library/maaframework/bin', { recursive: true }) | ||
fs.mkdir('./packages/server/library/maaframework/MaaAgentBinary', { | ||
recursive: true | ||
}) | ||
fs.mkdir('./packages/server/library/maaframework/model', { recursive: true }) | ||
fs.copyFile( | ||
'./packages/server/assets/controller_config.json', | ||
'./packages/server/library/maaframework/controller_config.json' | ||
) | ||
const { spawn } = require('child_process') | ||
const { createWriteStream } = require('fs') | ||
const { mkdir, readFile, rm, copyFile, cp } = require('fs/promises') | ||
const { join, resolve } = require('path') | ||
const { chdir } = require('process') | ||
const { arch, platform } = require('os') | ||
|
||
// fs.copyFile( | ||
// './packages/server/assets/config.develop.json', | ||
// './packages/server/config.json' | ||
// ) | ||
// fs.copyFile('./packages/server/assets/init.zip', './packages/server/saves.zip') | ||
// fs.mkdir('./packages/server/library/maaframework', { recursive: true }) | ||
// fs.mkdir('./packages/server/library/maaframework/bin', { recursive: true }) | ||
// fs.mkdir('./packages/server/library/maaframework/MaaAgentBinary', { | ||
// recursive: true | ||
// }) | ||
// fs.mkdir('./packages/server/library/maaframework/model', { recursive: true }) | ||
// fs.copyFile( | ||
// './packages/server/assets/controller_config.json', | ||
// './packages/server/library/maaframework/controller_config.json' | ||
// ) | ||
|
||
async function downloadTo(url, path) { | ||
const axios = require('axios') | ||
const writer = createWriteStream(path) | ||
|
||
return await axios({ | ||
method: 'get', | ||
url, | ||
responseType: 'stream' | ||
}).then(response => { | ||
return new Promise((resolve, reject) => { | ||
response.data.pipe(writer) | ||
let error = null | ||
writer.on('error', err => { | ||
error = err | ||
writer.close() | ||
reject(err) | ||
}) | ||
writer.on('close', () => { | ||
if (!error) { | ||
resolve(true) | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
const archMapper = { | ||
x64: 'x86_64', | ||
arm64: 'aarch64' | ||
} | ||
|
||
const platMapper = { | ||
win32: 'win', | ||
linux: 'linux', | ||
darwin: 'macos' | ||
} | ||
|
||
async function main() { | ||
const version = JSON.parse(await readFile('package.json', 'utf-8')).version | ||
const frameworkVersion = '0.3.6' | ||
|
||
const ar = archMapper[arch()] | ||
const os = platMapper[platform()] | ||
|
||
if (!ar || !os) { | ||
console.log(`platform ${platform()} arch ${arch()} not supported`) | ||
return | ||
} | ||
|
||
const envUrl = `https://github.com/MaaAssistantArknights/MaaJsonViewer/releases/download/v${version}/MaaJsonViewer-win-v${version}.zip` | ||
const frameworkUrl = `https://github.com/MaaAssistantArknights/MaaFramework/releases/download/v${frameworkVersion}/MAA-${os}-${arch}-v${frameworkVersion}.zip` | ||
const targetDir = join('.', 'running') | ||
const libraryDir = join(targetDir, 'library') | ||
|
||
console.log('update submodules') | ||
await new Promise(resolve => { | ||
spawn('git', ['submodule', 'update', '--init', '--recursive'], { | ||
stdio: 'inherit' | ||
}).addListener('close', resolve) | ||
}) | ||
chdir('packages/MaaJSLoader') | ||
await new Promise(resolve => { | ||
spawn('git', ['checkout', 'main'], { | ||
stdio: 'inherit' | ||
}).addListener('close', resolve) | ||
}) | ||
chdir('../..') | ||
|
||
console.log('install node modules') | ||
await new Promise(resolve => { | ||
spawn('npm', ['install'], { | ||
stdio: 'inherit' | ||
}).addListener('close', resolve) | ||
}) | ||
|
||
await mkdir(libraryDir, { recursive: true }) | ||
const extract = require('extract-zip') | ||
|
||
console.log('download', envUrl) | ||
const releasePath = 'release.zip' | ||
await downloadTo(envUrl, releasePath) | ||
await extract(releasePath, { | ||
dir: resolve(targetDir) | ||
}) | ||
|
||
console.log('download', frameworkUrl) | ||
const frameworkPath = 'framework.zip' | ||
await downloadTo(frameworkUrl, frameworkPath) | ||
const extractPath = join(targetDir, 'library', 'maaframework', 'install') | ||
await extract(frameworkPath, { | ||
dir: resolve(extractPath) | ||
}) | ||
await cp(join(extractPath, 'bin'), join(targetDir, 'library', 'maaframework')) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
# python scripts\build.py | ||
from urllib import request, error | ||
import os | ||
import shutil | ||
import zipfile | ||
from pathlib import Path | ||
|
||
# MAAjsonViever release版号 | ||
RELEASES_TAG = "v1.0.9" | ||
|
||
SAVEPATH = os.path.join(Path(__file__).parent, f'{RELEASES_TAG}.zip') | ||
projectDir: str = os.getcwd() | ||
serverDir = os.path.join(projectDir, r'packages\server') | ||
zipurl: str = f'https://github.com/MaaAssistantArknights/MaaJsonViewer/releases/download/{RELEASES_TAG}/MaaJsonViewer-win-{RELEASES_TAG}.zip' | ||
|
||
|
||
def reporthook(a, b, c): | ||
'''回调函数 | ||
@a:已经下载的数据块 | ||
@b:数据块的大小 | ||
@c:远程文件的大小 | ||
''' | ||
per = 100.0*a*b/c | ||
if per > 100: | ||
per = 100 | ||
print( | ||
f'---- {round(a*b/1024/1024,2)}MB / {round(c/1024/1024,2)}MB, {round(per,2)}%') | ||
|
||
|
||
def extractlib(zipPath: str, libPath: str): | ||
if os.path.exists(zipPath) is False: | ||
print(f'{zipPath} file not found') | ||
return | ||
if zipfile.is_zipfile(zipPath) is False: | ||
print(f'{zipPath} this file not a zip file') | ||
return | ||
with zipfile.ZipFile(zipPath, 'r') as zfile: | ||
zfList = zfile.namelist() | ||
for item in zfList[:]: | ||
if 'web' in item: | ||
zfList.remove(item) | ||
elif '.exe' in item: | ||
zfList.remove(item) | ||
for id, fileName in enumerate(zfList): | ||
zfile.extract(fileName, path=libPath) | ||
zfile.close() | ||
|
||
|
||
def npmIstall(): | ||
'''下载npm package''' | ||
print(f'git submodule MaaJSLoader') | ||
os.system('git submodule update --init --recursive') | ||
print(f'project npm i') | ||
os.system('npm i') | ||
|
||
|
||
if __name__ == "__main__": | ||
shutil.copyfile(f'{serverDir}/assets\config.json', | ||
f'{serverDir}\config.json') | ||
if os.path.exists(f'{projectDir}/node_modules') is False: | ||
print(f'start install npm package') | ||
npmIstall() | ||
print(f'successed install npm package') | ||
if os.path.exists(f'{serverDir}\library') is False: | ||
try: | ||
print(f'download MaaJsonViever-release{RELEASES_TAG}.zip') | ||
request.urlretrieve(zipurl, SAVEPATH, reporthook) | ||
extractlib(SAVEPATH, serverDir) | ||
print(f'success!!') | ||
except error.URLError as e: | ||
print( | ||
f'{e}\ndownload MaaJsonViever-release{RELEASES_TAG} failed\n请手动下载release包并解压!!') | ||
if os.path.exists(f'{serverDir}\library') is True: | ||
os.remove(SAVEPATH) |