diff --git a/extensions/appworks/CHANGELOG.md b/extensions/appworks/CHANGELOG.md index 80957cf77..06ec7308f 100644 --- a/extensions/appworks/CHANGELOG.md +++ b/extensions/appworks/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.5.3](https://github.com/apptools-lab/appworks/releases/tag/v1.5.3) + +- Feat: add material hooks for other extensions + ## [1.5.2](https://github.com/apptools-lab/appworks/releases/tag/v1.5.2) - Feat: add className={styles.xxx} automatic completion [#1002](https://github.com/apptools-lab/appworks/pull/1002) - Feat: Doctor use AppLint [#1001](https://github.com/apptools-lab/appworks/pull/1001) diff --git a/extensions/appworks/package.json b/extensions/appworks/package.json index 49fb60704..469755702 100644 --- a/extensions/appworks/package.json +++ b/extensions/appworks/package.json @@ -3,7 +3,7 @@ "displayName": "AppWorks", "description": "Application Development Pack, provide visualization and intelligent technology to build Universal Application faster and better, support Web / H5 / MiniProgram(小程序) Application.", "publisher": "iceworks-team", - "version": "1.5.2", + "version": "1.5.3", "engines": { "vscode": "^1.41.0" }, diff --git a/extensions/material-helper/CHANGELOG.md b/extensions/material-helper/CHANGELOG.md index f48b75243..2bbcd33d5 100644 --- a/extensions/material-helper/CHANGELOG.md +++ b/extensions/material-helper/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 1.1.4 + +- feat: exports material hook register function + ## 1.1.3 - chore: update taobao npm registry from `https://registry.npm.taobao.org` to `https://registry.npmmirror.com` diff --git a/extensions/material-helper/package.json b/extensions/material-helper/package.json index b76ba3b3b..23a4c2f4a 100644 --- a/extensions/material-helper/package.json +++ b/extensions/material-helper/package.json @@ -3,7 +3,7 @@ "displayName": "Component Helper", "description": "Easily use Component in React/Vue/Rax.", "publisher": "iceworks-team", - "version": "1.1.3", + "version": "1.1.4", "main": "./build/extension.js", "engines": { "vscode": "^1.41.0" @@ -389,4 +389,4 @@ "extensionDependencies": [ "iceworks-team.iceworks-refactor" ] -} +} \ No newline at end of file diff --git a/extensions/material-helper/src/extension.ts b/extensions/material-helper/src/extension.ts index 7f486862d..5f5348535 100644 --- a/extensions/material-helper/src/extension.ts +++ b/extensions/material-helper/src/extension.ts @@ -3,6 +3,7 @@ import { connectService, getHtmlForWebview } from '@appworks/connector/lib/vscod import { initExtension, registerCommand } from '@appworks/common-service'; import { autoSetContext as autoSetContextByProject } from '@appworks/project-service'; import { ICEWORKS_ICON_PATH } from '@appworks/constant'; +import { hookUtil } from '@appworks/material-engine'; import services from './services/index'; import propsAutoComplete from './propsAutoComplete'; import i18n from './i18n'; @@ -129,6 +130,25 @@ export function activate(context: vscode.ExtensionContext) { importAutoComplete(); // help user complete React Component's propTypes; propTypesAutoComplete(); + + // exports + return { + /* + example: + + hookUtil.registerHook('block.addBlockCode', (data, args) => { + console.log('block.addBlockCode', JSON.stringify(data), JSON.stringify(args)); + }); + hookUtil.registerHook('component.addCode', (data, args) => { + console.log('component.addCode', JSON.stringify(data), JSON.stringify(args)); + }); + hookUtil.registerHook('page.generate', (data, args) => { + console.log('page.generate', JSON.stringify(data), JSON.stringify(args)); + }); + + */ + registerHook: hookUtil.registerHook, + }; } export function deactivate() { } diff --git a/packages/material-engine/CHANGELOG.md b/packages/material-engine/CHANGELOG.md index 5d0092df4..c6be843e3 100644 --- a/packages/material-engine/CHANGELOG.md +++ b/packages/material-engine/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.2.2 + +- feat: add hook utils + ## 0.2.1 - feat: support get component type diff --git a/packages/material-engine/package.json b/packages/material-engine/package.json index 473e0501f..35751967a 100644 --- a/packages/material-engine/package.json +++ b/packages/material-engine/package.json @@ -1,6 +1,6 @@ { "name": "@appworks/material-engine", - "version": "0.2.1", + "version": "0.2.2", "description": "AppWorks Material Engine for VSCode extension.", "files": [ "lib" @@ -51,4 +51,4 @@ "prepublishOnly": "npm run compile" }, "gitHead": "fc5b35f95ab4cc24898845916acf598c2f34d576" -} +} \ No newline at end of file diff --git a/packages/material-engine/src/block/index.ts b/packages/material-engine/src/block/index.ts index bbd911e98..0c0ff09f6 100644 --- a/packages/material-engine/src/block/index.ts +++ b/packages/material-engine/src/block/index.ts @@ -24,6 +24,7 @@ import * as upperCamelCase from 'uppercamelcase'; import * as transfromTsToJs from 'transform-ts-to-js'; import i18n from './i18n'; import { generateBlockName } from './utils/generateBlockName'; +import { trigger } from '../utils/hook'; const { window, Position } = vscode; @@ -137,6 +138,9 @@ export async function addBlockCode(block: IMaterialBlock) { // install block dependencies await bulkInstallMaterialsDependencies([block], projectPath); + + // trigger hook + trigger('block.addBlockCode', block, { fsPath }); } export async function insertBlock(activeTextEditor: vscode.TextEditor, blockName: string) { diff --git a/packages/material-engine/src/component/index.ts b/packages/material-engine/src/component/index.ts index af4348d09..e7061ae26 100644 --- a/packages/material-engine/src/component/index.ts +++ b/packages/material-engine/src/component/index.ts @@ -36,6 +36,7 @@ import insertComponent from './utils/insertComponent'; import transformComponentsMap from './utils/transformComponentsMap'; import transformTextComponent from './utils/transformTextComponent'; import i18nService from './i18n'; +import { trigger } from '../utils/hook'; const { window, Position } = vscode; @@ -118,6 +119,9 @@ export async function addCode(dataSource: IMaterialComponent) { terminal.sendText(createNpmCommand(addDependencyAction, `${npm}@${version || 'latest'}`, '--save'), true); // activate the textEditor window.showTextDocument(activeTextEditor.document, activeTextEditor.viewColumn); + + // trigger hook + trigger('component.addCode', dataSource, { fsPath }); } export async function generateComponentCode( diff --git a/packages/material-engine/src/index.ts b/packages/material-engine/src/index.ts index a9ddfad61..6c59e838e 100644 --- a/packages/material-engine/src/index.ts +++ b/packages/material-engine/src/index.ts @@ -5,5 +5,6 @@ import * as router from './router'; import * as page from './page'; import * as scaffold from './scaffold'; import * as menu from './menu'; +import * as hookUtil from './utils/hook'; -export { block, component, material, router, page, scaffold, menu }; +export { block, component, material, router, page, scaffold, menu, hookUtil }; diff --git a/packages/material-engine/src/page/index.ts b/packages/material-engine/src/page/index.ts index b143efb0f..793633e42 100644 --- a/packages/material-engine/src/page/index.ts +++ b/packages/material-engine/src/page/index.ts @@ -27,6 +27,7 @@ import raxPageTemplate from './templates/template.rax'; import vuePageTemplate from './templates/template.vue'; import i18n from './i18n'; import renderEjsTemplates from './utils/renderEjsTemplates'; +import { trigger } from '../utils/hook'; const getCurPagesPath = async () => { const projectType = await getProjectType(); @@ -113,6 +114,9 @@ export const generate = async function ({ throw error; } + // trigger hook + trigger('page.generate', blocks, { pagePath: curPagesPath, pageName }); + return { pageIndexPath, pageName }; } }; diff --git a/packages/material-engine/src/utils/hook.ts b/packages/material-engine/src/utils/hook.ts new file mode 100644 index 000000000..522ac962d --- /dev/null +++ b/packages/material-engine/src/utils/hook.ts @@ -0,0 +1,37 @@ +/** + * hook utils + */ +const hookStore = {}; + +export interface IMaterialHookHandler { + (action: string, data?: any, args?: any): any; +} + +export function registerHook(action: string, handler: IMaterialHookHandler) { + if (!action || !handler) { + return; + } + + hookStore[action] = hookStore[action] || []; + + console.log('registerHook', action); + + hookStore[action].push(handler); +} + +export function trigger(action: string, ...data: any) { + if (!action || !hookStore[action]) { + console.log(`triggerHook, no action or no handler. action: ${action}`); + return; + } + + console.log('triggerHook', action); + + const handlers = hookStore[action]; + + handlers.forEach((handler) => { + if (handler && typeof handler === 'function') { + handler(...data); + } + }); +} diff --git a/yarn.lock b/yarn.lock index ebdd6a2f3..d050249e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1864,6 +1864,11 @@ resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7" integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw== +"@csstools/selector-specificity@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.0.tgz#65b12f12db55188422070e34687bf3af09870922" + integrity sha512-rZ6vufeY/UjAgtyiJ4WvfF6XP6HizIyOfbZOg0RnecIwjrvH8Am3nN1BpKnnPZunYAkUcPPXDhwbxOtGop8cfQ== + "@eslint/eslintrc@^0.4.3": version "0.4.3" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.3.tgz#9e42981ef035beb3dd49add17acb96e8ff6f394c" @@ -5489,7 +5494,7 @@ braces@^2.3.1, braces@^2.3.2: split-string "^3.0.2" to-regex "^3.0.1" -braces@^3.0.1, braces@~3.0.2: +braces@^3.0.1, braces@^3.0.2, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -7151,6 +7156,11 @@ css-functions-list@^3.0.1: resolved "https://registry.yarnpkg.com/css-functions-list/-/css-functions-list-3.0.1.tgz#1460df7fb584d1692c30b105151dbb988c8094f9" integrity sha512-PriDuifDt4u4rkDgnqRCLnjfMatufLmWNfQnGCq34xZwpY3oabwhB9SqRBmuvWUgndbemCFlKqg+nO7C2q0SBw== +css-functions-list@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/css-functions-list/-/css-functions-list-3.1.0.tgz#cf5b09f835ad91a00e5959bcfc627cd498e1321b" + integrity sha512-/9lCvYZaUbBGvYUgYGFJ4dcYiyqdhSjG7IPVluoV8A1ILjkF7ilmhp1OGUz8n+nmBcu0RNrQAzgD8B6FJbrt2w== + css-has-pseudo@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/css-has-pseudo/-/css-has-pseudo-0.10.0.tgz#3c642ab34ca242c59c41a125df9105841f6966ee" @@ -7531,6 +7541,13 @@ debug@^4.3.2, debug@^4.3.3: dependencies: ms "2.1.2" +debug@^4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" @@ -10705,6 +10722,11 @@ html-tags@^3.1.0: resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140" integrity sha512-1qYz89hW3lFDEazhjW0yVAV87lw8lVkrJocr72XmBkMKsoSVJCQx3W8BXsC7hO2qAt8BoVjYjtAcZ9perqGnNg== +html-tags@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.2.0.tgz#dbb3518d20b726524e4dd43de397eb0a95726961" + integrity sha512-vy7ClnArOZwCnqZgvv+ddgHgJiAFXe3Ge9ML5/mBctVJoUoYPCdxVucOywjDARn6CVoh3dRSFdPHy2sX80L0Wg== + html-webpack-plugin@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b" @@ -13382,6 +13404,11 @@ known-css-properties@^0.24.0: resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.24.0.tgz#19aefd85003ae5698a5560d2b55135bf5432155c" integrity sha512-RTSoaUAfLvpR357vWzAz/50Q/BmHfmE6ETSWfutT0AJiw10e6CmcdYRQJlLRd95B53D0Y2aD1jSxD3V3ySF+PA== +known-css-properties@^0.25.0: + version "0.25.0" + resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.25.0.tgz#6ebc4d4b412f602e5cfbeb4086bd544e34c0a776" + integrity sha512-b0/9J1O9Jcyik1GC6KC42hJ41jKwdO/Mq8Mdo5sYN+IuRTXs2YFHZC3kZSx6ueusqa95x3wLYe/ytKjbAfGixA== + ko-sleep@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/ko-sleep/-/ko-sleep-1.0.3.tgz#28a2a0a1485e8b7f415ff488dee17d24788ab082" @@ -14301,6 +14328,14 @@ micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4: snapdragon "^0.8.1" to-regex "^3.0.2" +micromatch@^4.0.5: + version "4.0.5" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" + integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== + dependencies: + braces "^3.0.2" + picomatch "^2.3.1" + miller-rabin@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d" @@ -14682,6 +14717,11 @@ nanoid@^3.3.1: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.1.tgz#6347a18cac88af88f58af0b3594b723d5e99bb35" integrity sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw== +nanoid@^3.3.4: + version "3.3.4" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab" + integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw== + nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" @@ -16021,6 +16061,11 @@ picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3: resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972" integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw== +picomatch@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" + integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== + pify@^2.0.0, pify@^2.2.0, pify@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" @@ -16851,6 +16896,14 @@ postcss-selector-parser@^6.0.0, postcss-selector-parser@^6.0.2, postcss-selector cssesc "^3.0.0" util-deprecate "^1.0.2" +postcss-selector-parser@^6.0.10: + version "6.0.10" + resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-6.0.10.tgz#79b61e2c0d1bfc2602d549e11d0876256f8df88d" + integrity sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w== + dependencies: + cssesc "^3.0.0" + util-deprecate "^1.0.2" + postcss-selector-parser@^6.0.6, postcss-selector-parser@^6.0.9: version "6.0.9" resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-6.0.9.tgz#ee71c3b9ff63d9cd130838876c13a2ec1a992b2f" @@ -16949,6 +17002,15 @@ postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.13, postcss@^7.0.14, postcss@^7.0.1 source-map "^0.6.1" supports-color "^6.1.0" +postcss@^8.4.14: + version "8.4.14" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.14.tgz#ee9274d5622b4858c1007a74d76e42e56fd21caf" + integrity sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig== + dependencies: + nanoid "^3.3.4" + picocolors "^1.0.0" + source-map-js "^1.0.2" + postcss@^8.4.6, postcss@^8.4.7: version "8.4.12" resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.12.tgz#1e7de78733b28970fa4743f7da6f3763648b1905" @@ -19752,7 +19814,7 @@ stylelint-scss@^4.1.0: postcss-selector-parser "^6.0.6" postcss-value-parser "^4.1.0" -stylelint@^13.12.0, stylelint@^13.7.0: +stylelint@^13.12.0: version "13.13.1" resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-13.13.1.tgz#fca9c9f5de7990ab26a00f167b8978f083a18f3c" integrity sha512-Mv+BQr5XTUrKqAXmpqm6Ddli6Ief+AiPZkRsIrAoUKFuq/ElkUh9ZMYxXD0iQNZ5ADghZKLOWz1h7hTClB7zgQ== @@ -19853,6 +19915,52 @@ stylelint@^14.3.0: v8-compile-cache "^2.3.0" write-file-atomic "^4.0.1" +stylelint@^14.5.1: + version "14.9.0" + resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-14.9.0.tgz#6d68fc69916f1df54798a6cc42f1c69e86fbfe1e" + integrity sha512-+xsQ4uKS56RQs8AGYx2CXc9nhWyPR7c/G0RqyiKgWZx2LuE3VJnIhGRQXUfnGQXOqBPHxNjMCHiK5NNQRB52sw== + dependencies: + "@csstools/selector-specificity" "^2.0.0" + balanced-match "^2.0.0" + colord "^2.9.2" + cosmiconfig "^7.0.1" + css-functions-list "^3.1.0" + debug "^4.3.4" + execall "^2.0.0" + fast-glob "^3.2.11" + fastest-levenshtein "^1.0.12" + file-entry-cache "^6.0.1" + get-stdin "^8.0.0" + global-modules "^2.0.0" + globby "^11.1.0" + globjoin "^0.1.4" + html-tags "^3.2.0" + ignore "^5.2.0" + import-lazy "^4.0.0" + imurmurhash "^0.1.4" + is-plain-object "^5.0.0" + known-css-properties "^0.25.0" + mathml-tag-names "^2.1.3" + meow "^9.0.0" + micromatch "^4.0.5" + normalize-path "^3.0.0" + picocolors "^1.0.0" + postcss "^8.4.14" + postcss-media-query-parser "^0.2.3" + postcss-resolve-nested-selector "^0.1.1" + postcss-safe-parser "^6.0.0" + postcss-selector-parser "^6.0.10" + postcss-value-parser "^4.2.0" + resolve-from "^5.0.0" + string-width "^4.2.3" + strip-ansi "^6.0.1" + style-search "^0.1.0" + supports-hyperlinks "^2.2.0" + svg-tags "^1.0.0" + table "^6.8.0" + v8-compile-cache "^2.3.0" + write-file-atomic "^4.0.1" + stylelint@^9.10.1: version "9.10.1" resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-9.10.1.tgz#5f0ee3701461dff1d68284e1386efe8f0677a75d"