Skip to content

Commit

Permalink
feat: temp update
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Dec 16, 2023
1 parent 0160cc8 commit 49fec23
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 50 deletions.
91 changes: 41 additions & 50 deletions .github/workflows/publish npm.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,49 @@
name: Publish NPM Packages
on: push
push:
branches:
- main
paths:
- 'packages/*/package.json'
workflow_dispatch:
inputs:
packagePath:
description: 'Path to the package (example: action-block)'
required: true
versionType:
description: 'Version update type (major, minor, patch)'
required: true
default: 'patch'

jobs:
publish:
publish-package:
runs-on: ubuntu-latest
if: >-
github.ref == 'refs/heads/main' &&
(github.actor == 'JackLian' || github.actor == 'liujuping')
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # 完全克隆

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # 根据项目需求更改 Node.js 版本
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16' # 或者您希望的任何版本

- name: Install Dependencies and Publish
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
cd packages
cd ${{ github.event.inputs.packagePath }}
npm install
# 假设您使用 npm 来修改版本和发布
npm run build
npm version patch
npm publish
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
echo "::set-output name=PACKAGE_NAME::$(node -p "require('./package.json').name")"
echo "::set-output name=PACKAGE_VERSION::$(node -p "require('./package.json').version")"
- name: Check for package.json changes
id: package-json-changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
CHANGED_PKG_FILES=$(git diff --name-only HEAD~1 HEAD -- 'packages/*/package.json')
if [ -z "$CHANGED_PKG_FILES" ]; then
echo "No package.json changes detected."
echo "CHANGED_PACKAGES=none" >> $GITHUB_ENV
else
CHANGED_DIRS=$(echo "$CHANGED_PKG_FILES" | xargs -L1 dirname)
echo "CHANGED_PACKAGES=$CHANGED_DIRS" >> $GITHUB_ENV
echo "Changed package.json files: $CHANGED_PKG_FILES"
fi
git tag -a "${{ steps.package_info.outputs.PACKAGE_NAME }}@${{ steps.package_info.outputs.PACKAGE_VERSION }}" -m "Release ${{ steps.package_info.outputs.PACKAGE_NAME }} version ${{ steps.package_info.outputs.PACKAGE_VERSION }}"
git push origin "${{ steps.package_info.outputs.PACKAGE_NAME }}@${{ steps.package_info.outputs.PACKAGE_VERSION }}"
- name: Publish packages
if: env.CHANGED_PACKAGES != 'none'
run: |
for dir in $CHANGED_PACKAGES; do
echo "Entering directory $dir"
cd $dir
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
npm install
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [[ $PACKAGE_VERSION == *beta* ]]; then
echo "Publishing $PACKAGE_NAME@$PACKAGE_VERSION as beta..."
npm publish --tag beta
else
echo "Publishing $PACKAGE_NAME@$PACKAGE_VERSION..."
npm publish
fi
cd -
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 确保在您的 GitHub 仓库的 Secrets 中设置了 NPM_TOKEN
19 changes: 19 additions & 0 deletions packages/plugin-test/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"plugins": [
[
"@alilc/build-plugin-alt",
{
"type": "plugin"
}
],
[
"build-plugin-fusion",
{
"themePackage": "@alifd/theme-lowcode-light"
}
],
["build-plugin-moment-locales", {
"locales": ["zh-cn"]
}]
]
}
44 changes: 44 additions & 0 deletions packages/plugin-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@alilc/lowcode-plugin-test",
"version": "1.0.0",
"description": "alibaba lowcode editor test plugin",
"files": [
"es",
"lib"
],
"main": "lib/index.js",
"module": "es/index.js",
"scripts": {
"start": "build-scripts start",
"build": "build-scripts build",
"prepublishOnly": "npm run build"
},
"keywords": [
"lowcode",
"editor"
],
"dependencies": {
"@alilc/lowcode-utils": "^1.0.0",
"@alilc/lowcode-types": "^1.1.9",
"react": "^16.8.1",
"react-dom": "^16.8.1"
},
"devDependencies": {
"@alib/build-scripts": "^0.1.3",
"@alilc/build-plugin-alt": "^1.0.1",
"@alilc/lowcode-engine": "^1.0.0",
"@types/react": "^16.9.13",
"@types/react-dom": "^16.9.4",
"build-plugin-fusion": "^0.1.22",
"build-plugin-moment-locales": "^0.1.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/alibaba/lowcode-plugins.git",
"directory": "packages/plugin-undo-redo"
}
}
115 changes: 115 additions & 0 deletions packages/plugin-test/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import React, { PureComponent } from 'react';
import { project } from '@alilc/lowcode-engine';
import { Button, Icon } from '@alifd/next';
import { PluginProps, IPublicTypeDisposable } from '@alilc/lowcode-types';

export interface IProps extends PluginProps {
logo?: string;
}

export interface IState {
undoEnable: boolean;
redoEnable: boolean;
}

class Test extends PureComponent<IProps, IState> {
static displayName = 'Test';

private history: any;
private changeDocumentDispose?: IPublicTypeDisposable;
private changeStateDispose?: IPublicTypeDisposable;
constructor(props: any) {
super(props);
this.state = {
undoEnable: false,
redoEnable: false,
};
this.init();
}

init = (): void => {
this.changeDocumentDispose = project.onChangeDocument(doc => {
this.history = doc.history;
this.updateState(this.history?.getState() || 0);
this.changeStateDispose?.();
this.changeStateDispose = this.history.onChangeState(() => {
this.updateState(this.history?.getState() || 0);
});
});
};

updateState = (state: number): void => {
this.setState({
undoEnable: !!(state & 1),
redoEnable: !!(state & 2),
});
};

handleUndoClick = (): void => {
this.history.back();
};

handleRedoClick = (): void => {
this.history.forward();
};

componentWillUnmount() {
this.changeDocumentDispose?.();
this.changeStateDispose?.();
}

render(): React.ReactNode {
const { undoEnable, redoEnable } = this.state;
return (
<div className="lowcode-plugin-undo-redo">
<Button
size="medium"
data-tip="撤销"
data-dir="bottom"
onClick={this.handleUndoClick}
ghost
disabled={!undoEnable}
>
<Icon type="houtui" />
</Button>
<Button
size="medium"
data-tip="恢复"
data-dir="bottom"
onClick={this.handleRedoClick}
ghost
disabled={!redoEnable}
>
<Icon type="qianjin" />
</Button>
</div>
);
}
}

const plugin = (ctx: any) => {
return {
// 插件名,注册环境下唯一
name: 'PluginTest',
// 依赖的插件(插件名数组)
dep: [],
// 插件的初始化函数,在引擎初始化之后会立刻调用
init() {
// 往引擎增加面板
ctx.skeleton.add({
area: 'topArea',
type: 'Widget',
name: 'undoRedo',
content: Test,
props: {
align: 'right',
width: 88,
},
})
},
};
};

plugin.pluginName = 'PluginTest'

export default plugin
9 changes: 9 additions & 0 deletions packages/plugin-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib"
},
"include": [
"./src/"
]
}

0 comments on commit 49fec23

Please sign in to comment.