#modify package maker program

This commit is contained in:
锦恢 2023-07-16 19:38:32 +08:00
parent ca4786ce41
commit 5136794741
11 changed files with 190 additions and 71 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ node_modules
*.vsix *.vsix
parser_stuck.v parser_stuck.v
**/*.wasm **/*.wasm
out-js/

View File

@ -1,17 +1,19 @@
.vscode/** .vscode/**
.vscode-test/**
test/**
.gitignore .gitignore
**/.gitignore
.git .git
.yarnrc
vsc-extension-quickstart.md
**/jsconfig.json
**/*.map **/*.map
**/.eslintrc.json .eslintrc.json
dist/**/*.map dist
webpack.config.js webpack.config.js
node_modules node_modules
out1/** out-js
vsixmake.js src
script script
resources/**/*.js
resources/**/*.d.ts
resources/**/*.wasm
vsixmake.js
CHANGELOG.md CHANGELOG.md
README.md
tsconfig.json

View File

@ -2,8 +2,27 @@
![](https://img.shields.io/badge/version-0.3.0-blue) ![](https://img.shields.io/badge/version-0.3.0-blue)
---
## Developer
make pakage:
```bash ```bash
npm i python script/command/make_package.py
``` ```
Enter Vscode & F5 make package.json command title token:
```bash
python script/command/make_title_token.py
```
translate title token:
```bash
python script/command/translate_from_en.py
```

View File

@ -5,7 +5,7 @@
"publisher": "sterben", "publisher": "sterben",
"homepage": "https://digital-eda.github.io/DIDE-doc-Cn", "homepage": "https://digital-eda.github.io/DIDE-doc-Cn",
"version": "0.3.0", "version": "0.3.0",
"main": "./out1/extension", "main": "./out/extension",
"icon": "images/DIDE.png", "icon": "images/DIDE.png",
"engines": { "engines": {
"vscode": "^1.72.0" "vscode": "^1.72.0"

21
script/build.bat Normal file
View File

@ -0,0 +1,21 @@
@echo off
cls
echo [10%] compile typescript
call tsc -p ./ --outDir out-js
echo [20%] webpack
call webpack --mode production
echo collect static resources
mkdir
echo [30%] remove out-js
if exist out-js (
rmdir /s /q out-js
)
echo [30%] remove out
if exist out (
rmdir /s /q out
)
echo [100%] finish build :D

View File

@ -0,0 +1,114 @@
import os
import shutil
import zipfile
from colorama import Fore, Style
from typing import List, Union
from collections import namedtuple
Command = namedtuple(typename='Command', field_names=['name', 'cmd'])
class CommandPipe:
def __init__(self) -> None:
self.pipes: List[Command] = []
def add_command(self, name: str, cmd: str):
command = Command(name, cmd)
self.pipes.append(command)
def run(self):
for i, p in enumerate(self.pipes):
progress = int((i + 1) / len(self.pipes) * 100)
space_prefix = ' ' if progress < 100 else ''
print(Fore.GREEN, f'[{space_prefix}{progress}%]', Style.RESET_ALL, p.name)
if callable(p.cmd):
p.cmd()
elif isinstance(p.cmd, str):
os.system(p.cmd)
print('Done! :D')
def remove_folder(name: str):
if os.path.exists(name):
shutil.rmtree(name)
def copy_dir(src, dist):
if os.path.exists(dist):
shutil.rmtree(dist)
shutil.copytree(src, dist)
def copy_file(src, dist):
if os.path.exists(dist):
os.remove(dist)
dirname = os.path.dirname(dist)
if not os.path.exists(dirname):
os.makedirs(dirname)
shutil.copyfile(src, dist)
def modify_vsix():
vsix_filter = filter(lambda file: file.endswith('.vsix'), os.listdir('.'))
vsix_file = list(vsix_filter)
if len(vsix_file) == 0:
print(Fore.RED, 'no .vsix is detected', Style.RESET_ALL)
exit()
vsix_path = vsix_file[0]
if not os.path.exists('dist'):
os.mkdir('dist')
dist_path = os.path.join('dist', vsix_path.replace('.vsix', '.zip'))
shutil.move(vsix_path, dist_path)
extract_folder = os.path.join('dist', 'digital-ide-temp')
with zipfile.ZipFile(dist_path, 'r') as zip_ref:
zip_ref.extractall(extract_folder)
os.remove(dist_path)
# move public
copy_dir('./resources/public', os.path.join(extract_folder, 'extension', 'resources', 'public'))
# move wasm
copy_dir('./resources/netlist/resources/kernel', os.path.join(extract_folder, 'extension', 'resources', 'kernel'))
copy_dir('./resources/fsm/resources/tree-sitter', os.path.join(extract_folder, 'extension', 'resources', 'tree-sitter'))
copy_file('./resources/hdlParser/parser.wasm', os.path.join(extract_folder, 'extension', 'out', 'parser.wasm'))
# webview
copy_dir('./resources/fsm/view', os.path.join(extract_folder, 'extension', 'resources', 'fsm', 'view'))
copy_dir('./resources/netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'netlist', 'view'))
# remake
target_path = os.path.join('dist', vsix_path)
zip_dir(extract_folder, target_path)
def zip_dir(dirpath, outFullName):
zip = zipfile.ZipFile(outFullName, "w", zipfile.ZIP_DEFLATED)
for path, _, filenames in os.walk(dirpath):
fpath = path.replace(dirpath, '')
for filename in filenames:
zip.write(os.path.join(path, filename), os.path.join(fpath, filename))
zip.close()
def install_extension():
vsix_filter = filter(lambda file: file.endswith('.vsix'), os.listdir('dist'))
vsix_files = list(vsix_filter)
if len(vsix_files) == 0:
print(Fore.RED, 'no .vsix is detected in dist', Style.RESET_ALL)
exit()
vsix_path = os.path.join('dist', vsix_files[0])
os.system('code --install-extension ' + vsix_path)
pipe = CommandPipe()
pipe.add_command('uninstall original extension', 'code --uninstall-extension sterben.digital-ide')
pipe.add_command('compile typescript', 'tsc -p ./ --outDir out-js')
pipe.add_command('webpack', 'webpack --mode production')
pipe.add_command('make vsix installer', 'vsce package')
pipe.add_command('modify vsix installer', lambda : modify_vsix())
pipe.add_command('remove out-js', lambda : remove_folder('out-js'))
pipe.add_command('remove out', lambda : remove_folder('out'))
pipe.add_command('install', lambda : install_extension())
pipe.run()

13
script/test.bat Normal file
View File

@ -0,0 +1,13 @@
@echo off
set production_folder=dist
@REM important static or config
if not exist %production_folder% (
mkdir %production_folder%
)
echo vsce package
call vsce package

View File

@ -8,6 +8,9 @@ module mux2to1(
); );
assign outp = sel == 1'b0 ? a : b; assign outp = sel == 1'b0 ? a : b;
endmodule endmodule

View File

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "commonjs",
"target": "ES2020", "target": "ES2020",
"outDir": "out1", "outDir": "out-js",
"skipLibCheck": true, "skipLibCheck": true,
"lib": [ "lib": [
"ES2020" "ES2020"

View File

@ -1,54 +0,0 @@
const { execSync } = require('child_process');
const fs = require('fs');
const fspath = require('path');
const PACKAGE_PATH = './package.json';
const SAVE_FOLDER = 'dist';
const WEBPACK_OUT_FOLDER = 'out';
function readJSON(path) {
const context = fs.readFileSync(path, 'utf-8');
return JSON.parse(context);
}
function writeJSON(path, obj) {
const jsonString = JSON.stringify(obj, null, '\t');
fs.writeFileSync(path, jsonString);
}
function changeMain(path) {
const packageJS = readJSON(PACKAGE_PATH);
packageJS.main = path;
writeJSON(PACKAGE_PATH, packageJS);
}
function findVsix() {
for (const file of fs.readdirSync(__dirname)) {
if (file.endsWith('.vsix') && file.includes('digital-ide')) {
return file;
}
}
return null;
}
if (!fs.existsSync(SAVE_FOLDER)) {
fs.mkdirSync(SAVE_FOLDER);
}
changeMain('./out/extension');
execSync('vsce package');
changeMain('./src/extension');
// remove orginal digital ide
execSync('code --uninstall-extension sterben.digital-ide');
const vsix = findVsix();
const targetPath = fspath.join(SAVE_FOLDER, vsix);
fs.copyFileSync(vsix, targetPath);
fs.unlinkSync(vsix);
fs.rm(WEBPACK_OUT_FOLDER, { recursive: true, force: true }, () => {});
const vsixPath = fspath.join(SAVE_FOLDER, vsix);
// install new one
execSync('code --install-extension ' + vsixPath);

View File

@ -2,7 +2,7 @@ const path = require('path');
const config = { const config = {
target: 'node', target: 'node',
entry: './out1/extension.js', entry: './out-js/extension.js',
output: { output: {
path: path.resolve(__dirname, 'out'), path: path.resolve(__dirname, 'out'),
filename: 'extension.js', filename: 'extension.js',