diff --git a/.github/workflows/publish npm.yml b/.github/workflows/publish npm.yml index d57fb51..53e3dd8 100644 --- a/.github/workflows/publish npm.yml +++ b/.github/workflows/publish npm.yml @@ -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 diff --git a/packages/plugin-test/build.json b/packages/plugin-test/build.json new file mode 100644 index 0000000..840cacf --- /dev/null +++ b/packages/plugin-test/build.json @@ -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"] + }] + ] +} diff --git a/packages/plugin-test/package.json b/packages/plugin-test/package.json new file mode 100644 index 0000000..6054c2f --- /dev/null +++ b/packages/plugin-test/package.json @@ -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" + } +} diff --git a/packages/plugin-test/src/index.tsx b/packages/plugin-test/src/index.tsx new file mode 100644 index 0000000..d489336 --- /dev/null +++ b/packages/plugin-test/src/index.tsx @@ -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 { + 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 ( +
+ + +
+ ); + } +} + +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 diff --git a/packages/plugin-test/tsconfig.json b/packages/plugin-test/tsconfig.json new file mode 100644 index 0000000..c37b76e --- /dev/null +++ b/packages/plugin-test/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "lib" + }, + "include": [ + "./src/" + ] +}