Skip to content

Commit

Permalink
release 1.5.3 (#1030)
Browse files Browse the repository at this point in the history
* chore: version

* feat: add material hook (#1024)

* feat: add material hook

* feat: 增加log

* feat: 升级版本,补充changelog

* feat: 补充log

* feat: 修改文件名

* feat: 修改方法名

Co-authored-by: qiansheng.wjz <[email protected]>

* fix: lint

Co-authored-by: wjz <[email protected]>
Co-authored-by: qiansheng.wjz <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2022
1 parent 87c8566 commit 93464d3
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 8 deletions.
4 changes: 4 additions & 0 deletions extensions/appworks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion extensions/appworks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 4 additions & 0 deletions extensions/material-helper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 2 additions & 2 deletions extensions/material-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -389,4 +389,4 @@
"extensionDependencies": [
"iceworks-team.iceworks-refactor"
]
}
}
20 changes: 20 additions & 0 deletions extensions/material-helper/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() { }
4 changes: 4 additions & 0 deletions packages/material-engine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.2.2

- feat: add hook utils

## 0.2.1

- feat: support get component type
Expand Down
4 changes: 2 additions & 2 deletions packages/material-engine/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -51,4 +51,4 @@
"prepublishOnly": "npm run compile"
},
"gitHead": "fc5b35f95ab4cc24898845916acf598c2f34d576"
}
}
4 changes: 4 additions & 0 deletions packages/material-engine/src/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/material-engine/src/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion packages/material-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
4 changes: 4 additions & 0 deletions packages/material-engine/src/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -113,6 +114,9 @@ export const generate = async function ({
throw error;
}

// trigger hook
trigger('page.generate', blocks, { pagePath: curPagesPath, pageName });

return { pageIndexPath, pageName };
}
};
Expand Down
37 changes: 37 additions & 0 deletions packages/material-engine/src/utils/hook.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
Loading

0 comments on commit 93464d3

Please sign in to comment.