├── packages ├── minapp-core │ ├── .gitignore │ ├── system.d.ts │ ├── .npmignore │ ├── system.js │ ├── src │ │ ├── util │ │ │ ├── index.ts │ │ │ ├── string.ts │ │ │ ├── warn.ts │ │ │ ├── pollute.ts │ │ │ └── mixin.ts │ │ ├── index.ts │ │ └── feat │ │ │ └── Location.ts │ ├── globals.d.ts │ ├── tsconfig.json │ └── package.json ├── minapp-wx │ └── README.md ├── minapp-vscode │ └── README.md ├── minapp-example-core-ts │ ├── src │ │ ├── pages │ │ │ ├── index │ │ │ │ ├── module2.wxs │ │ │ │ ├── inc.wxml │ │ │ │ ├── index.css │ │ │ │ ├── module1.wxs │ │ │ │ ├── index.cjson │ │ │ │ ├── index.wxml │ │ │ │ └── index.ts │ │ │ └── logs │ │ │ │ ├── logs.css │ │ │ │ ├── logs.cjson │ │ │ │ ├── logs.wxml │ │ │ │ └── logs.ts │ │ ├── images │ │ │ └── heart@3x.png │ │ ├── components │ │ │ └── counter │ │ │ │ ├── counter.css │ │ │ │ ├── counter.json │ │ │ │ ├── counter.wxml │ │ │ │ └── counter.ts │ │ ├── app.css │ │ ├── base │ │ │ ├── MyPage.ts │ │ │ ├── index.ts │ │ │ ├── MyComponent.ts │ │ │ └── MyApp.ts │ │ ├── app.cjson │ │ ├── project.config.json │ │ └── app.ts │ ├── minapp.cjson │ ├── webpack.minapp.js │ ├── package.json │ └── tsconfig.json ├── minapp-generator │ └── README.md ├── minapp-common │ ├── .npmignore │ ├── src │ │ ├── __tests__ │ │ │ ├── fixtures │ │ │ │ └── custom │ │ │ │ │ ├── attr-page.json │ │ │ │ │ ├── comp.json │ │ │ │ │ ├── test.json │ │ │ │ │ ├── using-comp.cjson │ │ │ │ │ ├── circle1.json │ │ │ │ │ ├── circle2.json │ │ │ │ │ ├── alias.json │ │ │ │ │ ├── attr.json │ │ │ │ │ ├── no.js │ │ │ │ │ └── comp.js │ │ │ └── custom.test.ts │ │ ├── dev │ │ │ ├── index.ts │ │ │ ├── Component.ts │ │ │ └── config.ts │ │ ├── index.ts │ │ ├── lib │ │ │ ├── index.ts │ │ │ ├── fs.ts │ │ │ ├── CacheableFile.ts │ │ │ └── ConditionalCacheableFile.ts │ │ └── hover.ts │ ├── tsconfig.json │ └── package.json ├── minapp-mobx │ ├── .npmignore │ ├── src │ │ ├── index.ts │ │ └── lib │ │ │ ├── MobxStore.ts │ │ │ ├── MobxApp.ts │ │ │ ├── MobxPage.ts │ │ │ ├── MobxComponent.ts │ │ │ └── pollute.ts │ ├── tsconfig.json │ └── package.json ├── minapp-wxml-parser │ ├── .npmignore │ ├── src │ │ ├── __tests__ │ │ │ ├── fixtures │ │ │ │ ├── b.xml │ │ │ │ ├── a.xml │ │ │ │ ├── b.json │ │ │ │ └── a.json │ │ │ └── debug.ts │ │ ├── config.ts │ │ └── index.ts │ ├── .vscode │ │ └── launch.json │ ├── tsconfig.json │ └── package.json ├── minapp-cli │ ├── common │ │ ├── Application │ │ │ ├── base │ │ │ │ ├── .gitignore.dtpl │ │ │ │ ├── .vscode │ │ │ │ │ └── extensions.json.dtpl │ │ │ │ ├── src │ │ │ │ │ ├── images │ │ │ │ │ │ └── heart@3x.png.dtpl │ │ │ │ │ ├── app.css.dtpl │ │ │ │ │ ├── app.cjson.dtpl │ │ │ │ │ └── project.config.json.dtpl │ │ │ │ ├── .npmignore.dtpl │ │ │ │ ├── .dtpl │ │ │ │ │ ├── page │ │ │ │ │ │ ├── $rawModuleName.$style.dtpl.dtpl │ │ │ │ │ │ ├── $rawModuleName.wxml.dtpl.dtpl │ │ │ │ │ │ └── $rawModuleName.cjson.dtpl.dtpl │ │ │ │ │ └── component │ │ │ │ │ │ ├── $rawModuleName.$style.dtpl.dtpl │ │ │ │ │ │ ├── $rawModuleName.wxml.dtpl.dtpl │ │ │ │ │ │ └── $rawModuleName.cjson.dtpl.dtpl │ │ │ │ ├── minapp.cjson.dtpl │ │ │ │ ├── README.md.dtpl │ │ │ │ └── webpack.minapp.js.dtpl │ │ │ ├── js │ │ │ │ ├── .dtpl │ │ │ │ │ ├── page │ │ │ │ │ │ └── $rawModuleName.js.dtpl.dtpl │ │ │ │ │ ├── component │ │ │ │ │ │ └── $rawModuleName.js.dtpl.dtpl │ │ │ │ │ └── dtpl.js.dtpl │ │ │ │ └── jsconfig.json.dtpl │ │ │ └── ts │ │ │ │ ├── .dtpl │ │ │ │ ├── page │ │ │ │ │ └── $rawModuleName.ts.dtpl.dtpl │ │ │ │ ├── component │ │ │ │ │ └── $rawModuleName.ts.dtpl.dtpl │ │ │ │ └── dtpl.js.dtpl │ │ │ │ └── tsconfig.json.dtpl │ │ └── Component │ │ │ ├── base │ │ │ ├── src │ │ │ │ └── res │ │ │ │ │ └── heart@3x.png.dtpl │ │ │ ├── README.md.dtpl │ │ │ └── minapp.json.dtpl │ │ │ ├── ts │ │ │ └── tsconfig.json.dtpl │ │ │ └── js │ │ │ └── jsconfig.json.dtpl │ ├── .npmignore │ ├── src │ │ ├── webpack │ │ │ ├── loader │ │ │ │ ├── README.md │ │ │ │ ├── pug-loader.ts │ │ │ │ ├── wxs-loader.ts │ │ │ │ └── json2sass-loader.ts │ │ │ ├── plugin │ │ │ │ ├── RemoveLessCache.ts │ │ │ │ └── WriteFile.ts │ │ │ ├── postcss │ │ │ │ └── px2rpx.ts │ │ │ └── index.ts │ │ ├── bin │ │ │ ├── minapp.ts │ │ │ ├── base.ts │ │ │ ├── minapp-clear.ts │ │ │ ├── minapp-build.ts │ │ │ ├── minapp-attrs.ts │ │ │ ├── minapp-dev.ts │ │ │ └── minapp-.ts │ │ └── config │ │ │ └── local.ts │ └── tsconfig.json ├── minapp-example-core-js │ ├── src │ │ ├── pages │ │ │ ├── index │ │ │ │ ├── inc.wxml │ │ │ │ ├── index.css │ │ │ │ ├── index.cjson │ │ │ │ ├── index.wxml │ │ │ │ └── index.js │ │ │ └── logs │ │ │ │ ├── logs.css │ │ │ │ ├── logs.cjson │ │ │ │ ├── logs.wxml │ │ │ │ └── logs.js │ │ ├── images │ │ │ └── heart@3x.png │ │ ├── components │ │ │ └── counter │ │ │ │ ├── counter.css │ │ │ │ ├── counter.json │ │ │ │ ├── counter.wxml │ │ │ │ └── counter.js │ │ ├── app.css │ │ ├── base │ │ │ ├── MyApp.js │ │ │ ├── MyPage.js │ │ │ ├── MyComponent.js │ │ │ └── index.js │ │ ├── app.cjson │ │ ├── project.config.json │ │ └── app.js │ ├── minapp.cjson │ ├── package.json │ └── jsconfig.json ├── minapp-example-mobx-js │ ├── src │ │ ├── pages │ │ │ ├── index │ │ │ │ ├── inc.wxml │ │ │ │ ├── index.cjson │ │ │ │ ├── index.css │ │ │ │ ├── index.wxml │ │ │ │ └── index.js │ │ │ └── logs │ │ │ │ ├── logs.css │ │ │ │ ├── logs.cjson │ │ │ │ ├── logs.wxml │ │ │ │ └── logs.js │ │ ├── components │ │ │ └── counter │ │ │ │ ├── counter.css │ │ │ │ ├── counter.cjson │ │ │ │ ├── counter.wxml │ │ │ │ └── counter.js │ │ ├── images │ │ │ └── heart@3x.png │ │ ├── app.css │ │ ├── base │ │ │ ├── MyApp.js │ │ │ ├── MyPage.js │ │ │ ├── MyComponent.js │ │ │ ├── index.js │ │ │ └── MyStore.js │ │ ├── app.cjson │ │ ├── project.config.json │ │ └── app.js │ ├── package.json │ └── jsconfig.json └── minapp-example-mobx-ts │ ├── src │ ├── pages │ │ ├── index │ │ │ ├── inc.wxml │ │ │ ├── index.cjson │ │ │ ├── index.css │ │ │ ├── index.wxml │ │ │ └── index.ts │ │ └── logs │ │ │ ├── logs.css │ │ │ ├── logs.cjson │ │ │ ├── logs.wxml │ │ │ └── logs.ts │ ├── components │ │ └── counter │ │ │ ├── counter.css │ │ │ ├── counter.json │ │ │ ├── counter.wxml │ │ │ └── counter.ts │ ├── images │ │ └── heart@3x.png │ ├── app.css │ ├── base │ │ ├── index.ts │ │ ├── MyPage.ts │ │ ├── MyComponent.ts │ │ ├── MyStore.ts │ │ └── MyApp.ts │ ├── app.cjson │ ├── project.config.json │ └── app.ts │ ├── .vscode │ └── extensions.json │ ├── .dtpl │ ├── page │ │ ├── $rawModuleName.$style.dtpl │ │ ├── $rawModuleName.wxml.dtpl │ │ ├── $rawModuleName.cjson.dtpl │ │ └── $rawModuleName.ts.dtpl │ ├── component │ │ ├── $rawModuleName.$style.dtpl │ │ ├── $rawModuleName.wxml.dtpl │ │ ├── $rawModuleName.cjson.dtpl │ │ └── $rawModuleName.ts.dtpl │ └── dtpl.js │ ├── package.json │ └── tsconfig.json ├── docs-md ├── doc-develop-npm-component.md ├── api-index.md ├── api-core-Location.md ├── doc-unit-in-style.md ├── doc-about-json-file.md ├── doc-attention-on-build.md ├── api-core-Url.md ├── doc-require-other-files-in-script.md ├── api-mobx-MobxStore.md ├── doc-install.md ├── api-mobx-MobxComponent.md ├── api-mobx-MobxApp.md ├── api-mobx-MobxPage.md ├── doc-coding-rule.md ├── doc-difference-with-wepy.md ├── doc-about-component.md ├── doc-warn.md ├── doc-use-setDataSmart-not-setData.md ├── doc-how-to-use-wxp-in-other-project.md ├── api-core-BaseApp.md ├── api-core-BasePage.md ├── api-core-BaseComponent.md ├── doc-data-bind.md ├── api-core-wxp.md ├── doc-about-page.md ├── doc-basic-code.md └── doc-custom-webpack.md ├── res └── logo.sketch ├── docs └── img │ ├── favicon.png │ ├── feature-complete.svg │ ├── feature-webpack.svg │ ├── feature-js.svg │ └── language.svg ├── website ├── static │ ├── img │ │ ├── favicon.png │ │ ├── feature-complete.svg │ │ ├── feature-webpack.svg │ │ └── feature-js.svg │ └── css │ │ └── custom.css ├── .gitignore ├── package.json ├── blog │ ├── 2018-03-09-redefine-3.md │ └── 2018-03-05-redefine-2.md ├── sidebars.json ├── pages │ └── en │ │ └── users.js └── i18n │ └── en.json ├── .gitignore ├── website.code-workspace ├── .dtpl ├── file │ ├── new.dtpl │ ├── modify-api.ts.dtpl │ └── modify-tpl.ts.dtpl └── dtpl.ts ├── .vscode └── settings.json ├── .gitmessage ├── lerna.json ├── package.json ├── minapp.code-workspace ├── tslint.json └── schema ├── page.json └── component.json /packages/minapp-core/.gitignore: -------------------------------------------------------------------------------- 1 | system.bundle.* 2 | -------------------------------------------------------------------------------- /docs-md/doc-develop-npm-component.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 组件化开发实战 3 | --- 4 | 5 | -------------------------------------------------------------------------------- /packages/minapp-wx/README.md: -------------------------------------------------------------------------------- 1 | 此库所有数据迁移到了 https://github.com/wx-minapp/minapp-wx 2 | -------------------------------------------------------------------------------- /res/logo.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/res/logo.sketch -------------------------------------------------------------------------------- /docs/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/docs/img/favicon.png -------------------------------------------------------------------------------- /packages/minapp-vscode/README.md: -------------------------------------------------------------------------------- 1 | 此库所有数据迁移到了 https://github.com/wx-minapp/minapp-vscode 2 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/module2.wxs: -------------------------------------------------------------------------------- 1 | module.exports.msg = 'module2' 2 | -------------------------------------------------------------------------------- /packages/minapp-generator/README.md: -------------------------------------------------------------------------------- 1 | 此库所有数据迁移到了 https://github.com/wx-minapp/minapp-generator 2 | -------------------------------------------------------------------------------- /packages/minapp-core/system.d.ts: -------------------------------------------------------------------------------- 1 | export * from './dist/' 2 | export {wxp} from '@minapp/wx/wxp' 3 | -------------------------------------------------------------------------------- /packages/minapp-common/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tslint.json 3 | src 4 | vendor 5 | coverage 6 | __tests__ 7 | -------------------------------------------------------------------------------- /packages/minapp-mobx/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tslint.json 3 | src 4 | vendor 5 | coverage 6 | __tests__ 7 | -------------------------------------------------------------------------------- /website/static/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/website/static/img/favicon.png -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tslint.json 3 | src 4 | vendor 5 | coverage 6 | __tests__ 7 | -------------------------------------------------------------------------------- /packages/minapp-core/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tslint.json 3 | src 4 | scripts 5 | vendor 6 | coverage 7 | __tests__ 8 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.gitignore.dtpl: -------------------------------------------------------------------------------- 1 | *.log 2 | dist 3 | .cache 4 | vendor 5 | node_modules 6 | coverage 7 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/index/inc.wxml: -------------------------------------------------------------------------------- 1 | 2 | 我是来自 inc.wxml 中的文字 3 | 4 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/inc.wxml: -------------------------------------------------------------------------------- 1 | 2 | 我是来自 inc.wxml 中的文字 3 | 4 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/index/inc.wxml: -------------------------------------------------------------------------------- 1 | 2 | 我是来自 inc.wxml 中的文字 3 | 4 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/index/inc.wxml: -------------------------------------------------------------------------------- 1 | 2 | 我是来自 inc.wxml 中的文字 3 | 4 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/components/counter/counter.css: -------------------------------------------------------------------------------- 1 | .counter { 2 | border: 1px solid wheat; 3 | color: aqua; 4 | } 5 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/components/counter/counter.css: -------------------------------------------------------------------------------- 1 | .counter { 2 | border: 1px solid wheat; 3 | color: aqua; 4 | } 5 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/attr-page.json: -------------------------------------------------------------------------------- 1 | { 2 | "usingComponents": { 3 | "attr": "./attr.json" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/images/heart@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/packages/minapp-example-core-js/src/images/heart@3x.png -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/images/heart@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/packages/minapp-example-core-ts/src/images/heart@3x.png -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/images/heart@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/packages/minapp-example-mobx-js/src/images/heart@3x.png -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/images/heart@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/packages/minapp-example-mobx-ts/src/images/heart@3x.png -------------------------------------------------------------------------------- /packages/minapp-cli/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tslint.json 3 | src 4 | !template/*/src 5 | !common/**/src 6 | gen 7 | vendor 8 | coverage 9 | __tests__ 10 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/loader/README.md: -------------------------------------------------------------------------------- 1 | ## 这里的 loader 要将源代码化分成两个部分: 2 | 3 | 1. extract 的部分(这里需要修证 require) 4 | 2. 继续留给 webpack 处理的部分 (这里主要就是 require 语句) 5 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/comp.json: -------------------------------------------------------------------------------- 1 | { 2 | "minapp": { 3 | "component": { 4 | "desc": ["test desc"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "minapp": { 3 | "component": { 4 | "desc": ["this is test"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "qiu8310.dot-template-vscode", 4 | "qiu8310.minapp-vscode" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.vscode/extensions.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "qiu8310.dot-template-vscode", 4 | "qiu8310.minapp-vscode" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Component/base/src/res/heart@3x.png.dtpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/packages/minapp-cli/common/Component/base/src/res/heart@3x.png.dtpl -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/components/counter/counter.css: -------------------------------------------------------------------------------- 1 | .counter { 2 | width: 400px; 3 | border: 1px solid wheat; 4 | color: aqua; 5 | background-color: whitesmoke; 6 | } 7 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/index/index.css: -------------------------------------------------------------------------------- 1 | .usermotto { 2 | margin-top: 20px; 3 | } 4 | 5 | .inc { 6 | margin-top: 40px; 7 | text-align: center; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/logs/logs.css: -------------------------------------------------------------------------------- 1 | .log-list { 2 | display: flex; 3 | flex-direction: column; 4 | padding: 40px; 5 | } 6 | .log-item { 7 | margin: 10px; 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/components/counter/counter.css: -------------------------------------------------------------------------------- 1 | .counter { 2 | width: 400px; 3 | border: 1px solid wheat; 4 | color: aqua; 5 | background-color: whitesmoke; 6 | } 7 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/index.css: -------------------------------------------------------------------------------- 1 | .usermotto { 2 | margin-top: 20px; 3 | } 4 | 5 | .inc { 6 | margin-top: 40px; 7 | text-align: center; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/logs/logs.css: -------------------------------------------------------------------------------- 1 | .log-list { 2 | display: flex; 3 | flex-direction: column; 4 | padding: 40px; 5 | } 6 | .log-item { 7 | margin: 10px; 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/logs/logs.css: -------------------------------------------------------------------------------- 1 | .log-list { 2 | display: flex; 3 | flex-direction: column; 4 | padding: 40px; 5 | } 6 | .log-item { 7 | margin: 10px; 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/logs/logs.css: -------------------------------------------------------------------------------- 1 | .log-list { 2 | display: flex; 3 | flex-direction: column; 4 | padding: 40px; 5 | } 6 | .log-item { 7 | margin: 10px; 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/src/images/heart@3x.png.dtpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiu8310/minapp/HEAD/packages/minapp-cli/common/Application/base/src/images/heart@3x.png.dtpl -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/using-comp.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "usingComponents": { 3 | "comp": "./comp.js", 4 | "no": "./no", 5 | "xx": "./xx_not_exists" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/logs/logs.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "navigationBarTitleText": "查看启动日志" 4 | } 5 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/logs/logs.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "navigationBarTitleText": "查看启动日志" 4 | } 5 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/logs/logs.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "navigationBarTitleText": "查看启动日志" 4 | } 5 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/page/$rawModuleName.$style.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/page/${dollar}rawModuleName.${dollar}style.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意:文件为空,编译时不会生成新文件 5 | */ 6 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/logs/logs.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "navigationBarTitleText": "查看启动日志" 4 | } 5 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.npmignore.dtpl: -------------------------------------------------------------------------------- 1 | *.log 2 | .cache 3 | vendor 4 | node_modules 5 | coverage 6 | 7 | tsconfig.json 8 | jsconfig.json 9 | .gitignore 10 | .dtpl 11 | src 12 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/circle1.json: -------------------------------------------------------------------------------- 1 | { 2 | "component": { 3 | "desc": ["circle1"] 4 | }, 5 | "usingComponents": { 6 | "circle2": "./circle2.json" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/circle2.json: -------------------------------------------------------------------------------- 1 | { 2 | "component": { 3 | "desc": ["circle2"] 4 | }, 5 | "usingComponents": { 6 | "circle1": "./circle1.json" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/alias.json: -------------------------------------------------------------------------------- 1 | { 2 | "usingComponents": { 3 | "comp": "./comp.js", 4 | "comp2": "/custom/test.json", 5 | "comp3": "~/custom/no.js" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/component/$rawModuleName.$style.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/component/${dollar}rawModuleName.${dollar}style.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意:文件为空,编译时不会生成新文件 5 | */ 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | dist 3 | .cache 4 | .dtpl/dtpl.js 5 | vendor 6 | node_modules 7 | coverage 8 | packages/minapp-cli/template 9 | package-lock.json 10 | yarn.lock 11 | ../.DS_Store 12 | .DS_Store 13 | 14 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/minapp.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../schema/minapp.json", 3 | "compiler": { 4 | "unitTransformer": { 5 | "px": "rpx", 6 | "rpx": "px" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/minapp.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../schema/minapp.json", 3 | "compiler": { 4 | "unitTransformer": { 5 | "px": "rpx", 6 | "rpx": "px" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /website.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "website" 5 | }, 6 | { 7 | "path": "docs-md" 8 | } 9 | ], 10 | "settings": { 11 | "git.decorations.enabled": false 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.dtpl/page/$rawModuleName.$style.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/component/${ref.dollar}rawModuleName.${ref.dollar}style.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意:文件为空,编译时不会生成新文件 5 | */ 6 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/components/counter/counter.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/component.json", 3 | "component": true, 4 | "usingComponents": {} 5 | } 6 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/components/counter/counter.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/component.json", 3 | "component": true, 4 | "usingComponents": {} 5 | } 6 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/components/counter/counter.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/component.json", 3 | "component": true, 4 | "usingComponents": {} 5 | } 6 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/components/counter/counter.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/component.json", 3 | "component": true, 4 | "usingComponents": {} 5 | } 6 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.dtpl/component/$rawModuleName.$style.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/component/${ref.dollar}rawModuleName.${ref.dollar}style.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意:文件为空,编译时不会生成新文件 5 | */ 6 | -------------------------------------------------------------------------------- /packages/minapp-core/system.js: -------------------------------------------------------------------------------- 1 | Object.defineProperty(exports, "__esModule", { value: true }) 2 | var tslib_1 = require("tslib") 3 | tslib_1.__exportStar(require("./dist/"), exports) 4 | 5 | exports.wxp = require("@minapp/wx/wxp").wxp 6 | -------------------------------------------------------------------------------- /docs-md/api-index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 说明 3 | --- 4 | 5 | 6 | > 注意: api 文档可能和你本地使用的版本不一致,而且 @minapp/core 和 @minapp/mobx 几乎没有提供什么额外的 api, 7 | > 并且几乎所有相关接口都有自动补全,所以一切以你系统的自动补全的接口为准 8 | > 9 | > 同时建议使用 TypeScript 来开发 minapp 项目 10 | 11 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/attr.json: -------------------------------------------------------------------------------- 1 | { 2 | "minapp": { 3 | "component": { 4 | "attrs": [ 5 | {"name": "foo"}, 6 | {"name": "bindclick"} 7 | ] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Component/base/README.md.dtpl: -------------------------------------------------------------------------------- 1 | # To Developer 2 | 3 | ## 没有用 .npmignore 4 | 5 | 所有要发布的文件指定在 `package.json` 中的 `files` 字段中 6 | 7 | 8 | ## minapp.json 9 | 10 | 这是 minapp 的配置文件,用于配置编译相关的选项;详情可以查看 json 中的自动提醒 11 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | lib/core/metadata.js 4 | lib/core/MetadataBlog.js 5 | website/translated_docs 6 | website/build/ 7 | website/yarn.lock 8 | website/node_modules 9 | 10 | website/i18n/* 11 | !website/i18n/en.json 12 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/app.css: -------------------------------------------------------------------------------- 1 | .container { 2 | height: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | justify-content: space-between; 7 | padding: 50px 0; 8 | box-sizing: border-box; 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/app.css: -------------------------------------------------------------------------------- 1 | .container { 2 | height: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | justify-content: space-between; 7 | padding: 50px 0; 8 | box-sizing: border-box; 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/app.css: -------------------------------------------------------------------------------- 1 | .container { 2 | height: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | justify-content: space-between; 7 | padding: 10px 0; 8 | box-sizing: border-box; 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/app.css: -------------------------------------------------------------------------------- 1 | .container { 2 | height: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | justify-content: space-between; 7 | padding: 50px 0; 8 | box-sizing: border-box; 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/src/app.css.dtpl: -------------------------------------------------------------------------------- 1 | .container { 2 | height: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | justify-content: space-between; 7 | padding: 50px 0; 8 | box-sizing: border-box; 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/components/counter/counter.wxml: -------------------------------------------------------------------------------- 1 | 2 | 当前值:{{start}} 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/page/$rawModuleName.wxml.dtpl: -------------------------------------------------------------------------------- 1 | 7 | 8 | page: $rawModuleName 9 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/components/counter/counter.wxml: -------------------------------------------------------------------------------- 1 | 2 | 子组件值:{{number}} 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/logs/logs.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/logs/logs.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/logs/logs.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/logs/logs.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | -------------------------------------------------------------------------------- /.dtpl/file/new.dtpl: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/module1.wxs: -------------------------------------------------------------------------------- 1 | /** 2 | * wxs 模块默认使用 babel 编译,但要注意: 3 | * 4 | * 小程序 wxs 中并没有 exports 变量,只有 module 变量, 5 | * 所以在写代码时需要避免直接使用 exports 6 | */ 7 | 8 | const exp = module.exports 9 | 10 | exp.msg = 'module1 ' + require('./module2.wxs').msg 11 | 12 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/component/$rawModuleName.wxml.dtpl: -------------------------------------------------------------------------------- 1 | 7 | 8 | component: $rawModuleName 9 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dot-template-vscode.debug": false, 3 | "files.exclude": { 4 | "*.code-workspace": true, 5 | "**/packages": true, 6 | "**/.git": true, 7 | "**/.svn": true, 8 | "**/.hg": true, 9 | "**/CVS": true, 10 | "**/.DS_Store": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.dtpl/page/$rawModuleName.wxml.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | 7 | 8 | page: $rawModuleName 9 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/components/counter/counter.wxml: -------------------------------------------------------------------------------- 1 | 2 | 子组件Count:{{number}} 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/components/counter/counter.wxml: -------------------------------------------------------------------------------- 1 | 2 | 子组件Count:{{number}} 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/index/index.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "usingComponents": { 4 | "counter": "components/counter/counter", 5 | "demo": "@minapp/component-demo" // 这个组件是 node_modules 中的组件 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/index.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "usingComponents": { 4 | "counter": "components/counter/counter", 5 | "demo": "@minapp/component-demo" // 这个组件是 node_modules 中的组件 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.gitmessage: -------------------------------------------------------------------------------- 1 | 2 | 3 | # (): 4 | # 5 | # Git Commit Message Guides: http://chris.beams.io/posts/git-commit/ 6 | # 7 | # Type keywrods: feat, fix, docs, style, refactor, perf, test, chore, revert 8 | # Changelog keywrods: Added, Changed, Breaks, Deprecated, Removed, Fixed, Security 9 | # 10 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.dtpl/component/$rawModuleName.wxml.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | 7 | 8 | component: $rawModuleName 9 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/__tests__/fixtures/b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | 1 8 | 2 9 | 10 | 11 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/no.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/fixtures/custom/comp.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | -------------------------------------------------------------------------------- /docs-md/api-core-Location.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Location 3 | --- 4 | 5 | 6 | * **pathname** 7 | 8 | 当前的 url 地址,不带参数 9 | 10 | * **query** 11 | 12 | 类型: `{[key: string]: string}` 13 | 14 | 默认值: `{}` 15 | 16 | 当前的 query 参数 17 | 18 | > 源代码: [Location.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-core/src/feat/Location.ts) 19 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/index/index.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "usingComponents": { 4 | "counter-a": "/components/counter/counter", 5 | "counter-b": "/components/counter/counter", 6 | "toast": "~/@minapp/component-toast" // 加载 npm 包中的组件 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/config.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export const SourceTags = ['wxs'] 7 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/page/$rawModuleName.cjson.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/page/${dollar}rawModuleName.cjson.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意: 5 | 1. cjson 是支持注释的 json 文件(可以在你的编辑器里配置文件关联) 6 | 2. 文件为空,编译时不会生成新文件 7 | */ 8 | 9 | { 10 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json" 11 | } 12 | -------------------------------------------------------------------------------- /docs-md/doc-unit-in-style.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 样式中的单位 3 | --- 4 | 5 | 由于微信小程序中支持 `rpx` 单位 6 | 7 | ``` 8 | 新增了尺寸单位。在写 CSS 样式时,开发者需要考虑到手机设备的屏幕会有不同的宽度和设备像素比, 9 | 采用一些技巧来换算一些像素单位。WXSS 在底层支持新的尺寸单位 rpx ,开发者可以免去换算的烦恼, 10 | 只要交给小程序底层来换算即可,由于换算采用的浮点数运算,所以运算结果会和预期结果有一点点偏差 11 | ``` 12 | 13 | 而原生的 css 并不支持此单位,所以为了开发方便,minapp 会默认把所有 `px` 转化成 `rpx` 单位,而把所有的 `rpx` 单位转化成 `px` 14 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.dtpl/page/$rawModuleName.cjson.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/page/${ref.dollar}rawModuleName.cjson.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意: 5 | 1. cjson 是支持注释的 json 文件(可以在你的编辑器里配置文件关联) 6 | 2. 文件为空,编译时不会生成新文件 7 | */ 8 | 9 | { 10 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json" 11 | } 12 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/page/$rawModuleName.ts.dtpl: -------------------------------------------------------------------------------- 1 | // 此文件是由模板文件 ".dtpl/page/${dollar}rawModuleName.ts.dtpl" 生成的,你可以自行修改模板 2 | 3 | import {pagify, MyPage, wxp} from 'base/' 4 | 5 | @pagify() 6 | export default class extends MyPage { 7 | data = { 8 | 9 | } 10 | 11 | async onLoad(options: any) { 12 | console.log(await wxp.getUserInfo()) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docs-md/doc-about-json-file.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 关于 json 文件 3 | --- 4 | 5 | 默认情况下,`minapp init` 生成的 json 文件的后缀都是 `.cjson` 文件,你的编辑器不一定支持。 6 | 7 | 这类文件表示**支持注释的 json 文件**,即你可以在文件中任意使用 `/* */` 或 `//` 注释,minapp 中的所有 json 文件都支持注释。 8 | 9 | 在 vscode 中你可以将 `.cjson` 后缀的文件关联到 `JSON with Comments` 文件类型,如下图所示: 10 | 11 | ![](//n1image.hjfile.cn/res7/2018/03/02/37c960c0cd965dbe53a07e1366c3836c.gif) 12 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/js/.dtpl/page/$rawModuleName.js.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | // 此文件是由模板文件 ".dtpl/page/${ref.dollar}rawModuleName.js.dtpl" 生成的,你可以自行修改模板 2 | 3 | import {pagify, MyPage, wxp} from 'base/' 4 | 5 | @pagify() 6 | export default class extends MyPage { 7 | data = { 8 | 9 | } 10 | 11 | async onLoad(options) { 12 | console.log(await wxp.getUserInfo()) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/ts/.dtpl/page/$rawModuleName.ts.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | // 此文件是由模板文件 ".dtpl/page/${ref.dollar}rawModuleName.ts.dtpl" 生成的,你可以自行修改模板 2 | 3 | import {pagify, MyPage, wxp} from 'base/' 4 | 5 | @pagify() 6 | export default class extends MyPage { 7 | data = { 8 | 9 | } 10 | 11 | async onLoad(options: any) { 12 | console.log(await wxp.getUserInfo()) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/component/$rawModuleName.cjson.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/component/${dollar}rawModuleName.cjson.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意: 5 | 1. cjson 是支持注释的 json 文件(可以在你的编辑器里配置文件关联) 6 | 2. 文件为空,编译时不会生成新文件 7 | */ 8 | 9 | { 10 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/component.json", 11 | "component": true 12 | } 13 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/index/index.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/page.json", 3 | "usingComponents": { 4 | "demo": "@minapp/component-demo", 5 | "counter-a": "components/counter/counter", 6 | "counter-b": "components/counter/counter", 7 | "toast": "@minapp/component-toast" // 加载 npm 包中的组件 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/minapp-common/src/dev/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './Component' 7 | export * from './components' 8 | export * from './config' 9 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './logParserError' 7 | export * from './parser' 8 | export * from './structs' 9 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/.dtpl/component/$rawModuleName.cjson.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | /* 2 | 此文件是由模板文件 ".dtpl/component/${ref.dollar}rawModuleName.cjson.dtpl" 生成的,你可以自行修改模板 3 | 4 | 注意: 5 | 1. cjson 是支持注释的 json 文件(可以在你的编辑器里配置文件关联) 6 | 2. 文件为空,编译时不会生成新文件 7 | */ 8 | 9 | { 10 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/component.json", 11 | "component": true 12 | } 13 | -------------------------------------------------------------------------------- /packages/minapp-common/src/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './dev/Component' 7 | export * from './autocomplete' 8 | export * from './hover' 9 | 10 | -------------------------------------------------------------------------------- /packages/minapp-common/src/lib/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './fs' 7 | export * from './CacheableFile' 8 | export * from './ConditionalCacheableFile' 9 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "2.7.1", 3 | "command": { 4 | "publish": { 5 | "ignoreChanges": [ 6 | "*.md", 7 | "**/__tests__/**" 8 | ], 9 | "bootstrap": { 10 | "ignore": [ 11 | "@minapp/example-*", 12 | "@minapp/component-*" 13 | ] 14 | } 15 | } 16 | }, 17 | "packages": [ 18 | "packages/*" 19 | ], 20 | "version": "2.2.2" 21 | } 22 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/base/MyApp.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {BaseApp} from '@minapp/core' 7 | 8 | export class MyApp extends BaseApp { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/base/MyApp.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxApp} from '@minapp/mobx' 7 | 8 | export class MyApp extends MobxApp { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/base/MyPage.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {BasePage} from '@minapp/core' 7 | 8 | export class MyPage extends BasePage { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/base/MyPage.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxPage} from '@minapp/mobx' 7 | 8 | export class MyPage extends MobxPage { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /docs-md/doc-attention-on-build.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 编译时的注意事项 3 | --- 4 | 5 | 小程序的样式文件中不允许使用本地图片资源,所以在使用 `minapp build` 时, 6 | 如果样式中有本地资源,编译程序会报错,如果没有,则能顺利编译通过;如果一定 7 | 要在样式中用本地资源的话,请使用 `minapp build --publicPath "http://xxx.com/xxx"` 8 | 指定一个 `publicPath`,编译后静态文件全会在 `dist/static` 目录下,你 9 | 只需要把这些静态文件上传到你指定的那个服务器就行了。 10 | 11 | ### 为什么 `minapp dev` 时不需要使用 `publicPath`? 12 | 13 | 因为 dev 环境中内置了一个服务器,静态资源都会在服务器中,即 `publicPath` 自动指定成了那个内置的服务器的路径。 14 | -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "examples": "docusaurus-examples", 4 | "dev": "docusaurus-start", 5 | "build": "docusaurus-build", 6 | "publish-gh-pages": "docusaurus-publish", 7 | "write-translations": "docusaurus-write-translations", 8 | "version": "docusaurus-version", 9 | "rename-version": "docusaurus-rename-version" 10 | }, 11 | "devDependencies": { 12 | "docusaurus": "^1.0.7" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/base/MyComponent.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {BaseComponent} from '@minapp/core' 7 | 8 | export class MyComponent extends BaseComponent { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/base/MyComponent.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxComponent} from '@minapp/mobx' 7 | 8 | export class MyComponent extends MobxComponent { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /website/blog/2018-03-09-redefine-3.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 重新定义小程序开发 — 编译篇 3 | author: Mora 4 | authorURL: https://github.com/qiu8310 5 | --- 6 | 7 | 用 `@minapp/core` 开发的框架,可以用 `@minapp/cli` 来编译, 8 | 甚至任何原生的微信小程序都可以用 `@minapp/cli` 来编译。 9 | 10 | 11 | 12 | 其实编译功能并不是真正写在 `@minapp/cli` 组件中,`@minapp/cli` 只是引入了 `@minapp/compiler` 组件。 13 | 所以所有的编译相关的代码都是 `@minapp/compiler` 项目中。 14 | 15 | 而 `@minapp/compiler` 完全就是一个 `webpack` 配置项目。 16 | 17 | > 未完待续... 18 | -------------------------------------------------------------------------------- /packages/minapp-core/src/util/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './mixin' 7 | export * from './object' 8 | export * from './pollute' 9 | export * from './string' 10 | export * from './warn' 11 | -------------------------------------------------------------------------------- /docs-md/api-core-Url.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Url 3 | --- 4 | 5 | * **go(searchOrQuery?)** 6 | 7 | 跳转当前 url 所指定的页面,会自动根据当前 url 是否是 tabBar 来决定调用 `wx.switchTab` 还是 `wx.navigateTo` 8 | 9 | * **redirect(searchOrQuery?)** 10 | 11 | 重定向到当前 url 所指定的页面 12 | 13 | 注意:当页面是 tabBar 时,无法使用此函数 14 | 15 | * **reload(searchOrQuery?)** 16 | 17 | 关闭所有页面,打开到应用内的某个页面 18 | 19 | 20 | > 源代码: [Url.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-core/src/feat/Url.ts) 21 | -------------------------------------------------------------------------------- /docs-md/doc-require-other-files-in-script.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 在脚本中 require 其它文件 3 | --- 4 | 5 | 像你用 webpack 开发 web 程序一样,图片文件路径不能直接写在 js 或 ts 中,需要使用 require 来引用,如: `require("path/to/image.png")` 6 | 7 | 另外,为了方便复用 json 文件,你也可以直接在 js 或 ts 中 require json 文件,如 `require("path/to/some.json")`; 8 | 通过这种方式 require 进的 json 会全部导入到文件中,可能有时你只需要 json 中的某个字段,这时你可以在文件后面加上字段的参数,如 9 | 现在需要取出 app.json 文件中的 tabBar 中的 list 字段,可以这样用 `require("./app.json?tabBar.list")`,如果这个字段 10 | 不存在,会返回 `undefined`。 11 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/base/MyPage.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {BasePage} from '@minapp/core' 7 | import {MyApp} from './MyApp' 8 | 9 | export class MyPage extends BasePage { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /packages/minapp-core/src/util/string.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | /** 7 | * 将 str 转化成 camelCase 8 | */ 9 | export function camelCase(str: string) { 10 | return str.replace(/[-_](\w)/g, (r, k: string) => k.toUpperCase()) 11 | } 12 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/base/index.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './MyApp' 7 | export * from './MyPage' 8 | export * from './MyComponent' 9 | 10 | export {wxp, pagify, appify, comify} from '@minapp/core' 11 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/base/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './MyApp' 7 | export * from './MyPage' 8 | export * from './MyComponent' 9 | 10 | export {wxp, pagify, appify, comify} from '@minapp/core' 11 | -------------------------------------------------------------------------------- /packages/minapp-mobx/src/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export {wxp} from '@minapp/core' 7 | export * from './lib/MobxApp' 8 | export * from './lib/MobxPage' 9 | export * from './lib/MobxComponent' 10 | export * from './lib/MobxStore' 11 | -------------------------------------------------------------------------------- /packages/minapp-mobx/src/lib/MobxStore.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {observable} from 'mobx' 7 | 8 | export class MobxStore { 9 | // @ts-ignore 10 | @observable private __MOBX__ = true // mobx autorun 中需要有取值的操作,才会触发监听 11 | } 12 | -------------------------------------------------------------------------------- /.dtpl/file/modify-api.ts.dtpl: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {ApiModifier, TemplateMeta} from '../..' 7 | 8 | export default class extends ApiModifier { 9 | modify($root: Cheerio): TemplateMeta[] { 10 | return [] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.dtpl/file/modify-tpl.ts.dtpl: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {TplModifier, TemplateMeta} from '../..' 7 | 8 | export default class extends TplModifier { 9 | modify($root: Cheerio): TemplateMeta[] { 10 | return [] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/minapp.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /****************************************************************** 4 | MIT License http://www.opensource.org/licenses/mit-license.php 5 | Author Mora (https://github.com/qiu8310) 6 | *******************************************************************/ 7 | 8 | if (require('import-local')(__filename)) { 9 | console.log('Using local version of @minapp/cli'); 10 | } else { 11 | require('./minapp-') 12 | } 13 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/base/MyComponent.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MyApp} from './MyApp' 7 | import {BaseComponent} from '@minapp/core' 8 | 9 | export class MyComponent extends BaseComponent { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/base/index.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './MyStore' 7 | export * from './MyApp' 8 | export * from './MyPage' 9 | export * from './MyComponent' 10 | 11 | export {wxp, pagify, appify, comify} from '@minapp/mobx' 12 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/base/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | export * from './MyStore' 7 | export * from './MyApp' 8 | export * from './MyPage' 9 | export * from './MyComponent' 10 | 11 | export {wxp, pagify, appify, comify} from '@minapp/mobx' 12 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/index/index.css: -------------------------------------------------------------------------------- 1 | .userinfo { 2 | display: flex; 3 | flex-direction: column; 4 | align-items: center; 5 | } 6 | 7 | .userinfo-avatar { 8 | width: 50px; 9 | height: 50px; 10 | margin: 20px; 11 | border-radius: 50%; 12 | } 13 | 14 | .userinfo-nickname { 15 | color: #aaa; 16 | background-image: url("images/heart@3x.png"); 17 | } 18 | 19 | .usermotto { 20 | margin-top: 10px; 21 | } 22 | 23 | .inc { 24 | margin-top: 40px; 25 | text-align: center; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/index/index.css: -------------------------------------------------------------------------------- 1 | .userinfo { 2 | display: flex; 3 | flex-direction: column; 4 | align-items: center; 5 | } 6 | 7 | .userinfo-avatar { 8 | width: 128px; 9 | height: 128px; 10 | margin: 20px; 11 | border-radius: 50%; 12 | } 13 | 14 | .userinfo-nickname { 15 | color: #aaa; 16 | background-image: url("images/heart@3x.png"); 17 | } 18 | 19 | .usermotto { 20 | margin-top: 100x; 21 | } 22 | 23 | .inc { 24 | margin-top: 40px; 25 | text-align: center; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/base/MyPage.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxPage} from '@minapp/mobx' 7 | import {MyStore} from './MyStore' 8 | import {MyApp} from './MyApp' 9 | 10 | export class MyPage extends MobxPage { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /packages/minapp-core/src/util/warn.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | let warn: (...args: any[]) => void 7 | 8 | if (__ENV__ === 'production') { 9 | warn = (...args: any[]) => {} 10 | } else { 11 | warn = (...args: any[]) => console.warn(...args) 12 | } 13 | 14 | export {warn} 15 | -------------------------------------------------------------------------------- /docs-md/api-mobx-MobxStore.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: MobxStore 3 | --- 4 | 5 | 自定义的 Store 必须继承 `@minapp/mobx` 中的 MobxStore,否则组件有可能不会更新 6 | 7 | 其它用法和 mobx 一致,可以[查看 mobx 的官方文档](https://mobx.js.org/) 8 | 9 | 10 | ### Example: 11 | 12 | ```js 13 | import {MobxStore} from '@minapp/mobx' 14 | import {observable} from 'mobx' 15 | 16 | export class MyStore extends MobxStore { 17 | @observable userInfo = null 18 | } 19 | ``` 20 | 21 | 22 | > 源代码: [MobxStore.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-mobx/src/lib/MobxStore.ts) 23 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Component/base/minapp.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/minapp.json", 3 | "component": "src/${name}", 4 | "compiler": { 5 | /* 6 | 将 px 转化成 rpx,同时将 rpx 转化成 px 7 | 8 | 如果需要将 1px 转化成 2rpx,可以设置成 {"px": "2rpx"} 9 | 如果需要将 2px 转化成 1rpx,可以设置成 {"px": "0.5rpx"} 10 | 你还可以设置其它任何单位的转化 11 | 12 | **注:左边的单位一定不能带任何数字** 13 | */ 14 | "unitTransformer": { 15 | "px": "rpx", 16 | "rpx": "px" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/base/MyComponent.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxComponent} from '@minapp/mobx' 7 | import {MyStore} from './MyStore' 8 | import {MyApp} from './MyApp' 9 | 10 | export class MyComponent extends MobxComponent { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /docs-md/doc-install.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 安装 3 | --- 4 | 5 | 6 | #### 安装 minapp 命令行工具 7 | 8 | ```bash 9 | npm install -g @minapp/cli 10 | ``` 11 | 12 | 13 | #### 初始化一个带基本功能的项目 14 | 15 | ```bash 16 | minapp init myproject 17 | ``` 18 | 19 | 20 | #### 切换至新创建的项目目录 21 | 22 | ```bash 23 | cd myproject 24 | ``` 25 | 26 | #### 安装依赖 27 | 28 | ```bash 29 | npm install 30 | ``` 31 | 32 | #### 开启实时编译 33 | 34 | ```bash 35 | npm run dev 36 | # 或者直接使用 37 | minapp dev 38 | ``` 39 | 40 | #### 发布 41 | 42 | ```bash 43 | npm run build 44 | # 或者直接使用 45 | minapp build 46 | ``` -------------------------------------------------------------------------------- /packages/minapp-common/src/dev/Component.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | export type Component = {name: string, docLink?: string, since?: string, desc: string[], attrs?: ComponentAttr[], authorize?: any, relateApis?: any[], notices?: string[], tips?: string[], bugs?: string[]} 3 | export type ComponentAttrValue = {value: string, desc?: string, since?: string} 4 | export type ComponentAttr = {name: string, type?: any, desc?: string[], required?: boolean, since?: string, defaultValue?: string, enum?: any[], extras?: any[], subAttrs?: Array<{equal: string, attrs: ComponentAttr[]}>} -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{motto}} 4 | 5 | 6 | 7 | 8 | 9 | 单向绑定: 10 | 双向绑定: 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/img/feature-complete.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /website/static/img/feature-complete.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/js/.dtpl/component/$rawModuleName.js.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | // 此文件是由模板文件 ".dtpl/component/${ref.dollar}rawModuleName.js.dtpl" 生成的,你可以自行修改模板 2 | 3 | import {MyComponent, comify} from 'base' 4 | 5 | @comify() 6 | export default class extends MyComponent { 7 | /** 8 | * 组件的属性列表 9 | */ 10 | properties = { 11 | 12 | } 13 | 14 | /** 15 | * 组件的初始数据 16 | */ 17 | data = { 18 | 19 | } 20 | 21 | /** 22 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 23 | */ 24 | onPropUpdate(prop, newValue, oldValue) { 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/component/$rawModuleName.ts.dtpl: -------------------------------------------------------------------------------- 1 | // 此文件是由模板文件 ".dtpl/component/${dollar}rawModuleName.ts.dtpl" 生成的,你可以自行修改模板 2 | 3 | import {MyComponent, comify} from 'base' 4 | 5 | @comify() 6 | export default class extends MyComponent { 7 | /** 8 | * 组件的属性列表 9 | */ 10 | properties = { 11 | 12 | } 13 | 14 | /** 15 | * 组件的初始数据 16 | */ 17 | data = { 18 | 19 | } 20 | 21 | /** 22 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 23 | */ 24 | onPropUpdate(prop: string, newValue: any, oldValue: any) { 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /docs-md/api-mobx-MobxComponent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: MobxComponent 3 | --- 4 | 5 | ### Class 属性及方法:继承 [BaseComponent](./api-core-BaseComponent.md) 6 | 7 | * **getStore()** 8 | 9 | 获取 app 中的 store 实例 10 | 11 | 12 | ### Example: 13 | 14 | ```js 15 | 16 | import {MobxComponent, comify} from '@minapp/mobx' 17 | 18 | @comify({ 19 | mixins: [] 20 | }) 21 | export default class extends MobxComponent { 22 | async onReady() { 23 | // todo 24 | } 25 | } 26 | 27 | ``` 28 | 29 | 30 | > 源代码: [MobxComponent.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-mobx/src/lib/MobxComponent.ts) 31 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/ts/.dtpl/component/$rawModuleName.ts.dtpl.dtpl: -------------------------------------------------------------------------------- 1 | // 此文件是由模板文件 ".dtpl/component/${ref.dollar}rawModuleName.ts.dtpl" 生成的,你可以自行修改模板 2 | 3 | import {MyComponent, comify} from 'base' 4 | 5 | @comify() 6 | export default class extends MyComponent { 7 | /** 8 | * 组件的属性列表 9 | */ 10 | properties = { 11 | 12 | } 13 | 14 | /** 15 | * 组件的初始数据 16 | */ 17 | data = { 18 | 19 | } 20 | 21 | /** 22 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 23 | */ 24 | onPropUpdate(prop: string, newValue: any, oldValue: any) { 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /packages/minapp-core/src/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | /// 7 | 8 | export * from './module/BaseApp' 9 | export * from './module/BasePage' 10 | export * from './module/BaseComponent' 11 | export * from './feat/Location' 12 | export * from './feat/Url' 13 | import * as util from './util' 14 | 15 | export {util} 16 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/base.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as sys from 'mora-scripts/libs/sys' 7 | import * as cli from 'mora-scripts/libs/tty/cli' 8 | import * as shell from 'mora-scripts/libs/tty/shell' 9 | import * as findup from 'mora-scripts/libs/fs/findup' 10 | 11 | export {compiler} from '../base/compiler' 12 | 13 | export {cli, findup, sys, shell} 14 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "program": "${workspaceFolder}/dist/__tests__/debug.js", 12 | "preLaunchTask": "npm: build", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/**/*.js" 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/__tests__/fixtures/a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | {{userInfo.nickName}} 10 | 11 | 12 | 13 | {{motto}} 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{motto}} 6 | 7 | 8 | 9 | {{foo.msg}} 10 | 11 | 12 | 单向绑定: 13 | 双向绑定: 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /packages/minapp-core/src/feat/Location.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import '@minapp/wx' 7 | 8 | export class Location { 9 | public pathname: string 10 | public query: {[key: string]: string} 11 | 12 | constructor() { 13 | let pages = getCurrentPages() 14 | let page = pages[pages.length - 1] 15 | this.pathname = page.route 16 | this.query = page.options || {} 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/loader/pug-loader.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {Loader} from './Loader' 7 | import * as pug from 'pug' 8 | 9 | @Loader.decorate 10 | export default class PugLoader extends Loader { 11 | async run(content: string) { 12 | this.lc.cacheable() 13 | return pug.render(content, {pretty: !this.minimize, filename: this.fromFile, basedir: this.srcDir, ...this.lc.query}) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docs-md/api-mobx-MobxApp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: MobxApp 3 | --- 4 | 5 | ### Class 属性及方法:继承 [BaseApp](./api-core-BaseApp.md) 6 | 7 | * **store** 8 | 9 | 即通过 `appify()` 函数注入的 store 对象 10 | 11 | 12 | ### Example: 13 | 14 | ```js 15 | 16 | import {MobxStore, MobxApp, appify} from '@minapp/mobx' 17 | 18 | @appify( 19 | new MobxStore(), 20 | { 21 | pages: require('./app.json?pages'), 22 | tabBarList: require('./app.json?tabBar.list') 23 | } 24 | ) 25 | export default class extends MobxApp { 26 | async onLaunch() { 27 | // todo 28 | } 29 | } 30 | 31 | ``` 32 | 33 | 34 | > 源代码: [MobxApp.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-mobx/src/lib/MobxApp.ts) 35 | -------------------------------------------------------------------------------- /docs/img/feature-webpack.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/minapp-core/globals.d.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | /** 7 | * process.env.NODE_ENV 中的值 8 | * 9 | * 如果没有指定则默认为 "developemnt" 10 | */ 11 | declare var __ENV__: 'developemnt' | 'production' | 'test' | string 12 | 13 | /** process.env.NODE_ENV === 'developemnt' 时此值为 true,否则为 false */ 14 | declare var __DEV__: boolean 15 | 16 | /** process.env.NODE_ENV === 'production' 时此值为 true,否则为 false */ 17 | declare var __PROD__: boolean 18 | 19 | 20 | -------------------------------------------------------------------------------- /website/static/img/feature-webpack.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/minapp.cjson.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/minapp.json", 3 | "compiler": { 4 | /* 5 | 将 px 转化成 rpx,同时将 rpx 转化成 px 6 | 7 | 如果需要将 1px 转化成 2rpx,可以设置成 {"px": "2rpx"} 8 | 如果需要将 2px 转化成 1rpx,可以设置成 {"px": "0.5rpx"} 9 | 你还可以设置其它任何单位的转化 10 | 11 | **注:左边的单位一定不能带任何数字** 12 | */ 13 | "unitTransformer": { 14 | "px": "rpx", 15 | "rpx": "px" 16 | }, 17 | 18 | // webpack-dev-server 相关的配置,详情参考:https://webpack.js.org/configuration/dev-server/ 19 | // 建议在 webpack.minapp.js 中配置 20 | // 注意:host 和 port 配置只能通过命令行配置 21 | "devServer": { 22 | 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs-md/api-mobx-MobxPage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: MobxPage 3 | --- 4 | 5 | ### Class 属性及方法:继承 [BasePage](./api-core-BasePage.md) 6 | 7 | * **store** 8 | 9 | 对 `app.store` 的引用 10 | 11 | 12 | ### Example: 13 | 14 | ```js 15 | 16 | import {MobxPage, pagify} from '@minapp/mobx' 17 | 18 | @pagify({ 19 | observe: true, // 是否自动监听 store 的变化 20 | mapStoreToData: (store) => {}, // 将 store 中的值映射到当前 page 的 data 中 21 | lazySetData: true, // 优化性能:页面隐藏状态下不调用 setData,在页面显示时统一再调用 22 | mixins: [] 23 | }) 24 | export default class extends MobxPage { 25 | async onShow() { 26 | // todo 27 | } 28 | } 29 | 30 | ``` 31 | 32 | 33 | > 源代码: [MobxPage.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-mobx/src/lib/MobxPage.ts) 34 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/__tests__/debug.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {parse} from '../parser' 7 | 8 | debugger 9 | let xml = parse(` 10 | 11 | 12 | function test() { 13 | return { 14 | CREATED: '1', 15 | REWARDED: '2', 16 | } 17 | } 18 | 19 | 20 | `) 21 | 22 | console.log(xml.toXML({ 23 | prefix: '', 24 | eol: '\n', 25 | preferSpaces: true, 26 | tabSize: 2, 27 | maxLineCharacters: 100, 28 | removeComment: false 29 | })) 30 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/app.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/app.json", 3 | "pages": [ 4 | /* 5 | 注意: 6 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 7 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 8 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 9 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 10 | */ 11 | 12 | /*# INJECT_START {"key": "page"} #*/ 13 | "pages/index/index", 14 | "pages/logs/logs", 15 | /*# INJECT_END #*/ 16 | ], 17 | "window": { 18 | "backgroundTextStyle": "light", 19 | "navigationBarBackgroundColor": "#fff", 20 | "navigationBarTitleText": "WeChat", 21 | "navigationBarTextStyle": "black" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/app.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/app.json", 3 | "pages": [ 4 | /* 5 | 注意: 6 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 7 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 8 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 9 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 10 | */ 11 | 12 | /*# INJECT_START {"key": "page"} #*/ 13 | "pages/index/index", 14 | "pages/logs/logs", 15 | /*# INJECT_END #*/ 16 | ], 17 | "window": { 18 | "backgroundTextStyle": "light", 19 | "navigationBarBackgroundColor": "#fff", 20 | "navigationBarTitleText": "WeChat", 21 | "navigationBarTextStyle": "black" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/app.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/app.json", 3 | "pages": [ 4 | /* 5 | 注意: 6 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 7 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 8 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 9 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 10 | */ 11 | 12 | /*# INJECT_START {"key": "page"} #*/ 13 | "pages/index/index", 14 | "pages/logs/logs", 15 | /*# INJECT_END #*/ 16 | ], 17 | "window": { 18 | "backgroundTextStyle": "light", 19 | "navigationBarBackgroundColor": "#fff", 20 | "navigationBarTitleText": "WeChat", 21 | "navigationBarTextStyle": "black" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/app.cjson: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/app.json", 3 | "pages": [ 4 | /* 5 | 注意: 6 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 7 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 8 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 9 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 10 | */ 11 | 12 | /*# INJECT_START {"key": "page"} #*/ 13 | "pages/index/index", 14 | "pages/logs/logs", 15 | /*# INJECT_END #*/ 16 | ], 17 | "window": { 18 | "backgroundTextStyle": "light", 19 | "navigationBarBackgroundColor": "#fff", 20 | "navigationBarTitleText": "WeChat", 21 | "navigationBarTextStyle": "black" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/src/app.cjson.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/app.json", 3 | "pages": [ 4 | /* 5 | 注意: 6 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 7 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 8 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 9 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 10 | */ 11 | 12 | /*# INJECT_START {"key": "page"} #*/ 13 | "pages/index/index", 14 | "pages/logs/logs", 15 | /*# INJECT_END #*/ 16 | ], 17 | "window": { 18 | "backgroundTextStyle": "light", 19 | "navigationBarBackgroundColor": "#fff", 20 | "navigationBarTitleText": "WeChat", 21 | "navigationBarTextStyle": "black" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs-md/doc-coding-rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 编码准则 3 | --- 4 | 5 | 由于微信原生 api 并不支持 class,所以除 `Store` 外,`App`,`Component` 和 `Page` 相关的类都要遵循下面的约束: 6 | 7 | * **不要在 class 的类方法中使用箭头函数,但可以在类方法内部使用(主要因为箭头函数将 this 绑定死了 Class,无法转到 Object 上)** 8 | 9 | 不可以这样用: 10 | ```ts 11 | class MyPage extends BasePage { 12 | foo = () => this.app 13 | } 14 | ``` 15 | 16 | 可以这样用: 17 | ```ts 18 | class MyPage extends BasePage { 19 | foo() { 20 | someArr.forEach(() => {}) 21 | } 22 | } 23 | ``` 24 | 25 | * **最好不要使用 `get prop() {}`,@minapp/mobx 框架支持,但微信内部会遍历 Object 中的属性的值,所以你的 prop 在 Page 还没初始化前就会被调用,有可能会导致错误** 26 | 27 | 最好不要这样用: 28 | ```ts 29 | class MyPage extends BasePage { 30 | get foo() { 31 | return this.something 32 | } 33 | } 34 | ``` 35 | -------------------------------------------------------------------------------- /docs-md/doc-difference-with-wepy.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 和 wepy 的对比 3 | --- 4 | 5 | 6 | 和 wepy 并不一样,wepy 把开发小程序做的像开发 vue 项目一样,所以它和原生的小程序开发感觉完全是两套不同的风格; 7 | 而 minapp 是还原原生小程序的开发模式,在原模式上进行语言级别的优化。 8 | 9 | 10 | ### 和 wepy 的一些不同点 11 | 12 | * wepy 会在编译的时候修改你的代码;minapp 不会修改你的任何代码,但需要你按照一定的开发模式去开发 13 | * wepy 内部实现了一个脏检查机制;minapp 依赖 mobx 来完成全局数据维护,并保留原生组件内部状态数据更新机制(`setData`) 14 | * wepy 的组件是它自己实现的,并没有使用小程序的组件,所以打包的时候它会将组件模板编译到 page 内;minapp 使用的还是小程序的组件 15 | * wepy 的编译器是自己实现的;minapp 是依赖于 webpack 来编译的 16 | 17 | ### 和 wepy 的一些相同点 18 | 19 | * 支持加载外部 npm 包 20 | * 提供 promise 化的原生接口 21 | 22 | ### 优于 wepy 的一些点 23 | 24 | * 完美的自动补全机制(参见[代码自动补全](./guide-autocomplete.md)) 25 | * 基于 mobx 的全局数据管理,使得修改和获取全局数据非常方便 26 | * 开发环境中集成了 webpack-dev-server,可以方便的使用本地静态资源 27 | * minapp 复用了开源社区中的模块,没有重复造轮子,维护成本低 28 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/base/MyStore.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxStore} from '@minapp/mobx' 7 | import {observable} from 'mobx' 8 | 9 | export class MyStore extends MobxStore { 10 | /** 11 | * 注意: 12 | * 小程序 setData({key: value}) 中,如果 value 为 undefined,小程序会报错(主要 undefined 时,小程序不会更新原来存储在 key 中的值) 13 | * 而 start 中的值会被注入到 page 的 data 中,所以不要有 undefined 14 | * 15 | * 另外,函数相关的 ts 定义都存储在 wx.[同名函数] 的 namespace 中,如下面的 ParamPropSuccessParamPropUserInfo 16 | */ 17 | @observable userInfo = null 18 | } 19 | -------------------------------------------------------------------------------- /packages/minapp-common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "removeComments": false, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": false, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "strictPropertyInitialization": true, 19 | "noLib": false, 20 | "lib": [ 21 | "es6" 22 | ], 23 | "outDir": "dist" 24 | }, 25 | "include": [ 26 | "src" 27 | ], 28 | "exclude": [ 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /packages/minapp-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "removeComments": false, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "strictPropertyInitialization": true, 19 | "noLib": false, 20 | "lib": [ 21 | "es6" 22 | ], 23 | "outDir": "dist/" 24 | }, 25 | "include": [ 26 | "src/" 27 | ], 28 | "exclude": [ 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /website/static/css/custom.css: -------------------------------------------------------------------------------- 1 | /* your custom css */ 2 | 3 | #try .blockContent h2 { 4 | margin-top: 0; 5 | } 6 | 7 | .homeGifContainer .blockContent p { 8 | max-width: none; 9 | } 10 | 11 | .homeGifContainer .blockImage { 12 | max-width: none; 13 | max-height: 400px; 14 | } 15 | 16 | .homeGifContainer .blockImage img { 17 | max-height: 400px; 18 | width: auto; 19 | } 20 | 21 | .homeGifContainer .gridBlock .twoByGridBlock { 22 | flex: 1 0 100%; 23 | } 24 | 25 | @media only screen and (min-device-width: 360px) and (max-device-width: 736px) { 26 | } 27 | 28 | @media only screen and (min-width: 1024px) { 29 | } 30 | 31 | @media only screen and (max-width: 1023px) { 32 | } 33 | 34 | @media only screen and (min-width: 1400px) { 35 | } 36 | 37 | @media only screen and (min-width: 1500px) { 38 | } 39 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/project.config.json", 3 | "description": "项目配置文件。", 4 | "setting": { 5 | "urlCheck": true, 6 | "es6": false, 7 | "postcss": false, 8 | "minified": false, 9 | "newFeature": true 10 | }, 11 | "compileType": "miniprogram", 12 | "libVersion": "1.9.1", 13 | "appid": "wxcbe3dcec68e268e3", 14 | "projectname": "core-js", 15 | "isGameTourist": false, 16 | "condition": { 17 | "search": { 18 | "current": -1, 19 | "list": [] 20 | }, 21 | "conversation": { 22 | "current": -1, 23 | "list": [] 24 | }, 25 | "game": { 26 | "currentL": -1, 27 | "list": [] 28 | }, 29 | "miniprogram": { 30 | "current": -1, 31 | "list": [] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/project.config.json", 3 | "description": "项目配置文件。", 4 | "setting": { 5 | "urlCheck": true, 6 | "es6": false, 7 | "postcss": false, 8 | "minified": false, 9 | "newFeature": true 10 | }, 11 | "compileType": "miniprogram", 12 | "libVersion": "1.9.1", 13 | "appid": "wxcbe3dcec68e268e3", 14 | "projectname": "core-ts", 15 | "isGameTourist": false, 16 | "condition": { 17 | "search": { 18 | "current": -1, 19 | "list": [] 20 | }, 21 | "conversation": { 22 | "current": -1, 23 | "list": [] 24 | }, 25 | "game": { 26 | "currentL": -1, 27 | "list": [] 28 | }, 29 | "miniprogram": { 30 | "current": -1, 31 | "list": [] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/project.config.json", 3 | "description": "项目配置文件。", 4 | "setting": { 5 | "urlCheck": true, 6 | "es6": false, 7 | "postcss": false, 8 | "minified": false, 9 | "newFeature": true 10 | }, 11 | "compileType": "miniprogram", 12 | "libVersion": "1.9.1", 13 | "appid": "wxcbe3dcec68e268e3", 14 | "projectname": "mobx-js", 15 | "isGameTourist": false, 16 | "condition": { 17 | "search": { 18 | "current": -1, 19 | "list": [] 20 | }, 21 | "conversation": { 22 | "current": -1, 23 | "list": [] 24 | }, 25 | "game": { 26 | "currentL": -1, 27 | "list": [] 28 | }, 29 | "miniprogram": { 30 | "current": -1, 31 | "list": [] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/project.config.json", 3 | "description": "项目配置文件。", 4 | "setting": { 5 | "urlCheck": true, 6 | "es6": false, 7 | "postcss": false, 8 | "minified": false, 9 | "newFeature": true 10 | }, 11 | "compileType": "miniprogram", 12 | "libVersion": "1.9.1", 13 | "appid": "wxcbe3dcec68e268e3", 14 | "projectname": "mobx-ts", 15 | "isGameTourist": false, 16 | "condition": { 17 | "search": { 18 | "current": -1, 19 | "list": [] 20 | }, 21 | "conversation": { 22 | "current": -1, 23 | "list": [] 24 | }, 25 | "game": { 26 | "currentL": -1, 27 | "list": [] 28 | }, 29 | "miniprogram": { 30 | "current": -1, 31 | "list": [] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-mobx/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "removeComments": false, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "strictPropertyInitialization": true, 19 | "noLib": false, 20 | "lib": [ 21 | "es6" 22 | ], 23 | "outDir": "dist" 24 | }, 25 | "include": [ 26 | "src" 27 | ], 28 | "exclude": [ 29 | "**/__*" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /packages/minapp-common/src/lib/fs.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {promisify} from 'mora-common/util/promisify' 7 | import * as fs from 'fs' 8 | 9 | export const stat: (filepath: string) => Promise = promisify(fs.stat, fs) 10 | 11 | export const readdir: (dirpath: string) => Promise = promisify(fs.readdir, fs) 12 | 13 | export const readFile: (filepath: string) => Promise = promisify(fs.readFile, fs) 14 | 15 | export const exists: (filepath: string) => Promise = promisify(fs.exists, fs) 16 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "strictPropertyInitialization": true, 19 | "noLib": false, 20 | "lib": [ 21 | "es6" 22 | ], 23 | "outDir": "dist" 24 | }, 25 | "include": [ 26 | "src" 27 | ], 28 | "exclude": [ 29 | "node_modules" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/base/MyApp.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {Url, BaseApp} from '@minapp/core' 7 | 8 | export class MyApp extends BaseApp { 9 | // @ts-ignore 10 | $url: { 11 | /* 12 | 注意: 13 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 14 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 15 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 16 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 17 | */ 18 | 19 | /*# INJECT_START {"key": "pagesMap"} #*/ 20 | index: Url 21 | logs: Url 22 | /*# INJECT_END #*/ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Component/ts/tsconfig.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": false, 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "strictPropertyInitialization": true, 19 | "noLib": false, 20 | "lib": [ 21 | "es6" 22 | ], 23 | "outDir": "dist" 24 | }, 25 | "include": [ 26 | "src" 27 | ], 28 | "exclude": [ 29 | "node_modules" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/loader/wxs-loader.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | // import * as path from 'path' 7 | import {Loader} from './Loader' 8 | import {parse} from './js-loader' 9 | 10 | const debug = require('debug')('minapp:cli:wxs-loader') 11 | 12 | 13 | @Loader.decorate 14 | export default class WxsLoader extends Loader { 15 | // @ts-ignore 16 | async run(content: string) { 17 | debug('FromFile: ' + this.fromFile) 18 | debug('ToFile: %o', this.toFile) 19 | 20 | this.lc.cacheable() 21 | 22 | return await parse(this, debug, content, '.wxs') 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/minapp-cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": false, 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "strictPropertyInitialization": true, 19 | "noLib": false, 20 | "lib": [ 21 | "es6", "es2016.array.include" 22 | ], 23 | "outDir": "dist" 24 | }, 25 | "include": [ 26 | "src" 27 | ], 28 | "exclude": [ 29 | "node_modules" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/logs/logs.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, MyPage} from 'base/' 7 | 8 | @pagify() 9 | export default class extends MyPage { 10 | data = { 11 | logs: [] 12 | } 13 | 14 | backToHome() { 15 | this.app.$back() 16 | } 17 | 18 | onLoad() { 19 | let location = this.getLocation() 20 | console.log(`当前页面 ${location.pathname}, 页面参数 ${JSON.stringify(location.query)}`) 21 | this.setDataSmart({ 22 | logs: (wx.getStorageSync('logs') || []).map((log) => new Date(log).toLocaleString()) 23 | }) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/example-mobx-js", 3 | "version": "2.0.0", 4 | "description": "minapp js 示例项目", 5 | "scripts": { 6 | "test": "echo 0", 7 | "clear": "node ../minapp-cli/dist/bin/minapp.js clear dist", 8 | "dev": "node ../minapp-cli/dist/bin/minapp.js dev", 9 | "build": "node ../minapp-cli/dist/bin/minapp.js build --publicPath http://lcdn.static.lotlot.com/" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "author": "Mora (https://qiu8310.github.io/)", 15 | "license": "MIT", 16 | "dependencies": { 17 | "@minapp/component-toast": "^2.0.0", 18 | "@minapp/core": "^2.0.0", 19 | "@minapp/mobx": "^2.0.0", 20 | "@minapp/wx": "latest", 21 | "babel-runtime": "^6.24.0", 22 | "mobx": "^3.5.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/base/MyStore.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MobxStore} from '@minapp/mobx' 7 | import {observable} from 'mobx' 8 | 9 | export class MyStore extends MobxStore { 10 | /** 11 | * 注意: 12 | * 小程序 setData({key: value}) 中,如果 value 为 undefined,小程序会报错(主要 undefined 时,小程序不会更新原来存储在 key 中的值) 13 | * 而 start 中的值会被注入到 page 的 data 中,所以不要有 undefined 14 | * 15 | * 另外,函数相关的 ts 定义都存储在 wx.[同名函数] 的 namespace 中,如下面的 ParamPropSuccessParamPropUserInfo 16 | */ 17 | @observable userInfo: null | wx.getUserInfo.ParamPropSuccessParamPropUserInfo = null 18 | } 19 | -------------------------------------------------------------------------------- /docs-md/doc-about-component.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 关于 Component 3 | --- 4 | 5 | * 官方组件的生命周期函数都不是以 `on` 开头的函数,所以为了方便和 Page 中的生命周期函数统一,你可以使用带 `on` 版本的生成周期函数: 6 | 7 | `onCreated`, `onAttached`, `onReady`, `onMoved`, `onDetached` 8 | 9 | 10 | * 另外官方组件中的方法需要放在 methods 中,如 11 | 12 | ```js 13 | @comify() 14 | export MyComponent extends BaseComponent { 15 | methods = { 16 | fn1() { 17 | /**/ 18 | } 19 | } 20 | } 21 | ``` 22 | 23 | 这样不方便编辑器判断函数的 `this` 的作用域,所以你可以直接将上面例子中的 `fn1` 放在最外层即可,在 `comify()` 中会将这些外部的 24 | 非生命周期函数移动到 methods 内部! 25 | 26 | 27 | * 组件的属性中可以配置一个 `observer` 函数,如果在每个属性中都配置的话,会很麻烦,所以做了一个钩子方法 `onPropUpdate`,只要有属性变化,就会执行此方法 28 | 29 | ```js 30 | @comify() 31 | export MyComponent extends BaseComponent { 32 | onPropUpdate(propName, propNewValue, propOldValue) { 33 | 34 | } 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /docs-md/doc-warn.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 重要提醒 3 | --- 4 | 5 | ### 开发前的准备: 6 | 7 | 1. 注册小程序:[点此直接跳到微信小程序注册页面](https://mp.weixin.qq.com/wxopen/waregister?action=step1) 8 | 2. 登录 https://mp.weixin.qq.com/ 在菜单 “设置”-“开发设置” 中可以看到小程序的 AppID 9 | 3. 安装官方提供的[开发者工具](https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html) 10 | 4. 使用 minapp init 新建项目,过程中会让你提供 appid,如果没提供,可以手动修改 src/project.config.json 中的 appid 字段 11 | 12 | 更多详细介绍可以前往[微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/) 13 | 14 | ### 关于 project.config.json 15 | 16 | 主要是下面的 setting 部分,`es6`、`postcss`、`minified` 都设置为 false 即可,`minapp build` 的时候会自动为你做这些事; 17 | 默认情况下 `minapp init` 初始化的项目都已经帮你配置好了,你无需修改 18 | 19 | ```json 20 | "setting": { 21 | "urlCheck": true, 22 | "es6": false, 23 | "postcss": false, 24 | "minified": false, 25 | "newFeature": true 26 | } 27 | ``` 28 | 29 | 30 | -------------------------------------------------------------------------------- /packages/minapp-core/src/util/pollute.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {toObject} from './object' 7 | import {mixin} from './mixin' 8 | 9 | export interface PolluteOptions { 10 | /** 指定要注入的 mixin */ 11 | mixins?: any[] 12 | } 13 | 14 | export function pollute(Klass: any, options: PolluteOptions, callback?: (obj: any) => void) { 15 | let obj: Page.Options = toObject(new Klass()) 16 | let app = getApp() as any 17 | 18 | if (options.mixins && options.mixins.length) { 19 | mixin(obj, options.mixins) 20 | } 21 | 22 | obj.app = app 23 | 24 | if (callback) callback(obj) 25 | return obj 26 | } 27 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/example-core-js", 3 | "version": "2.0.0", 4 | "description": "minapp js 示例项目", 5 | "scripts": { 6 | "test": "echo 0", 7 | "clear": "node ../minapp-cli/dist/bin/minapp.js clear dist", 8 | "dev": "node ../minapp-cli/dist/bin/minapp.js dev", 9 | "build": "node ../minapp-cli/dist/bin/minapp.js build --publicPath http://lcdn.static.lotlot.com/" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "author": "Mora (https://qiu8310.github.io/)", 15 | "license": "MIT", 16 | "dependencies": { 17 | "@minapp/component-demo": "^2.0.0", 18 | "@minapp/component-toast": "^2.0.0", 19 | "@minapp/core": "^2.0.0", 20 | "@minapp/wx": "latest" 21 | }, 22 | "devDependencies": { 23 | "babel-runtime": "^6.24.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/logs/logs.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, MyPage} from 'base/' 7 | 8 | @pagify() 9 | export default class extends MyPage { 10 | data = { 11 | logs: [] 12 | } 13 | 14 | backToHome() { 15 | this.app.$back() 16 | } 17 | 18 | onLoad() { 19 | let location = this.getLocation() 20 | console.log(`当前页面 ${location.pathname}, 页面参数 ${JSON.stringify(location.query)}`) 21 | 22 | let logs = wx.getStorageSync('logs') || [] 23 | this.setDataSmart({ 24 | logs: logs.map(log => new Date(log).toLocaleString()) 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/img/feature-js.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/logs/logs.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, MyPage} from 'base/' 7 | 8 | @pagify() 9 | export default class extends MyPage { 10 | data = { 11 | logs: [] 12 | } 13 | 14 | backToHome() { 15 | this.app.$back() 16 | } 17 | 18 | onLoad() { 19 | let location = this.getLocation() 20 | console.log(`当前页面 ${location.pathname}, 页面参数 ${JSON.stringify(location.query)}`) 21 | 22 | let logs: string[] = wx.getStorageSync('logs') || [] 23 | this.setDataSmart({ 24 | logs: logs.map(log => new Date(log).toLocaleString()) 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /website/static/img/feature-js.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs-md/doc-use-setDataSmart-not-setData.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 使用 setDataSmart 而不是 setData 3 | --- 4 | 5 | 小程序页面在跳转时,页面对象有可能并没有销毁,同时可能会有些异步函数在页面隐藏的时候才返回值,它们返回的时候可能会去调用 setData,但这时页面其实隐藏了,这些 setData 对用户来说并没有什么效果。 6 | 7 | 还可能有种更严重的情况是:当我们使用了全局数据时(如 `@minapp/mobx` 的 store),我们只要在某个地方修改 store ,可能会导致所有引用了此 store 的 page 都更新,这样小程序性能可能就不会很好了。 8 | 9 | 所以,我们需要当页面处于隐藏状态时,不去真正触发 setData,而是将这些 data 缓存起来,当页面真正出现的时候,再将缓存的这些 data 统一去调用 setData,如此,可以避免一些不必要的性能损耗,这就是 `setDataSmart` 内部会处理的逻辑。 10 | 11 | 另外,如果你要使用数据双向绑定,也必须使用 `setDataSmart`,详情参考: [如何在原生的小程中实现数据双向绑定](./doc-how-to-realize-two-way-data-bind.md) 12 | 13 | 14 | 15 | > 参考:[微信官方对性能优化的建议](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/performance/tips.html#%E5%B8%B8%E8%A7%81%E7%9A%84-setdata-%E6%93%8D%E4%BD%9C%E9%94%99%E8%AF%AF) 16 | 17 | 18 | 19 | ### 为什么不覆盖 `setData` 方法,而去添加一个新方法? 20 | 21 | 其实是有尝试过覆盖 `setData` 方法的,但微信开发者工具会报错,此方法是只读的,无法修改! 22 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/src/project.config.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/qiu8310/minapp/master/schema/project.config.json", 3 | "description": "${description}", 4 | "setting": { 5 | "urlCheck": true, 6 | "es6": false, 7 | "postcss": false, 8 | "minified": false, 9 | "newFeature": true 10 | }, 11 | "compileType": "miniprogram", 12 | "libVersion": "2.1.0", 13 | "appid": "${appid}", 14 | "projectname": "${name}", 15 | "isGameTourist": false, 16 | "condition": { 17 | "search": { 18 | "current": -1, 19 | "list": [] 20 | }, 21 | "conversation": { 22 | "current": -1, 23 | "list": [] 24 | }, 25 | "game": { 26 | "currentL": -1, 27 | "list": [] 28 | }, 29 | "miniprogram": { 30 | "current": -1, 31 | "list": [] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/logs/logs.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, MyPage} from 'base/' 7 | 8 | @pagify() 9 | export default class extends MyPage { 10 | data = { 11 | logs: [] 12 | } 13 | 14 | backToHome() { 15 | this.app.$back() 16 | } 17 | 18 | onLoad() { 19 | this.store.userInfo = null // 清除 userInfo 20 | let location = this.getLocation() 21 | console.log(`当前页面 ${location.pathname}, 页面参数 ${JSON.stringify(location.query)}`) 22 | this.setDataSmart({ 23 | logs: (wx.getStorageSync('logs') || []).map((log: string) => new Date(log).toLocaleString()) 24 | }) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs-md/doc-how-to-use-wxp-in-other-project.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 如何在其它项目中复用 wx 及 wxp 自动补全 3 | --- 4 | 5 | ## minapp v2 用户 6 | 7 | 只需要安装 `@minapp/wx`(从 2.0.0 开始,此模块会跟着官方的微信库版本号走)即可 8 | 9 | * 如果需要使用 `wx` 的自动补全,只需要 10 | 11 | ```js 12 | import '@minapp/wx' 13 | ``` 14 | 15 | * 如果需要使用 `wxp` 的自动补全,只需要 16 | 17 | ```js 18 | import {wxp} from '@minapp/wx/wxp' 19 | ``` 20 | 21 | ## minapp v1 用户 22 | 23 | 框架中所有 wx 和 wxp 的自动补全的文档都是从官方文档中抓取下来的,为了方便复用,我把它们单独发布在了 `@minapp/core` 中, 24 | 所以,如果你不想使用 minapp 提供的框架,而是使用了 wepy 或其它框架,你也一样可以安装 `@minapp/core` 模块,这样就可以在 25 | 你的编辑器中实现所有 wx 和 wxp 的自动补全功能,引用方式如下: 26 | 27 | 28 | * 只想使用 wx 的自动补全:使用 ts 的 reference,或将 wx.d.ts 写到配置文件 tsconfig.json 或 jsconfig.json 中 29 | 30 | ```ts 31 | /// 32 | ``` 33 | 34 | * 想要使用 wx 和 wxp 的自动补全 35 | 36 | ```js 37 | import {wxp} from '@minapp/core/wxp' // 注意后面要带 wxp 后缀 38 | ``` 39 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/base/MyApp.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {Url} from '@minapp/core' 7 | import {MobxApp} from '@minapp/mobx' 8 | import {MyStore} from './MyStore' 9 | 10 | export class MyApp extends MobxApp { 11 | // @ts-ignore 12 | $url: { 13 | /* 14 | 注意: 15 | 1. INJECT_START 到 INJECT_END 之间的文件是自动注入的,请不要随意修改 16 | 2. 注入规则写在 .dtpl 文件夹中的 dtpl.js 文件中 17 | 3. 需要安装 vscode 插件 dot-template-vscode 来达到注入功能 18 | 4. 触发条件是:每次在 src/pages 目录下新建一个空文件夹时 19 | */ 20 | 21 | /*# INJECT_START {"key": "pagesMap"} #*/ 22 | index: Url 23 | logs: Url 24 | /*# INJECT_END #*/ 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.dtpl/dtpl.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as _ from 'types-dot-template' 7 | 8 | export default function(s: _.Source): _.IDtplConfig { 9 | return { 10 | templates: [ 11 | { 12 | name: './file/modify-api.ts.dtpl', 13 | matches: () => s.basicData.dirPath.indexOf('/modify/api/') >= 0 14 | }, 15 | { 16 | name: './file/modify-tpl.ts.dtpl', 17 | matches: () => s.basicData.dirPath.indexOf('/modify/tpl/') >= 0 18 | }, 19 | { 20 | name: './file/new.dtpl', 21 | matches: () => s.basicData.fileExt === '.ts' || s.basicData.fileExt === '.js' 22 | } 23 | ], 24 | globalData: {} 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs-md/api-core-BaseApp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: BaseApp 3 | --- 4 | 5 | 6 | ### Class 属性及方法: 7 | 8 | * **$home** 9 | 10 | 当前主页的 [Url](./api-core-Url.md) 对象,主页即配置在 app.json 中的 pages 中的第一个 url 地址 11 | 12 | * **$url** 13 | 14 | 类型: `{[key: string]: Url}` 15 | 16 | 一个所有页面的 map 表,key 是对应页面的 camelCase 的文件的名称(无后缀),如有个文件名为 `foo-bar.js` 17 | 的 page,则可以通过 `app.$url.fooBar` 来取到它的 [Url](./api-core-Url.md) 对象 18 | 19 | * **$back(delta: number = 1)** 20 | 21 | 对 `wx.navigateBack` 接口的简单封装 22 | 23 | ### Example: 24 | 25 | ```js 26 | 27 | import {BaseApp, appify} from '@minapp/core' 28 | 29 | @appify({ 30 | pages: require('./app.json?pages'), 31 | tabBarList: require('./app.json?tabBar.list') 32 | }) 33 | export default class extends BaseApp { 34 | async onLaunch() { 35 | // todo 36 | } 37 | } 38 | 39 | ``` 40 | 41 | 42 | > 源代码: [BaseApp.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-core/src/module/BaseApp.ts) 43 | -------------------------------------------------------------------------------- /docs-md/api-core-BasePage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: BasePage 3 | --- 4 | 5 | ### Class 属性及方法: 6 | 7 | * **app** 8 | 9 | 当前 app 实例,微信原生需要通过全局函数 `getApp()` 来获取,这里为了方便,可以直接在 Page 中通过 `this.app` 来获取 10 | 11 | * **setDataSmart(data, callback?)** 12 | 13 | 对 `setData` 的封装,不过 `setDataSmart` 还支持 **数据双向绑定** 及 **hide 状态下不更新 data** 的两个功能 14 | 15 | * **getLocation()** 16 | 17 | 获取关于此页面的一个 [Location](./api-core-Location.md) 对象 18 | 19 | * **$visiable** 20 | 21 | 限制:`readonly` 22 | 23 | 类型: `boolean` 24 | 25 | 当前页面是显示还是隐藏 26 | 27 | ### Example: 28 | 29 | ```js 30 | 31 | import {BasePage, pagify} from '@minapp/core' 32 | 33 | @pagify({ 34 | lazySetData: true, // 优化性能:页面隐藏状态下不调用 setData,在页面显示时统一再调用 35 | mixins: [] 36 | }) 37 | export default class extends BasePage { 38 | async onShow() { 39 | // todo 40 | } 41 | } 42 | 43 | ``` 44 | 45 | 46 | > 源代码: [BasePage.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-core/src/module/BasePage.ts) 47 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/plugin/RemoveLessCache.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as webpack from 'webpack' 7 | import * as path from 'path' 8 | 9 | import {Env} from '../../config/env' 10 | 11 | // less 会缓存 import 的文件,需要在每次编译完清除缓存 12 | export class RemoveLessCache { 13 | less: any 14 | constructor(public env: Env) { 15 | try { 16 | this.less = require(path.join(this.env.modulesDir, 'less')) 17 | } catch (e) {} 18 | } 19 | apply(compiler: webpack.Compiler) { 20 | compiler.hooks.done.tap('RemoveLessCache', () => { 21 | try { 22 | if (this.less) { 23 | this.less.environment.fileManagers[0].contents = {}; 24 | } 25 | } catch (e) {} 26 | }) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/webpack.minapp.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 修改 loader 或 loader 配置 4 | */ 5 | module.exports.updateLoaders = function(loaders, env) { 6 | /** 修改 ts loader **/ 7 | // loaders.ts.loader = 'awesome-typescript-loader' // 使用本地的 awesome-typescript-loader 8 | // loaders.ts.options = {} // 修改配置 9 | 10 | 11 | /** 添加 postcss plugin **/ 12 | // loaders.postcss.options.plugins.push(/* your plugin */) 13 | 14 | 15 | /** 添加 babel plugin (ts 项目不会使用 babel-loader) **/ 16 | // loaders.babel.options.plugins.push(/* your plugin */) 17 | 18 | 19 | /** 查看 loaders 结构 **/ 20 | // console.log(loaders) 21 | } 22 | 23 | 24 | 25 | /** 26 | * 修改 webpack 配置 27 | */ 28 | module.exports.webpack = function(wpConf, webpack, env) { 29 | // minapp build 时 env.mode 为 production 30 | // minapp dev 时 env.mode 为 development 31 | 32 | if (env.mode === 'production') { 33 | 34 | } else { 35 | 36 | } 37 | 38 | // env 中还有许多其它环境相关的变量,输出查看其结构 39 | // console.log(env) 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/minapp-clear.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as path from 'path' 7 | import * as fs from 'fs-extra' 8 | import {sys, cli} from './base' 9 | 10 | export const clearOptions: cli.Options = { 11 | 12 | } 13 | 14 | /** 15 | * 删除指定的文件夹(默认为 dist 文件夹) 16 | * @param res 命令行的参数(由 cli 脚本生成) 17 | */ 18 | export function clearCommand(res: cli.Response) { 19 | let directories = res._.length 20 | ? res._ // 使用命令行上指定的文件夹 21 | : ['dist'] // 使用根目录下的 dist 文件夹 22 | 23 | directories.forEach(directory => { 24 | directory = path.resolve(directory) 25 | 26 | if (fs.existsSync(directory)) { 27 | sys.info(`Empty directory ${directory}\n`) 28 | fs.emptyDirSync(directory) 29 | } 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/example-core-ts", 3 | "version": "2.1.0", 4 | "description": "minapp ts 示例项目", 5 | "scripts": { 6 | "test": "echo 0", 7 | "lint": "tslint src/**/*.ts", 8 | "clear": "node ../minapp-cli/dist/bin/minapp.js clear dist", 9 | "dev": "node ../minapp-cli/dist/bin/minapp.js dev", 10 | "build": "node ../minapp-cli/dist/bin/minapp.js build --publicPath http://lcdn.static.lotlot.com/" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "author": "Mora (https://github.com/qiu8310)", 16 | "license": "MIT", 17 | "dependencies": { 18 | "@minapp/component-demo": "^2.0.0", 19 | "@minapp/component-toast": "^2.0.0", 20 | "@minapp/core": "^2.0.0", 21 | "@minapp/wx": "latest", 22 | "tslib": "^1.9.0" 23 | }, 24 | "devDependencies": { 25 | "@types/node": "^8.0.0", 26 | "ts-lint": "^4.5.1", 27 | "ts-loader": "^4.2.0", 28 | "typescript": "^2.7.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // "checkJs": true, 4 | "target": "es5", 5 | "module": "commonjs", 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | // "allowSyntheticDefaultImports": false, 9 | // "noUnusedLocals": true, 10 | // "noUnusedParameters": false, 11 | // "noImplicitThis": true, 12 | // "noFallthroughCasesInSwitch": true, 13 | // "noImplicitReturns": true, 14 | // "strictNullChecks": true, 15 | "noLib": false, 16 | "rootDir": "src", 17 | "baseUrl": "src", 18 | 19 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 20 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 21 | "lib": [ 22 | "es5", 23 | "es2015.core", 24 | "es2015.symbol", 25 | "es2015.collection", 26 | "es2015.promise" 27 | ] 28 | }, 29 | "include": [ 30 | "src" 31 | ], 32 | "exclude": [ 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // "checkJs": true, 4 | "target": "es5", 5 | "module": "commonjs", 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | // "allowSyntheticDefaultImports": false, 9 | // "noUnusedLocals": true, 10 | // "noUnusedParameters": false, 11 | // "noImplicitThis": true, 12 | // "noFallthroughCasesInSwitch": true, 13 | // "noImplicitReturns": true, 14 | // "strictNullChecks": true, 15 | "noLib": false, 16 | "rootDir": "src", 17 | "baseUrl": "src", 18 | 19 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 20 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 21 | "lib": [ 22 | "es5", 23 | "es2015.core", 24 | "es2015.symbol", 25 | "es2015.collection", 26 | "es2015.promise" 27 | ] 28 | }, 29 | "include": [ 30 | "src" 31 | ], 32 | "exclude": [ 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/js/jsconfig.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // "checkJs": true, 4 | "target": "es5", 5 | "module": "commonjs", 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | // "allowSyntheticDefaultImports": false, 9 | // "noUnusedLocals": true, 10 | // "noUnusedParameters": false, 11 | // "noImplicitThis": true, 12 | // "noFallthroughCasesInSwitch": true, 13 | // "noImplicitReturns": true, 14 | // "strictNullChecks": true, 15 | "noLib": false, 16 | "rootDir": "src", 17 | "baseUrl": "src", 18 | 19 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 20 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 21 | "lib": [ 22 | "es5", 23 | "es2015.core", 24 | "es2015.symbol", 25 | "es2015.collection", 26 | "es2015.promise" 27 | ] 28 | }, 29 | "include": [ 30 | "src" 31 | ], 32 | "exclude": [ 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Component/js/jsconfig.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // "checkJs": true, 4 | "target": "es5", 5 | "module": "commonjs", 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | // "allowSyntheticDefaultImports": false, 9 | // "noUnusedLocals": true, 10 | // "noUnusedParameters": false, 11 | // "noImplicitThis": true, 12 | // "noFallthroughCasesInSwitch": true, 13 | // "noImplicitReturns": true, 14 | // "strictNullChecks": true, 15 | "noLib": false, 16 | "rootDir": "src", 17 | "baseUrl": "src", 18 | 19 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 20 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 21 | "lib": [ 22 | "es5", 23 | "es2015.core", 24 | "es2015.symbol", 25 | "es2015.collection", 26 | "es2015.promise" 27 | ] 28 | }, 29 | "include": [ 30 | "src" 31 | ], 32 | "exclude": [ 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /packages/minapp-mobx/src/lib/MobxApp.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as core from '@minapp/core/system' 7 | import {MobxStore} from './MobxStore' 8 | 9 | export interface AppifyOptions extends core.AppifyOptions { 10 | } 11 | 12 | export function appify(store: S, options: AppifyOptions) { 13 | return core.appify(options, (obj) => { 14 | // @ts-ignore 15 | if (!store || !store.__MOBX__) { 16 | core.util.warn(`用 appify 函数时提供的 store: %o 没有继承 @minapp/mobx 中的 MobxStore 类`, store) 17 | } 18 | 19 | obj.store = store 20 | }) 21 | } 22 | 23 | export interface MobxApp extends core.BaseApp { 24 | } 25 | 26 | export class MobxApp extends core.BaseApp { 27 | // @ts-ignore 28 | readonly store: S 29 | } 30 | 31 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{userInfo.nickName}} 7 | 8 | 9 | 10 | {{motto}} 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 双向绑定 21 | 单向绑定 22 | 23 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/example-mobx-ts", 3 | "version": "2.0.0", 4 | "description": "minapp ts 示例项目", 5 | "scripts": { 6 | "test": "echo 0", 7 | "lint": "tslint src/**/*.ts", 8 | "clear": "node ../minapp-cli/dist/bin/minapp.js clear dist", 9 | "dev": "node ../minapp-cli/dist/bin/minapp.js dev", 10 | "build": "node ../minapp-cli/dist/bin/minapp.js build --publicPath http://lcdn.static.lotlot.com/" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | }, 15 | "author": "Mora (https://github.com/qiu8310)", 16 | "license": "MIT", 17 | "dependencies": { 18 | "@minapp/component-demo": "^2.0.0", 19 | "@minapp/component-toast": "^2.0.0", 20 | "@minapp/core": "^2.0.0", 21 | "@minapp/mobx": "^2.0.0", 22 | "@minapp/wx": "latest", 23 | "mobx": "^3.5.1", 24 | "tslib": "^1.9.0" 25 | }, 26 | "devDependencies": { 27 | "@types/node": "^8.0.0", 28 | "ts-lint": "^4.5.1", 29 | "ts-loader": "^4.0.0", 30 | "typescript": "^2.7.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/minapp-mobx/src/lib/MobxPage.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as core from '@minapp/core/system' 7 | import {MobxStore} from './MobxStore' 8 | import {MobxApp} from './MobxApp' 9 | import {PolluteOptions, pollute} from './pollute' 10 | 11 | export interface PagifyOptions extends PolluteOptions, core.PagifyOptions { 12 | } 13 | 14 | /** 15 | * 将一个继承了 BasePage 的类转化成 小程序 Page 的调用 16 | */ 17 | export function pagify>(options: PagifyOptions = {}) { 18 | return core.pagify(options, (obj) => { 19 | pollute(obj, 'onLoad', 'onUnload', options) 20 | }) 21 | } 22 | 23 | 24 | export class MobxPage> extends core.BasePage { 25 | /** 26 | * app.store 的别名 27 | */ 28 | // @ts-ignore 29 | readonly store: S 30 | } 31 | -------------------------------------------------------------------------------- /docs-md/api-core-BaseComponent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: BaseComponent 3 | --- 4 | 5 | ### Class 属性及方法: 6 | 7 | * **getApp()** 8 | 9 | 获取 app 实例,对微信原生全局函数 `getApp()` 的简单封装 10 | 11 | 12 | * **setDataSmart(data, callback?)** 13 | 14 | 对 `setData` 的封装,不过 `setDataSmart` 还支持 **数据双向绑定** 及 **hide 状态下不更新 data** 的两个功能 15 | 16 | * **生成周期函数:** 17 | 18 | - `onCreated:`组件生命周期函数,在组件实例进入页面节点树时执行,注意此时不能调用 setData 19 | - `onAttached:`组件生命周期函数,在组件实例进入页面节点树时执行 20 | - `onReady:`组件生命周期函数,在组件布局完成后执行,此时可以获取节点信息(使用 SelectorQuery ) 21 | - `onMoved:`组件生命周期函数,在组件实例被移动到节点树另一个位置时执行 22 | - `onDetached:`组件生命周期函数,在组件实例被从页面节点树移除时执行 23 | - `onPropUpdate(prop: string, newValue: any, oldValue: any):`组件中 data 值变化时调用 24 | 25 | 26 | ### Example: 27 | 28 | ```js 29 | 30 | import {BaseComponent, comify} from '@minapp/core' 31 | 32 | @comify({ 33 | mixins: [] 34 | }) 35 | export default class extends BaseComponent { 36 | async onReady() { 37 | // todo 38 | } 39 | } 40 | 41 | ``` 42 | 43 | 44 | > 源代码: [BaseComponent.ts](https://github.com/qiu8310/minapp/blob/master/packages/minapp-core/src/module/BaseComponent.ts) 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minapp-pack", 3 | "version": "0.0.0", 4 | "private": true, 5 | "license": "MIT", 6 | "scripts": { 7 | "publish_app": "lerna publish --registry https://registry.npmjs.org/ --ignore @minapp/wx --ignore '@minapp/example-*' --ignore '@minapp/component-*' --ignore minapp-vscode", 8 | "build_app": "lerna run build --ignore '@minapp/example-*' --ignore '@minapp/component-*'", 9 | "build_exp": "lerna run build --scope '@minapp/component-*' --scope '@minapp/example-*'", 10 | "all_build": "npm run build_app && npm run build_exp", 11 | "all_test": "lerna run test --ignore minapp-vscode", 12 | "all_publish": "lerna publish --ignore @minapp/wx --registry https://registry.npmjs.org/", 13 | "all_publish_tag": "lerna publish --ignore @minapp/wx --npm-tag next --registry https://registry.npmjs.org/ --repo-version 2.0.0-alpha.2", 14 | "build": "tsc .dtpl/dtpl.ts --outDir .dtpl/", 15 | "watch": "tsc -w .dtpl/dtpl.ts --outDir .dtpl/" 16 | }, 17 | "devDependencies": { 18 | "lerna": "^2.7.1", 19 | "typescript": "^2.7.0", 20 | "types-dot-template": "^0.2.5" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": false, 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "noLib": false, 19 | "rootDir": "src", 20 | "baseUrl": "src", 21 | 22 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 23 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 24 | "lib": [ 25 | "es5", 26 | "es2015.core", 27 | "es2015.symbol", 28 | "es2015.collection", 29 | "es2015.promise" 30 | ] 31 | }, 32 | "include": [ 33 | "src" 34 | ], 35 | "exclude": [ 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": false, 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "noLib": false, 19 | "rootDir": "src", 20 | "baseUrl": "src", 21 | 22 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 23 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 24 | "lib": [ 25 | "es5", 26 | "es2015.core", 27 | "es2015.symbol", 28 | "es2015.collection", 29 | "es2015.promise" 30 | ] 31 | }, 32 | "include": [ 33 | "src" 34 | ], 35 | "exclude": [ 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/ts/tsconfig.json.dtpl: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": false, 6 | "removeComments": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": false, 9 | "importHelpers": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitAny": true, 16 | "strict": true, 17 | "strictNullChecks": true, 18 | "noLib": false, 19 | "rootDir": "src", 20 | "baseUrl": "src", 21 | 22 | // 参考微信小程序公众平台的 "E6S支持情况 / 客户端ES6 API支持情况" 23 | // https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/details.html#%E5%AE%A2%E6%88%B7%E7%AB%AFes6-api-%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5 24 | "lib": [ 25 | "es5", 26 | "es2015.core", 27 | "es2015.symbol", 28 | "es2015.collection", 29 | "es2015.promise" 30 | ] 31 | }, 32 | "include": [ 33 | "src" 34 | ], 35 | "exclude": [ 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/__tests__/fixtures/b.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "comment": "b.xml" 4 | }, 5 | { 6 | "name": "view", 7 | "attrs": { 8 | "class": "container log-list" 9 | }, 10 | "children": [ 11 | { 12 | "name": "block", 13 | "attrs": { 14 | "wx:for": "{{logs}}", 15 | "wx:key": "i", 16 | "wx:for-item": "log" 17 | }, 18 | "children": [ 19 | { 20 | "name": "text", 21 | "attrs": { 22 | "class": "log-item" 23 | }, 24 | "children": [ 25 | { 26 | "content": "{{index + 1}}. {{log}}" 27 | } 28 | ] 29 | } 30 | ] 31 | }, 32 | { 33 | "name": "view", 34 | "children": [ 35 | { 36 | "content": "1" 37 | }, 38 | { 39 | "name": "text", 40 | "children": [ 41 | { 42 | "content": "2" 43 | } 44 | ] 45 | } 46 | ] 47 | } 48 | ] 49 | } 50 | ] 51 | -------------------------------------------------------------------------------- /packages/minapp-common/src/dev/config.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {ComponentAttr, Component} from './Component' 7 | 8 | export const JSON_REGEXP = /\.(?:json|cjson|jsonc)$/i 9 | 10 | export interface CustomAttr extends ComponentAttr { 11 | addBrace?: boolean // 是否加上 {{}} 12 | boolean?: boolean // 属性是个 boolean 值,不需要加 = 13 | } 14 | 15 | export interface LanguageConfig { 16 | id: string 17 | /** 基本属性 */ 18 | baseAttrs: CustomAttr[] 19 | /** 事件相关配置 */ 20 | event: { 21 | prefixes: string[] 22 | modifiers: string[] 23 | attrs: CustomAttr[] 24 | } 25 | /** 语言相关的 trigger */ 26 | custom: { 27 | [prefix: string]: { 28 | attrs: CustomAttr[] 29 | modifiers: string[] 30 | } 31 | }, 32 | /** 自定义的组件 */ 33 | components: Component[] 34 | 35 | /** 在自动补全时,不需要 baseAttrs 和 event 的组件名称 */ 36 | noBasicAttrsComponents?: string[] 37 | } 38 | 39 | -------------------------------------------------------------------------------- /docs-md/doc-data-bind.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 数据双向绑定 3 | --- 4 | 5 | 在 minapp 中使用数据双向绑定非常简单,只需要满足如下四个条件: 6 | 7 | 1. 父子组件都要继承自 `BaseComponent` 或 `BasePage` (使用 minapp 框架默认就满足此条件) 8 | 2. 组件更新数据时,不要使用 `setData`,而是使用 `setDataSmart` (更多详情请参考文档[如何在原生的小程中实现数据双向绑定](./doc-how-to-realize-two-way-data-bind.md)) 9 | 3. wxml 中绑定数据时使用 `.sync` 后缀,如 `` 10 | 4. 使用 `@minapp/cli` 编译项目(主要是需要 wxml 编译功能) 11 | 12 | ### Example: 13 | 14 | ```js 15 | // 子组件: toast 16 | import {BaseComponent, comify} from '@minapp/core' 17 | 18 | @comify() 19 | export default class extends BaseComponent { 20 | properties = { 21 | visible: { 22 | // 实现双向绑定,不需要在子组件中额外配置 23 | type: Boolean, 24 | value: false 25 | } 26 | } 27 | } 28 | 29 | ``` 30 | 31 | ```js 32 | // 父容器 33 | import {BasePage, pagify} from '@minapp/core' 34 | 35 | @pagify() 36 | export default class extends BasePage { 37 | data = { 38 | isToastVisible: false 39 | } 40 | 41 | toggleToast() { 42 | this.setDataSmart({isToastVisible: !this.data.isToastVisible}) 43 | } 44 | } 45 | ``` 46 | 47 | ```html 48 | 49 | 50 | 51 | 52 | ``` 53 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/js/.dtpl/dtpl.js.dtpl: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | module.exports = function (source) { 4 | return { 5 | templates: [ 6 | { 7 | // 当在 pages 目录下新建一个文件夹时,向这个文件夹内注入 .dtpl/page 下的文件 8 | matches: function () { return source.isDirectory && /^pages?$/.test(source.basicData.dirName); }, 9 | name: './page', 10 | inject: function () { 11 | let {rawModuleName, dirName, dirPath} = source.basicData 12 | let page = [dirName, rawModuleName, rawModuleName].join('/') 13 | 14 | // 向 app.cjson 中注入内容 15 | let appJson = path.resolve(dirPath, '..', 'app.cjson') 16 | 17 | return [ 18 | { file: appJson, data: { page: "\"" + page + "\"," }, tags: 'loose', append: true } 19 | ] 20 | } 21 | }, 22 | { 23 | // 当在 components 目录下新建一个文件夹时,向这个文件夹内注入 .dtpl/component 下的文件 24 | matches: function () { return source.isDirectory && /^components?$/.test(source.basicData.dirName); }, 25 | name: './component/' 26 | } 27 | ], 28 | globalData: { 29 | dollar: '$', 30 | style: '${style}' 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/pages/index/index.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, MyPage} from 'base/' 7 | 8 | // 把这个 class 转化成 微信的 Page 参数,并且注入全局 store 9 | @pagify() 10 | export default class extends MyPage { 11 | data = { 12 | count: 10, 13 | npmToast: false, 14 | demoToast: false, 15 | motto: '' 16 | } 17 | 18 | onShow() { 19 | /** 20 | * setDataSmart 和 setData 基本一样,但 setDataSmart 内部做过优化: 21 | * 22 | * 1. 支持双向绑定 23 | * 2. 页面隐藏是会缓存 data,等到页面显示的时候再 set 24 | */ 25 | this.setDataSmart({motto: 'See you again, Try to click me!'}) 26 | } 27 | 28 | gotoLogsPage() { 29 | // 跳转到 logs 页面 30 | this.app.$url.logs.go({id: 1}) 31 | this.setDataSmart({motto: '开始跳转到 logs 页面'}) 32 | } 33 | 34 | toggleDemoToast() { 35 | this.setDataSmart({demoToast: !this.data.demoToast}) 36 | } 37 | 38 | increase() { 39 | this.setDataSmart({count: this.data.count + 1}) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/pages/index/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, MyPage} from 'base/' 7 | 8 | // 把这个 class 转化成 微信的 Page 参数,并且注入全局 store 9 | @pagify() 10 | export default class extends MyPage { 11 | data = { 12 | count: 10, 13 | npmToast: false, 14 | demoToast: false, 15 | motto: '' 16 | } 17 | 18 | onShow() { 19 | /** 20 | * setDataSmart 和 setData 基本一样,但 setDataSmart 内部做过优化: 21 | * 22 | * 1. 支持双向绑定 23 | * 2. 页面隐藏是会缓存 data,等到页面显示的时候再 set 24 | */ 25 | this.setDataSmart({motto: 'See you again, Try to click me!'}) 26 | } 27 | 28 | gotoLogsPage() { 29 | // 跳转到 logs 页面 30 | this.app.$url.logs.go({id: 1}) 31 | this.setDataSmart({motto: '开始跳转到 logs 页面'}) 32 | } 33 | 34 | toggleDemoToast() { 35 | this.setDataSmart({demoToast: !this.data.demoToast}) 36 | } 37 | 38 | increase() { 39 | this.setDataSmart({count: this.data.count + 1}) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{userInfo.nickName}} 7 | 8 | 9 | 10 | {{motto}} 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 双向绑定: 23 | 单向绑定: 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/minapp-mobx/src/lib/MobxComponent.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as core from '@minapp/core/system' 7 | 8 | import {MobxStore} from './MobxStore' 9 | import {MobxApp} from './MobxApp' 10 | 11 | export interface ComifyOptions extends core.ComifyOptions { 12 | } 13 | 14 | /** 15 | * 将一个继承了 MobxComponent 的类转化成 小程序 Component 的调用 16 | */ 17 | export function comify>(options: ComifyOptions = {}) { 18 | return core.comify(options, obj => { 19 | obj.store = (getApp() as any).store 20 | }) 21 | } 22 | 23 | 24 | export class MobxComponent> extends core.BaseComponent { 25 | /** 26 | * 获取 app.store 对象 27 | * 28 | * @deprecated 直接使用 this.store 即可,无需使用函数调用 29 | */ 30 | getStore() { 31 | return this.getApp().store 32 | } 33 | 34 | /** 35 | * app.store 对象 36 | */ 37 | // @ts-ignore 38 | readonly store: S 39 | } 40 | -------------------------------------------------------------------------------- /website/sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "docs": { 3 | "入门指南": [ 4 | "doc-install", 5 | "doc-autocomplete", 6 | "doc-warn", 7 | "doc-difference-with-wepy", 8 | "doc-update-v1-to-v2" 9 | ], 10 | "基本功能": [ 11 | "doc-about-style", 12 | "doc-data-bind", 13 | "doc-use-setDataSmart-not-setData", 14 | "doc-about-json-file", 15 | "doc-require-other-files-in-script", 16 | "doc-custom-webpack", 17 | "doc-basic-code" 18 | ], 19 | "进阶功能": [ 20 | "doc-coding-rule", 21 | "doc-about-page", 22 | "doc-about-component", 23 | "doc-how-to-use-wxp-in-other-project", 24 | "doc-how-to-realize-two-way-data-bind", 25 | "doc-attention-on-build" 26 | ] 27 | }, 28 | "api": { 29 | "minapp 1.x": [ 30 | "api-index" 31 | ], 32 | "@minapp/core": [ 33 | "api-core-wxp", 34 | "api-core-BaseApp", 35 | "api-core-BasePage", 36 | "api-core-BaseComponent", 37 | "api-core-Url", 38 | "api-core-Location"], 39 | "@minapp/mobx": [ 40 | "api-mobx-MobxApp", 41 | "api-mobx-MobxPage", 42 | "api-mobx-MobxComponent", 43 | "api-mobx-MobxStore" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs-md/api-core-wxp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: wxp 3 | --- 4 | 5 | 6 | ### `wxp` 是官方 `wx` 接口的 promise 化的版本 7 | 8 | * `wx` 上所有接口都能在 `wxp` 上找到 9 | * `wxp` 会将 `wx` 接口中需要提供 `success/fail/complete` 回调函数的所有接口 promise 化 10 | * 为了和 `wx` 接口兼容,你也可以在 `wxp` 中使用 `success/fail/complete` 回调函数 11 | * `wxp` 也给 `Promise` 注入了一个 `finally` 方法,类似于 `complete` 函数 12 | 13 | ### 调用方法 14 | 15 | ```js 16 | import {wxp} from '@minapp/core' 17 | ``` 18 | 19 | 20 | 21 | ### 示例 22 | 23 | 1. 在 async/await 中使用 24 | 25 | ```js 26 | async onLoad() { 27 | let res = await wxp.getUserInfo() 28 | } 29 | ``` 30 | 31 | 2. 原生 Promise 32 | 33 | ```js 34 | onLoad() { 35 | wxp.getUserInfo() 36 | .then(res => { 37 | // 处理结果 38 | }) 39 | .catch(e => { 40 | // 处理错误 41 | }) 42 | .finally(() => { 43 | // 请求完成 44 | }) 45 | } 46 | ``` 47 | 48 | 3. 像 wx 一样使用 49 | 50 | ```js 51 | wxp.getUserInfo({ 52 | success() { 53 | 54 | }, 55 | fail() { 56 | 57 | }, 58 | complete() { 59 | 60 | } 61 | }) 62 | ``` 63 | 64 | 65 | > 源代码: [wxp](https://github.com/qiu8310/minapp/blob/master/packages/minapp-wx/src/wxp.ts) 66 | -------------------------------------------------------------------------------- /minapp.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | }, 6 | { 7 | "path": "packages/minapp-core" 8 | }, 9 | { 10 | "path": "packages/minapp-wxml-parser" 11 | }, 12 | { 13 | "path": "packages/minapp-common" 14 | }, 15 | { 16 | "path": "packages/minapp-cli" 17 | }, 18 | { 19 | "path": "packages/minapp-mobx" 20 | }, 21 | { 22 | "path": "packages/minapp-example-core-ts" 23 | }, 24 | { 25 | "path": "packages/minapp-example-core-js" 26 | }, 27 | { 28 | "path": "packages/minapp-example-mobx-ts" 29 | }, 30 | { 31 | "path": "packages/minapp-example-mobx-js" 32 | } 33 | ], 34 | "settings": { 35 | "dot-template-vscode.debug": false, 36 | "dot-template-vscode.watchFilesGolbPattern": "**/src/**", 37 | "jsDocCompletion.enabled": false, 38 | "files.exclude": { 39 | "**/dist": false, 40 | "**/packages": true, 41 | "**/.git": true, 42 | "**/.svn": true, 43 | "**/.hg": true, 44 | "**/CVS": true, 45 | "**/.DS_Store": true 46 | }, 47 | "typescript.tsdk": "wxapp/node_modules/typescript/lib" 48 | }, 49 | "extensions": { 50 | "recommendations": [ 51 | "qiu8310.dot-template-vscode", 52 | "qiu8310.minapp-vscode" 53 | ] 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/minapp-mobx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/mobx", 3 | "description": "微信小程序框架", 4 | "version": "2.2.0", 5 | "main": "dist/index.js", 6 | "typings": "dist/index.d.ts", 7 | "scripts": { 8 | "test": "echo 0", 9 | "lint": "tslint src/**/*.ts", 10 | "postpublish": "sync-taobao", 11 | "clear": "remove-all dist", 12 | "build": "npm run clear && tsc", 13 | "watch": "tsc -w" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "license": "MIT", 19 | "author": "Mora (https://github.com/qiu8310)", 20 | "bugs": "https://github.com/qiu8310/minapp/issues", 21 | "homepage": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-mobx", 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-mobx" 25 | }, 26 | "peerDependencies": { 27 | "mobx": ">= 3.0.0 < 4.0.0" 28 | }, 29 | "dependencies": { 30 | "@minapp/core": "^2.0.0", 31 | "tslib": "^1.9.0" 32 | }, 33 | "devDependencies": { 34 | "@types/debug": "^0.0.30", 35 | "@types/jest": "^22.1.3", 36 | "jest": "^22.1.4", 37 | "mobx": "^3.5.1", 38 | "mora-scripts": "^1.6.28", 39 | "ts-jest": "^22.0.2", 40 | "ts-lint": "^4.5.1", 41 | "typescript": "^2.7.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [], 4 | "rules": { 5 | "quotemark": [true, "single", "jsx-single"], 6 | "semicolon": [true, "never"], 7 | "member-access": false, 8 | "member-ordering": false, 9 | "new-parens": true, 10 | "no-arg": true, 11 | "no-bitwise": true, 12 | "no-reference": false, 13 | "no-conditional-assignment": true, 14 | "no-empty-interface": false, 15 | "interface-name": [false], 16 | "no-var-requires": false, 17 | "no-debugger": false, 18 | "variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case", "allow-leading-underscore"], 19 | "no-unused-variable": true, 20 | "no-unused-expression": true, 21 | "no-var-keyword": true, 22 | "prefer-for-of": false, 23 | 24 | "no-console": [false], 25 | "prefer-const": [false], 26 | "max-line-length": [false], 27 | "object-literal-sort-keys": false, 28 | "max-classes-per-file": [false], 29 | 30 | "curly": false, 31 | "no-empty": false, 32 | "arrow-parens": [false], 33 | "ban-types": [false], 34 | "ordered-imports": [false], 35 | "trailing-comma": [false], 36 | "only-arrow-functions": [false], 37 | "no-consecutive-blank-lines": [true, 2] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/app.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {appify, wxp, MyApp, MyStore} from 'base/' 7 | 8 | @appify(new MyStore(), {pages: require('./app.cjson?pages'), tabBarList: require('./app.cjson?tabBar.list')}) 9 | export default class extends MyApp { 10 | async onLaunch() { 11 | // 展示本地存储能力 12 | let logs = wxp.getStorageSync('logs') || [] 13 | logs.unshift(Date.now()) 14 | wxp.setStorageSync('logs', logs) 15 | 16 | // 登录 17 | let {code} = await wxp.login() 18 | console.log('微信 code %o', code) // 发送 code 到后台换取 openId, sessionKey, unionId 19 | 20 | // 获取用户信息 21 | let setting = await wxp.getSetting() 22 | if (setting.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 23 | // 可以将 getUserInfo 返回的对象发送给后台解码出 unionId 24 | let res = await wxp.getUserInfo() 25 | console.log('微信 userInfo %o', res.userInfo) 26 | this.store.userInfo = res.userInfo // 将用户信息存入 store 中 27 | } else { 28 | console.log('没有授权过') 29 | } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/app.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {appify, wxp, MyApp, MyStore} from 'base/' 7 | 8 | @appify(new MyStore(), {pages: require('./app.cjson?pages'), tabBarList: require('./app.cjson?tabBar.list')}) 9 | export default class extends MyApp { 10 | async onLaunch() { 11 | // 展示本地存储能力 12 | let logs = wxp.getStorageSync('logs') || [] 13 | logs.unshift(Date.now()) 14 | wxp.setStorageSync('logs', logs) 15 | 16 | // 登录 17 | let {code} = await wxp.login() 18 | console.log('微信 code %o', code) // 发送 code 到后台换取 openId, sessionKey, unionId 19 | 20 | // 获取用户信息 21 | let setting = await wxp.getSetting() 22 | if (setting.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 23 | // 可以将 getUserInfo 返回的对象发送给后台解码出 unionId 24 | let res = await wxp.getUserInfo() 25 | console.log('微信 userInfo %o', res.userInfo) 26 | this.store.userInfo = res.userInfo // 将用户信息存入 store 中 27 | } else { 28 | console.log('没有授权过') 29 | } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/plugin/WriteFile.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as fs from 'fs-extra' 7 | import * as path from 'path' 8 | import * as webpack from 'webpack' 9 | import {createHash} from 'crypto' 10 | 11 | import {Env} from '../../config/env' 12 | 13 | export class WriteFile { 14 | private sourceMap: any = {} 15 | 16 | constructor(public env: Env) {} 17 | apply(compiler: webpack.Compiler) { 18 | compiler.hooks.afterEmit.tapPromise('WriteFile', async (compilation: webpack.compilation.Compilation) => { 19 | Object.keys(compilation.assets).forEach(key => { 20 | let source = compilation.assets[key].source() 21 | 22 | let sourceHash = createHash('sha256').update(source).digest('hex') 23 | if (this.sourceMap[key] !== sourceHash) { 24 | this.sourceMap[key] = sourceHash 25 | 26 | let file = path.join(this.env.distDir, key) 27 | fs.ensureDirSync(path.dirname(file)) 28 | fs.writeFileSync(file, source) 29 | } 30 | }) 31 | }) 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/app.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {appify, wxp, MyApp} from 'base/' 7 | 8 | @appify({pages: require('./app.cjson?pages'), tabBarList: require('./app.cjson?tabBar.list')}) 9 | export default class extends MyApp { 10 | async onLaunch() { 11 | // 展示本地存储能力 12 | let logs = wxp.getStorageSync('logs') || [] 13 | logs.unshift(Date.now()) 14 | wxp.setStorageSync('logs', logs) 15 | 16 | // 登录 17 | let {code} = await wxp.login() 18 | console.log('微信 code %o', code) // 发送 code 到后台换取 openId, sessionKey, unionId 19 | 20 | 21 | // require 图片链接 22 | console.log('使用 require(image) 来获取图片链接 %o', require('./images/heart@3x.png')) 23 | 24 | // 获取用户信息 25 | let setting = await wxp.getSetting() 26 | if (setting.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 27 | // 可以将 getUserInfo 返回的对象发送给后台解码出 unionId 28 | let res = await wxp.getUserInfo() 29 | console.log('微信 userInfo %o', res.userInfo) 30 | } else { 31 | console.log('没有获取到 userInfo,因为没有授权过') 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /docs/img/language.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/app.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {appify, wxp, MyApp} from 'base/' 7 | 8 | @appify({pages: require('./app.cjson?pages'), tabBarList: require('./app.cjson?tabBar.list')}) 9 | export default class extends MyApp { 10 | async onLaunch() { 11 | // 展示本地存储能力 12 | let logs = wxp.getStorageSync('logs') || [] 13 | logs.unshift(Date.now()) 14 | wxp.setStorageSync('logs', logs) 15 | 16 | // 登录 17 | let {code} = await wxp.login() 18 | console.log('微信 code %o', code) // 发送 code 到后台换取 openId, sessionKey, unionId 19 | 20 | 21 | // require 图片链接 22 | console.log('使用 require(image) 来获取图片链接 %o', require('./images/heart@3x.png')) 23 | 24 | // 获取用户信息 25 | let setting = await wxp.getSetting() 26 | if (setting.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 27 | // 可以将 getUserInfo 返回的对象发送给后台解码出 unionId 28 | let res = await wxp.getUserInfo() 29 | console.log('微信 userInfo %o', res.userInfo) 30 | } else { 31 | console.log('没有获取到 userInfo,因为没有授权过') 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/minapp-build.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {cli, compiler} from './base' 7 | 8 | export const buildOptions: cli.Options = { 9 | 'srcDir': ' specify code source directory {{"src"}}', 10 | 'distDir': ' specify build files directory {{"dist"}}', 11 | 'pretty': ' do not minimize source code', 12 | 'p | publicPath': ' static file\'s publicPath, just like `output.publicPath` in webpack', 13 | 'w | watch': ' watch mode, without webpack-dev-server', 14 | 'e | empty': ' empty distDir before compile', 15 | } 16 | 17 | /** 18 | * @param res 命令行的参数(由 cli 脚本生成) 19 | */ 20 | export function buildCommand(res: cli.Response) { 21 | 22 | process.env.NODE_ENV = 'production' 23 | if (res.srcDir) process.env.MINAPP_SRC_DIR = res.srcDir 24 | if (res.distDir) process.env.MINAPP_DIST_DIR = res.distDir 25 | if (res.pretty) process.env.MINAPP_PRETTY = 'true' 26 | if (res.publicPath) process.env.MINAPP_PUBLIC_PATH = res.publicPath 27 | 28 | compiler(res.watch, null, {empty: res.empty}) 29 | } 30 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/README.md.dtpl: -------------------------------------------------------------------------------- 1 | ## minapp 开发简易手册 2 | 3 | ### 开发环境 4 | 5 | * vscode 用户 6 | - 安装插件 [minapp](https://marketplace.visualstudio.com/items?itemName=qiu8310.minapp-vscode):提供 wxml 的语法高亮和自动补全功能 7 | - 安装插件 [dot-template](https://marketplace.visualstudio.com/items?itemName=qiu8310.dot-template-vscode):提供快速创建模板文件功能 8 | 9 | * 非 vscode 用户 10 | - wxml 插件功能暂时无法提供,你可以搜索对应插件市场是否有类似插件 11 | - 模板文件可以通过安装 `npm i -g dot-template-cli`,并在 `@minapp/cli` 创建的项目根目录下执行 `dtpl watch` 命令,即可实现 vscode 插件 dot-template 类似的功能 12 | 13 | ### 注意事项 14 | 15 | 1. `.cjson` 后缀的文件表示的是带注释的 json 文件,你可以在 vscode 中配置文件关联(minapp 项目中的 json 文件都支持带注释) 16 | 2. 由于微信原生 api 并不支持 class,所以除 `Store` 外,`App`,`Component` 和 `Page` 相关的类都要遵循下面的约束: 17 | 18 | * **不要在 class 的类方法中使用箭头函数,但可以在类方法内部使用(主要因为箭头函数将 this 绑定死了 Class,无法转到 Object 上)** 19 | 20 | 不可以这样用: 21 | ```ts 22 | class MyPage extends BasePage { 23 | foo = () => this.app 24 | } 25 | ``` 26 | 27 | 可以这样用: 28 | ```ts 29 | class MyPage extends BasePage { 30 | foo() { 31 | someArr.forEach(() => {}) 32 | } 33 | } 34 | ``` 35 | 36 | * **最好不要使用 `get prop() {}`,@minapp/mobx 框架支持,但微信内部会遍历 Object 中的属性的值,所以你的 prop 在 Page 还没初始化前就会被调用,有可能会导致错误** 37 | 38 | 最好不要这样用: 39 | ```ts 40 | class MyPage extends BasePage { 41 | get foo() { 42 | return this.something 43 | } 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /docs-md/doc-about-page.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 关于 Page 3 | --- 4 | 5 | * 默认情况下,mobx 项目的所有的 page 都会自动监听全局 store 的变化,可以设置 observe 来禁用: 6 | 7 | ```js 8 | import {MobxPage} from '@minapp/mobx' 9 | // 在 page 中禁用 10 | @pagify({observe: false}) 11 | export MyPage extends MobxPage { 12 | 13 | } 14 | ``` 15 | 16 | * 默认情况下,如果启用了 observe,会将所有的 store 中的属性注入到 data 中,可能会和你自己定义的数据冲突, 17 | 或者你只想监听 store 中的某个字段,你可以这样做: 18 | 19 | ```js 20 | @pagify({mapStoreToData: (store) => { 21 | return { 22 | newKey: store.oldKey 23 | } 24 | }}) 25 | export MyPage extends MobxPage { 26 | 27 | } 28 | ``` 29 | 30 | * 不用担心使用了全局对象会造成 page 的频繁更新,当你使用 `setDataSmart` 时,当页面处于 hide 31 | 状态时,并不会真正更新隐藏的页面数据,而等到页面 show 后,会统一更新页面数据。 32 | 33 | 如果不想要此功能,可以设置 `lazySetData` 为 false 来禁用此功能 34 | 35 | ```js 36 | @pagify({lazySetData: false}) 37 | export MyPage extends MobxPage { 38 | 39 | } 40 | ``` 41 | 42 | * 使用 mixin 扩展组件功能 43 | 44 | 如 [编码准则](./doc-coding-rule.md) 中所述,框架中的 App,Page,Component 的子类并不是完整的 class,有一些 class 45 | 的功能你不能使用,但你可以使用下面的 mixin 来实现你需要的功能 46 | 47 | ```js 48 | const mixins = [ 49 | { 50 | onLoad() { 51 | console.log('in mixin') 52 | } 53 | } 54 | ] 55 | 56 | @pagify({mixins}) 57 | export MyPage extends MobxPage { 58 | onLoad() { 59 | console.log('in page') 60 | } 61 | } 62 | ``` 63 | 64 | 上面两个 onLoad 都会执行,**注意:mixins 必须保证函数的执行顺序是无关的** 65 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/minapp-attrs.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as fs from 'fs-extra' 7 | import {sys, cli} from './base' 8 | import {getComponentJson} from '../base/helper' 9 | import {parseAttrs} from '@minapp/common/dist/parseAttrs' 10 | import * as DotProp from 'mora-scripts/libs/lang/DotProp' 11 | 12 | export const attrsOptions: cli.Options = { 13 | 14 | } 15 | 16 | /** 17 | * @param res 命令行的参数(由 cli 脚本生成) 18 | */ 19 | export function attrsCommand(res: cli.Response) { 20 | let minapp = require('../config/env').env.minapp 21 | if (!minapp.component) return sys.error('Not component develop environment') 22 | 23 | let {jsonFile, jsFile, jsContent, json} = getComponentJson(minapp.component) 24 | if (!jsonFile || !json || !jsFile || !jsContent) return sys.error('Can not found any component files') 25 | let attrs = parseAttrs(jsContent) 26 | if (!attrs.length) return sys.warn('Not found any component attrs in ' + jsFile) 27 | 28 | DotProp.set(json, 'minapp.component.attrs', attrs) 29 | console.log(`write component attrs: `) 30 | console.log(JSON.stringify(attrs, null, 2)) 31 | fs.writeFileSync(jsonFile, JSON.stringify(json, null, 2)) 32 | } 33 | -------------------------------------------------------------------------------- /packages/minapp-core/src/util/mixin.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {isObject} from './object' 7 | import {warn} from './warn' 8 | 9 | export function mixin(target: any, source: any[] | any) { 10 | let sources = Array.isArray(source) ? source : [source] 11 | 12 | sources.forEach(src => { 13 | if (!src || !isObject(src)) return 14 | Object.getOwnPropertyNames(src).forEach(name => { 15 | let srcDesc = Object.getOwnPropertyDescriptor(src, name) as PropertyDescriptor 16 | let distDesc = Object.getOwnPropertyDescriptor(target, name) 17 | 18 | if (!distDesc) { 19 | Object.defineProperty(target, name, srcDesc) 20 | } else { 21 | if (typeof distDesc.value === 'function' && typeof srcDesc.value === 'function') { 22 | Object.defineProperty(target, name, { 23 | ...distDesc, 24 | value() { 25 | (distDesc as any).value.apply(this, arguments) 26 | srcDesc.value.apply(this, arguments) 27 | } 28 | }) 29 | } else { 30 | warn(`无法将 %o 对象 mixin 到 %o 对象中,%o 字段值的类型不一致`, src, target, name) 31 | } 32 | } 33 | }) 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /packages/minapp-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/core", 3 | "version": "2.0.0", 4 | "description": "minapp 微信小程序的核心框架", 5 | "main": "system.js", 6 | "types": "system.d.ts", 7 | "scripts": { 8 | "test": "echo 0", 9 | "lint": "tslint src/**/*.ts", 10 | "postpublish": "sync-taobao", 11 | "bundle:pretty": "webpack --output-library-target commonjs system.js system.bundle.js", 12 | "bundle:minify": "webpack -p --output-library-target commonjs system.js system.bundle.min.js", 13 | "build": "tsc && npm run bundle:pretty && npm run bundle:minify", 14 | "watch": "tsc -w" 15 | }, 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "license": "MIT", 20 | "author": "Mora (https://github.com/qiu8310)", 21 | "bugs": "https://github.com/qiu8310/minapp/issues", 22 | "homepage": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-core", 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-core" 26 | }, 27 | "peerDependencies": { 28 | "@minapp/wx": "*" 29 | }, 30 | "devDependencies": { 31 | "@minapp/wx": "^2.0.0", 32 | "@types/fs-extra": "^5.0.0", 33 | "fs-extra": "^5.0.0", 34 | "mora-scripts": "^1.6.28", 35 | "ts-lint": "^4.5.1", 36 | "typescript": "^2.7.1", 37 | "webpack": "^3.11.0" 38 | }, 39 | "dependencies": { 40 | "tslib": "^1.9.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /website/pages/en/users.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | const React = require('react'); 9 | 10 | const CompLibrary = require('../../core/CompLibrary.js'); 11 | const Container = CompLibrary.Container; 12 | 13 | const siteConfig = require(process.cwd() + '/siteConfig.js'); 14 | 15 | class Users extends React.Component { 16 | render() { 17 | const showcase = siteConfig.users.map((user, i) => { 18 | return ( 19 | 20 | 21 | 22 | ); 23 | }); 24 | 25 | return ( 26 |
27 | 28 |
29 |
30 |

谁在使用这个项目?

31 |

下面这些人或组织在使用此项目

32 |
33 |
{showcase}
34 |

你在用这个项目吗?

35 | 38 | 快来添加 39 | 40 |
41 |
42 |
43 | ); 44 | } 45 | } 46 | 47 | module.exports = Users; 48 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/components/counter/counter.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MyComponent, comify} from 'base' 7 | 8 | @comify() 9 | export default class extends MyComponent { 10 | /** 11 | * 组件的属性列表 12 | */ 13 | properties = { 14 | start: { 15 | value: 0, 16 | type: Number 17 | } 18 | } 19 | 20 | /** 21 | * 组件的初始数据 22 | */ 23 | data = { 24 | 25 | } 26 | 27 | /** 28 | * 生命周期函数 29 | * 30 | * 原生的是 create,为了方便语法提醒,统一改成以 on 开头的函数 31 | */ 32 | onCreated() { 33 | console.log('组件 Created') 34 | } 35 | 36 | onReady() { 37 | console.log('在 counter 组件中获取 store: %o', this.store) 38 | } 39 | 40 | /** 41 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 42 | */ 43 | onPropUpdate(prop, newValue, oldValue) { 44 | console.log(`属性 ${prop} 从 ${oldValue} 更新到了 ${newValue}`) 45 | } 46 | 47 | /** 48 | * 自定义的函数,不需要放在 methods 中,在 comify 中会帮你提取出来放到 methods 49 | */ 50 | increase() { 51 | this.setDataSmart({start: this.data.start + 1}) 52 | } 53 | 54 | /** 55 | * 自定义的函数,不需要放在 methods 中,在 comify 中会帮你提取出来放到 methods 56 | */ 57 | decrease() { 58 | this.setDataSmart({start: this.data.start - 1}) 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /docs-md/doc-basic-code.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 基本代码 3 | --- 4 | 5 | 6 | **MyStore.js** 7 | 8 | ```js 9 | // MyStore.js 建一个 MobxStore 类 10 | 11 | import {MobxStore} from '@minapp/mobx' 12 | import {observable} from 'mobx' 13 | 14 | export class MyStore extends MobxStore { 15 | @observable userInfo = null 16 | } 17 | ``` 18 | 19 | 20 | **MyApp.js** 21 | 22 | ```js 23 | // MyApp.js 24 | import {MobxApp, MobxStore, appify, wxp} from '@minapp/mobx' 25 | import {MyStore} from './MyStore' 26 | 27 | // appify 主要是将 MyApp 转化成一个 PlainObject,并传入微信原生的函数 App 中;另外注入全局 store 和框架需要的数据 28 | @appify( 29 | new MyStore(), 30 | { 31 | // 下面两个参数主要是提供给 @minapp/mobx 框架使用,生成一个 $url 实例,让你可以方便的在 url 之间跳转 32 | pages: require('./app.json?pages'), // 获取 app.json 中的 pages 字段 33 | tabBarList: require('./app.json?tabBar.list') // 获取 app.json 中的 tabBar.list 字段 34 | } 35 | ) 36 | export class MyApp extends MobxApp { 37 | async onLoad() { 38 | this.store.userInfo = (await wxp.getUserInfo()).userInfo // 轻松修改全局数据 39 | } 40 | } 41 | ``` 42 | 43 | **IndexPage.js** 44 | 45 | ```js 46 | import {MobxPage, pagify} from '@minapp/mobx' 47 | 48 | // 类似于 appify,所有 Page 都需要调用 pagify; 49 | // 它会将 IndexPage 转化成 PlainObject,并传入微信原生的函数 App 中; 50 | // 另外会像这个对象中注入 app 实例和 app.store 对象 51 | @pagify() 52 | export class IndexPage extends MobxPage { 53 | onLoad() { 54 | // getUserInfo 是网络接口,所以当 indexPage 加载完的时候,app 中的接口不一定请求完了,所以要判断 55 | if (this.store.userInfo) { 56 | 57 | } 58 | } 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /packages/minapp-common/src/lib/CacheableFile.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {stat, readFile} from './fs' 7 | 8 | /** 9 | * 支持缓存的文件 10 | * 11 | * 避免频繁去读取文件系统 12 | * 13 | * @export 14 | * @class File 15 | */ 16 | export class CacheableFile { 17 | private ctime?: number 18 | private mtime?: number 19 | private cachedContent: Buffer | undefined 20 | /** 用于标识 getContent 是不是从 Cache 中取出的 */ 21 | public cached?: boolean 22 | 23 | constructor(private filepath: string) {} 24 | 25 | /** 26 | * 获取文件内容(如果文件没有更新过,优先使用缓存) 27 | * 28 | * @returns Promise 29 | * @memberof CacheableFile 30 | */ 31 | async getContent() { 32 | let stats = await stat(this.filepath) 33 | if (!stats.isFile()) throw new Error(`${this.filepath} is not a file`) 34 | 35 | let ctime = stats.ctime.getTime() 36 | let mtime = stats.mtime.getTime() 37 | 38 | if (!this.ctime || !this.mtime || !this.cachedContent || this.ctime !== ctime || this.mtime !== mtime) { 39 | this.ctime = ctime 40 | this.mtime = mtime 41 | this.cachedContent = await readFile(this.filepath) 42 | this.cached = false 43 | } else { 44 | this.cached = true 45 | } 46 | 47 | return this.cachedContent 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/minapp-dev.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {cli, compiler} from './base' 7 | import * as portscanner from 'portscanner' 8 | 9 | export const devOptions: cli.Options = { 10 | 'srcDir': ' specify code source directory {{"src"}}', 11 | 'distDir': ' specify build files directory {{"dist"}}', 12 | 'host': ' server host {{"localhost"}}', 13 | 'port': ' server port {{"8080"}}', 14 | 'e | empty': ' empty distDir before compile', 15 | } 16 | 17 | /** 18 | * @param res 命令行的参数(由 cli 脚本生成) 19 | */ 20 | export function devCommand(res: cli.Response) { 21 | // 写入域名相关信息 22 | let host = res.host || 'localhost' 23 | let rawPort = res.port || '8080' 24 | let intPort = parseInt(rawPort, 10) 25 | portscanner.findAPortNotInUse(intPort, intPort + 10, host, (err, port) => { 26 | if (err) return console.error(err) 27 | 28 | process.env.NODE_ENV = 'development' 29 | process.env.MINAPP_HOST = host 30 | process.env.MINAPP_PORT = port + '' 31 | if (res.srcDir) process.env.MINAPP_SRC_DIR = res.srcDir 32 | if (res.distDir) process.env.MINAPP_DIST_DIR = res.distDir 33 | 34 | compiler(false, {host, port}, {empty: res.empty}) 35 | }) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/base/webpack.minapp.js.dtpl: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 修改 loader 或 loader 配置 4 | */ 5 | module.exports.updateLoaders = function(loaders, env) { 6 | /** 修改 ts loader **/ 7 | // loaders.ts.loader = 'awesome-typescript-loader' // 使用本地的 awesome-typescript-loader 8 | // loaders.ts.options = {} // 修改配置 9 | 10 | 11 | /** 添加 postcss plugin **/ 12 | // loaders.postcss.options.plugins.push(/* your plugin */) 13 | 14 | 15 | /** 添加 babel plugin (ts 项目不会使用 babel-loader) **/ 16 | // loaders.babel.options.plugins.push(/* your plugin */) 17 | 18 | 19 | Object.assign(loaders.wxml.options, { 20 | // 更多 format 配置查看:https://github.com/qiu8310/minapp/blob/master/packages/minapp-wxml-parser/src/structs.ts#L7-L28 21 | format: { 22 | /** 是否删除注释,默认在 build 的时候会删除,dev 时候会保留 */ 23 | // removeComment: true, 24 | 25 | /** 26 | * 开启此项可以使的 text 标签内的文本不会做任何的修改; 27 | * 28 | * 默认如果标签内的文本内容比较少,会将它前后的空格去除, 29 | * 而如果标签内的文本内容很多时,会在它前后加上换行字符 30 | */ 31 | // reserveTags: ['text'] 32 | } 33 | }) 34 | 35 | /** 查看 loaders 结构 **/ 36 | // console.log(loaders) 37 | } 38 | 39 | 40 | 41 | /** 42 | * 修改 webpack 配置 43 | */ 44 | module.exports.webpack = function(wpConf, webpack, env) { 45 | // minapp build 时 env.mode 为 production 46 | // minapp dev 时 env.mode 为 development 47 | 48 | if (env.mode === 'production') { 49 | 50 | } else { 51 | 52 | } 53 | 54 | // env 中还有许多其它环境相关的变量,输出查看其结构 55 | // console.log(env) 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/.dtpl/dtpl.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | module.exports = function (source) { 4 | return { 5 | templates: [ 6 | { 7 | // 当在 pages 目录下新建一个文件夹时,向这个文件夹内注入 .dtpl/page 下的文件 8 | matches: function () { return source.isDirectory && /^pages?$/.test(source.basicData.dirName); }, 9 | name: './page', 10 | inject: function () { 11 | let {rawModuleName, dirName, dirPath} = source.basicData 12 | let page = [dirName, rawModuleName, rawModuleName].join('/') 13 | 14 | // 向 app.json 和 base/MyApp.ts 中注入内容 15 | let appJson = path.resolve(dirPath, '..', 'app.cjson') 16 | let MyAppTs = path.resolve(dirPath, '..', 'base', 'MyApp.ts') 17 | 18 | return [ 19 | { file: appJson, data: { page: "\"" + page + "\"," }, tags: 'loose', append: true }, 20 | { file: MyAppTs, data: { pagesMap: camelCase(rawModuleName) + ": Url" }, tags: 'loose', append: true }, 21 | ] 22 | } 23 | }, 24 | { 25 | // 当在 components 目录下新建一个文件夹时,向这个文件夹内注入 .dtpl/component 下的文件 26 | matches: function () { return source.isDirectory && /^components?$/.test(source.basicData.dirName); }, 27 | name: './component/' 28 | } 29 | ], 30 | globalData: { 31 | dollar: '$', 32 | style: 'css' 33 | } 34 | } 35 | } 36 | 37 | function camelCase(str) { return str.replace(/[-_](\w)/g, camelCaseReplacer) } 38 | function camelCaseReplacer(r, k) { return k.toUpperCase() } 39 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/postcss/px2rpx.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as postcss from 'postcss' 7 | 8 | interface Map { 9 | [key: string]: {rate: number, unit: string} 10 | } 11 | 12 | export function px2rpx(transformMap: {[key: string]: string} = {px: 'rpx'}) { 13 | let keys = Object.keys(transformMap) 14 | if (!keys.length) throw new Error(`postcss-px2rpx config error, nothing to transform`) 15 | 16 | let rateUnitRegExp = /^([\.\d]+)(\w+)$/ 17 | let map: Map = keys.reduce((res, key) => { 18 | let rate: number = 1 19 | let unit: string = transformMap[key] 20 | if (rateUnitRegExp.test(unit)) { 21 | rate = parseFloat(RegExp.$1) 22 | unit = RegExp.$2 23 | } 24 | res[key] = {rate, unit} 25 | return res 26 | }, {} as Map) 27 | 28 | let reg = new RegExp(`\\b((?:\\d*\\.)?\\d+)(${keys.join('|')})\\b`, 'g') 29 | 30 | return (root: postcss.Root, result: postcss.Result) => { 31 | root.walkDecls(decl => { 32 | let val = decl.value 33 | val = val.replace(reg, replacer) 34 | if (val !== decl.value) { 35 | decl.value = val 36 | } 37 | }) 38 | } 39 | 40 | function replacer(r: string, num: string, key: string) { 41 | return parseFloat(num) * map[key].rate + map[key].unit 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/minapp-cli/common/Application/ts/.dtpl/dtpl.js.dtpl: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | module.exports = function (source) { 4 | return { 5 | templates: [ 6 | { 7 | // 当在 pages 目录下新建一个文件夹时,向这个文件夹内注入 .dtpl/page 下的文件 8 | matches: function () { return source.isDirectory && /^pages?$/.test(source.basicData.dirName); }, 9 | name: './page', 10 | inject: function () { 11 | let {rawModuleName, dirName, dirPath} = source.basicData 12 | let page = [dirName, rawModuleName, rawModuleName].join('/') 13 | 14 | // 向 app.json 和 base/MyApp.ts 中注入内容 15 | let appJson = path.resolve(dirPath, '..', 'app.cjson') 16 | let MyAppTs = path.resolve(dirPath, '..', 'base', 'MyApp.ts') 17 | 18 | return [ 19 | { file: appJson, data: { page: "\"" + page + "\"," }, tags: 'loose', append: true }, 20 | { file: MyAppTs, data: { pagesMap: camelCase(rawModuleName) + ": Url" }, tags: 'loose', append: true }, 21 | ] 22 | } 23 | }, 24 | { 25 | // 当在 components 目录下新建一个文件夹时,向这个文件夹内注入 .dtpl/component 下的文件 26 | matches: function () { return source.isDirectory && /^components?$/.test(source.basicData.dirName); }, 27 | name: './component/' 28 | } 29 | ], 30 | globalData: { 31 | dollar: '$', 32 | style: '${style}' 33 | } 34 | } 35 | } 36 | 37 | function camelCase(str) { return str.replace(/[-_](\w)/g, camelCaseReplacer) } 38 | function camelCaseReplacer(r, k) { return k.toUpperCase() } 39 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/components/counter/counter.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MyComponent, comify} from 'base' 7 | 8 | @comify() 9 | export default class extends MyComponent { 10 | /** 11 | * 组件的属性列表 12 | */ 13 | properties = { 14 | number: { 15 | value: 0, 16 | type: Number 17 | } 18 | } 19 | 20 | /** 21 | * 组件的初始数据 22 | */ 23 | data: any = { 24 | 25 | } 26 | 27 | /** 28 | * 生命周期函数 29 | * 30 | * 原生的是 create,为了方便语法提醒,统一改成以 on 开头的函数 31 | */ 32 | onCreated() { 33 | 34 | } 35 | 36 | onReady() { 37 | console.log('在 counter 组件中获取 store: %o', this.store) 38 | } 39 | 40 | 41 | /** 42 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 43 | */ 44 | onPropUpdate(prop: string, newValue: any, oldValue: any) { 45 | console.log(`属性 ${prop} 从 %o 更新到了 %o`, oldValue, newValue) 46 | } 47 | 48 | /** 49 | * 自定义的函数,不需要放在 methods 中,在 comify() 执行过程中会帮你提取出来放到 methods 50 | */ 51 | increase() { 52 | // 支持双向绑定的数据需要使用 setDataSmart 来更新 53 | this.setDataSmart({number: this.data.number + 1}) 54 | } 55 | 56 | /** 57 | * 自定义的函数,不需要放在 methods 中,在 comify 中会帮你提取出来放到 methods 58 | */ 59 | decrease() { 60 | // 支持双向绑定的数据需要使用 setDataSmart 来更新 61 | this.setDataSmart({number: this.data.number - 1}) 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /packages/minapp-example-core-js/src/components/counter/counter.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MyComponent, comify} from 'base' 7 | 8 | @comify() 9 | export default class extends MyComponent { 10 | /** 11 | * 组件的属性列表 12 | */ 13 | properties = { 14 | number: { 15 | value: 0, 16 | type: Number 17 | } 18 | } 19 | 20 | /** 21 | * 组件的初始数据 22 | */ 23 | data = { 24 | 25 | } 26 | 27 | // 虽然是 Math.random(), 但所有此组件的此值都会是一样的, 因为组件只会初始化一次 28 | // 所以建议在 onCreated 中初化化组件的属性(也不要在 constructor 中初始化) 29 | prop = Math.random() 30 | 31 | /** 32 | * 生命周期函数 33 | * 34 | * 原生的是 create,为了方便语法提醒,统一改成以 on 开头的函数 35 | */ 36 | onCreated() { 37 | console.log('获取属性 prop: %o, 获取 app 实例: %o', this.prop, this.app) 38 | } 39 | 40 | /** 41 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 42 | */ 43 | onPropUpdate(prop, newValue, oldValue) { 44 | console.log(`属性 ${prop} 从 %o 更新到了 %o`, oldValue, newValue) 45 | } 46 | 47 | /** 48 | * 自定义的函数,不需要放在 methods 中,在 comify() 执行过程中会帮你提取出来放到 methods 49 | */ 50 | increase() { 51 | this.setDataSmart({number: this.data.number + 1}) 52 | } 53 | 54 | /** 55 | * 自定义的函数,不需要放在 methods 中,在 comify 中会帮你提取出来放到 methods 56 | */ 57 | decrease() { 58 | this.setDataSmart({number: this.data.number - 1}) 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /packages/minapp-example-core-ts/src/components/counter/counter.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {MyComponent, comify} from 'base' 7 | 8 | @comify() 9 | export default class extends MyComponent { 10 | /** 11 | * 组件的属性列表 12 | */ 13 | properties = { 14 | number: { 15 | value: 0, 16 | type: Number 17 | } 18 | } 19 | 20 | /** 21 | * 组件的初始数据 22 | */ 23 | data: any = { 24 | 25 | } 26 | 27 | // 虽然是 Math.random(), 但所有此组件的此值都会是一样的, 因为组件只会初始化一次 28 | // 所以建议在 onCreated 中初化化组件的属性(也不要在 constructor 中初始化) 29 | prop = Math.random() 30 | 31 | /** 32 | * 生命周期函数 33 | * 34 | * 原生的是 create,为了方便语法提醒,统一改成以 on 开头的函数 35 | */ 36 | onCreated() { 37 | console.log('获取属性 prop: %o, 获取 app 实例: %o', this.prop, this.app) 38 | } 39 | 40 | /** 41 | * 组件属性值有更新时会调用此函数,不需要在 properties 中设置 observer 函数 42 | */ 43 | onPropUpdate(prop: string, newValue: any, oldValue: any) { 44 | console.log(`属性 ${prop} 从 %o 更新到了 %o`, oldValue, newValue) 45 | } 46 | 47 | /** 48 | * 自定义的函数,不需要放在 methods 中,在 comify() 执行过程中会帮你提取出来放到 methods 49 | */ 50 | increase() { 51 | this.setDataSmart({number: this.data.number + 1}) 52 | } 53 | 54 | /** 55 | * 自定义的函数,不需要放在 methods 中,在 comify 中会帮你提取出来放到 methods 56 | */ 57 | decrease() { 58 | this.setDataSmart({number: this.data.number - 1}) 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /docs-md/doc-custom-webpack.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 自定义 webpack 配置 3 | --- 4 | 5 | 在根目录上使用文件 `webpack.minapp.js` 或 `webpack.minapp.ts`(如果使用了 ts,需要安装 `ts-node` 模块) 6 | 7 | **注意:** 8 | 9 | - minapp@v1 使用的是 webpack@3,所以请使用 webpack@3 相关的插件或配置 10 | - minapp@v2 使用的是 webpack@4,所以请使用 webpack@4 相关的插件或配置 11 | 12 | 如: 13 | 14 | ```js 15 | // webpack.minapp.js 16 | 17 | module.exports = function(webpackOpts, webpack, env) { 18 | // minapp build 时 env.mode 为 production 19 | // minapp dev 时 env.mode 为 development 20 | 21 | if (env.mode === 'production') { 22 | 23 | } else { 24 | 25 | } 26 | 27 | // env 中还有许多其它环境相关的变量,输出查看其结构 28 | // console.log(env) 29 | } 30 | ``` 31 | 32 | ```ts 33 | // webpack.minapp.ts 34 | 35 | export default function(webpackOpts: any, webpack: any, env: any) { 36 | // minapp build 时 env.mode 为 production 37 | // minapp dev 时 env.mode 为 development 38 | 39 | if (env.mode === 'production') { 40 | 41 | } else { 42 | 43 | } 44 | 45 | // env 中还有许多其它环境相关的变量,输出查看其结构 46 | // console.log(env) 47 | } 48 | 49 | ``` 50 | 51 | ### 另外 minapp v2 中,可以自定义修改 loader 或 loader 的配置,如: 52 | 53 | ```js 54 | module.exports.updateLoaders = function(loaders, env) { 55 | /** 修改 ts loader **/ 56 | loaders.ts.loader = 'awesome-typescript-loader' // 使用本地的 awesome-typescript-loader 57 | loaders.ts.options = {} // 修改配置 58 | 59 | 60 | /** 添加 postcss plugin **/ 61 | loaders.postcss.options.plugins.push(/* your plugin */) 62 | 63 | 64 | /** 添加 babel plugin (ts 项目不会使用 babel-loader) **/ 65 | loaders.babel.options.plugins.push(/* your plugin */) 66 | 67 | 68 | /** 查看 loaders 结构 **/ 69 | console.log(loaders) 70 | } 71 | ``` 72 | -------------------------------------------------------------------------------- /packages/minapp-common/src/hover.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {CustomOptions, getCustomComponents} from './custom' 7 | import {components, getComponentMarkdown, getComponentAttrMarkdown, ComponentAttr, LanguageConfig} from './dev' 8 | 9 | export async function hoverComponentMarkdown(tag: string, lc: LanguageConfig, co?: CustomOptions) { 10 | let comp = await getComponent(tag, lc, co) 11 | return comp ? getComponentMarkdown(comp) : undefined 12 | } 13 | 14 | export async function hoverComponentAttrMarkdown(tag: string, name: string, lc: LanguageConfig, co?: CustomOptions) { 15 | let comp = await getComponent(tag, lc, co) 16 | if (!comp) return 17 | let attrs = comp.attrs || [] 18 | 19 | let attr: ComponentAttr | undefined 20 | attrs.find(a => { 21 | if (a.name === name) { 22 | attr = a 23 | } else if (a.subAttrs) { 24 | a.subAttrs.some(s => s.attrs.some(sa => { 25 | if (sa.name === name) { 26 | attr = a 27 | } 28 | return !!attr 29 | })) 30 | } 31 | return !!attr 32 | }) 33 | 34 | return attr ? getComponentAttrMarkdown(attr) : undefined 35 | } 36 | 37 | async function getComponent(tagName: string, lc: LanguageConfig, co?: CustomOptions) { 38 | let comp = [...lc.components, ...components].find(c => c.name === tagName) 39 | if (!comp) { 40 | comp = (await getCustomComponents(co)).find(c => c.name === tagName) 41 | } 42 | return comp 43 | } 44 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/wxml-parser", 3 | "description": "微信小程序 wxml 解析器", 4 | "version": "2.1.5", 5 | "main": "dist/index.js", 6 | "typings": "dist/index.d.ts", 7 | "scripts": { 8 | "lint": "tslint src/**/*.ts", 9 | "test": "jest", 10 | "postpublish": "sync-taobao", 11 | "clear": "remove-all dist", 12 | "build": "npm run clear && tsc", 13 | "watch": "tsc -w" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "license": "MIT", 19 | "author": "Mora (https://github.com/qiu8310)", 20 | "bugs": "https://github.com/qiu8310/minapp/issues", 21 | "homepage": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-wxml-parser", 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-wxml-parser" 25 | }, 26 | "jest": { 27 | "roots": [ 28 | "src" 29 | ], 30 | "collectCoverage": true, 31 | "coverageReporters": [ 32 | "text", 33 | "html" 34 | ], 35 | "coveragePathIgnorePatterns": [ 36 | "/node_modules/", 37 | "/__tests__/helper/" 38 | ], 39 | "coverageDirectory": "./coverage", 40 | "transform": { 41 | "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" 42 | }, 43 | "testRegex": "(/__tests__/.*\\.(test|spec))\\.(ts|tsx)$", 44 | "moduleFileExtensions": [ 45 | "ts", 46 | "tsx", 47 | "js", 48 | "json" 49 | ] 50 | }, 51 | "dependencies": { 52 | "debug": "^3.1.0", 53 | "mora-scripts": "^1.6.28", 54 | "tslib": "^1.9.0" 55 | }, 56 | "devDependencies": { 57 | "@types/jest": "^22.1.3", 58 | "jest": "^22.1.4", 59 | "ts-jest": "^22.0.2", 60 | "ts-lint": "^4.5.1", 61 | "typescript": "^2.8.3" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/config/local.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as fs from 'fs-extra' 7 | import * as path from 'path' 8 | import * as webpack from 'webpack' 9 | import {Env} from './env' 10 | 11 | export interface ILocalConfig { 12 | webpack: (wpConf: webpack.Configuration, webpack: any) => webpack.Configuration 13 | updateLoaders: (loaders: T) => T 14 | } 15 | 16 | export function localConfig(env: Env): ILocalConfig { 17 | let mod: any 18 | 19 | if (fs.existsSync(path.join(env.rootDir, 'webpack.minapp.js'))) { 20 | mod = require(path.join(env.rootDir, 'webpack.minapp.js')) as any 21 | } else if (fs.existsSync(path.join(env.rootDir, 'webpack.minapp.ts'))) { 22 | require('ts-node/register') 23 | mod = require(path.join(env.rootDir, 'webpack.minapp.ts')) as any 24 | } 25 | 26 | if (!mod) mod = {} 27 | 28 | if (!mod.webpack) { 29 | if (typeof mod === 'function') mod.webpack = mod 30 | else if (typeof mod.default === 'function') mod.webpack = mod.default 31 | } 32 | 33 | return { 34 | webpack: (wpConf: webpack.Configuration, wp: any) => { 35 | let temp: webpack.Configuration | undefined 36 | if (typeof mod.webpack === 'function') temp = mod.webpack(wpConf, wp, env) 37 | return temp || wpConf 38 | }, 39 | updateLoaders: (map: T) => { 40 | let temp: T | undefined 41 | if (typeof mod.updateLoaders === 'function') temp = mod.updateLoaders(map, env) as any 42 | return temp || map 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {resolve, join} from 'path' 7 | import { Env } from '../config/env' 8 | export {ExtractMinappCode} from './plugin/ExtractMinappCode' 9 | export {WriteFile} from './plugin/WriteFile' 10 | export {RemoveLessCache} from './plugin/RemoveLessCache' 11 | 12 | // postcss plugins 13 | import {px2rpx} from './postcss/px2rpx' 14 | import * as autoprefixer from 'autoprefixer' 15 | 16 | let loaderDir = resolve(join(__dirname, 'loader')) 17 | 18 | function toLoader(key: string, options: {[key: string]: any} = {}) { 19 | return {loader: join(loaderDir, key), options} 20 | } 21 | 22 | export function getLoader(env: Env) { 23 | 24 | let {browsers, unitTransformer, json2sassPath} = env.minapp.compiler 25 | 26 | let plugins: any[] = [] 27 | if (Object.keys(unitTransformer).length) { 28 | plugins.push(px2rpx(unitTransformer)) 29 | } 30 | 31 | plugins.push(autoprefixer({ 32 | // https://github.com/ai/browserslist#queries 33 | browsers, 34 | remove: false, 35 | add: true 36 | })) 37 | 38 | return { 39 | json: toLoader('json-loader', {}), 40 | json2sass: toLoader('json2sass-loader', {path: json2sassPath}), 41 | js: toLoader('js-loader', {}), 42 | wxs: toLoader('wxs-loader', {}), 43 | wxml: toLoader('wxml-loader', {}), 44 | axml: toLoader('axml-loader', {}), 45 | pug: toLoader('pug-loader', {}), 46 | wxss: toLoader('wxss-loader', {}), 47 | acss: toLoader('acss-loader', {}), 48 | postcss: toLoader('postcss-loader', {plugins}), 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/minapp-mobx/src/lib/pollute.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as core from '@minapp/core/system' 7 | import {IReactionDisposer, toJS, autorun} from 'mobx' 8 | 9 | export interface PolluteOptions { 10 | /** 是否自动监听全局 store 的变化,默认为 true */ 11 | observe?: boolean 12 | /** 将 store 中的对象映射到当前组件的 data 中,不指定则全部会映射 */ 13 | mapStoreToData?: (storeData: any) => any 14 | } 15 | 16 | export function pollute(obj: any, init: string, destroy: string, options: PolluteOptions) { 17 | let app = getApp() as any 18 | 19 | if (options.observe !== false) { 20 | observe(obj, init, destroy, options.mapStoreToData) 21 | } 22 | 23 | obj.store = app.store || {} 24 | return obj 25 | } 26 | 27 | function observe(obj: Page.Options, init: string, destroy: string, mapStoreToData?: (storeData: any) => any) { 28 | let dispose: IReactionDisposer 29 | 30 | let mixin: any = {} 31 | mixin[init] = function() { 32 | dispose = autorun(() => { 33 | let data: any 34 | if (typeof mapStoreToData === 'function') { 35 | data = mapStoreToData(obj.store) 36 | } else { 37 | data = toJS(obj.store) as any 38 | if (data.__MOBX__) { 39 | delete data.constructor 40 | delete data.__MOBX__ 41 | } 42 | } 43 | this.setDataSmart(data) 44 | }) 45 | // @ts-ignore mobx 4 没有 onError 了,放在 autorun 配置中,但 4 之前 autorun 有个 scope 配置 46 | if (dispose.onError) dispose.onError(e => console.error(e)) 47 | } 48 | mixin[destroy] = function() { 49 | if (dispose) dispose() 50 | } 51 | 52 | core.util.mixin(obj, mixin) 53 | } 54 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-js/src/pages/index/index.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, wxp, MyPage} from 'base/' 7 | 8 | // 把这个 class 转化成 微信的 Page 参数,并且注入全局 store 9 | @pagify() 10 | export default class extends MyPage { 11 | data = { 12 | conterStart: 10, 13 | toastVisble: false, 14 | 15 | motto: '', 16 | canIUseOpenButton: wxp.canIUse('button.open-type.getUserInfo') 17 | } 18 | 19 | onShow() { 20 | this.setDataSmart({motto: 'Hello World'}) 21 | } 22 | 23 | onClickAvatarImage() { 24 | // 跳转到 logs 页面 25 | this.app.$url.logs.go({id: 1}) 26 | this.setDataSmart({motto: '开始跳转到 logs 页面'}) 27 | } 28 | 29 | onClickOpenButton(e) { 30 | // 轻松修改全局数据 31 | this.store.userInfo = e.detail.userInfo 32 | 33 | // 组件内数据还是用 setDataSmart 34 | this.setDataSmart({motto: '点击了『获取头像昵称』按钮'}) 35 | } 36 | 37 | showToast() { 38 | console.log('showToast') 39 | this.setDataSmart({toastVisble: true}) 40 | } 41 | hideToast() { 42 | console.log('hideToast') 43 | this.setDataSmart({toastVisble: false}) 44 | } 45 | 46 | increase() { 47 | this.setDataSmart({conterStart: this.data.conterStart + 1}) 48 | } 49 | 50 | async onLoad(options) { 51 | // 使用 require 加载图片 52 | console.log('可以使用 require 的方法加载图片: %o', require('images/heart@3x.png')) 53 | // 轻松读取全局数据 54 | console.log('当前 Store: %o', this.store) 55 | if (!this.store.userInfo && !this.data.canIUseOpenButton) { 56 | // 在没有 open-type=getUserInfo 版本的兼容处理 57 | let {userInfo} = await wxp.getUserInfo() 58 | this.store.userInfo = userInfo 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/bin/minapp-.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as cli from 'mora-scripts/libs/tty/cli' 7 | import {clearCommand, clearOptions} from './minapp-clear' 8 | import {initCommand, initOptions} from './minapp-init' 9 | import {devCommand, devOptions} from './minapp-dev' 10 | import {buildCommand, buildOptions} from './minapp-build' 11 | import {attrsCommand, attrsOptions} from './minapp-attrs' 12 | 13 | const pkg = require('../../package.json') 14 | require('update-notifier')({pkg}).notify() 15 | const version = false 16 | 17 | cli({ 18 | usage: 'minapp [options]', 19 | version: pkg.version 20 | }).commands({ 21 | 'clear': { 22 | cmd: clearCommand, 23 | conf: {version, usage: 'minapp clear [...directories]'}, 24 | desc: 'clear directories', 25 | options: clearOptions 26 | }, 27 | 'init': { 28 | cmd: initCommand, 29 | conf: {version, usage: 'minapp init '}, 30 | desc: 'init a project', 31 | options: 32 | initOptions 33 | }, 34 | 'dev': { 35 | cmd: devCommand, 36 | conf: {version}, 37 | desc: 'develop a preject, will inject a global variable: __ENV__="development"', 38 | options: devOptions 39 | }, 40 | 'build': { 41 | cmd: buildCommand, 42 | conf: {version}, 43 | desc: 'build a preject, will inject a global variable: __ENV__="production"', 44 | options: buildOptions 45 | }, 46 | 'attrs | component-attrs': { 47 | cmd: attrsCommand, 48 | conf: {version}, 49 | desc: 'generate component attributes description to component json file', 50 | options: attrsOptions 51 | }, 52 | }).parse((res, cli) => cli.help()) 53 | -------------------------------------------------------------------------------- /packages/minapp-cli/src/webpack/loader/json2sass-loader.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | const fs = require('fs') 6 | const path = require('path') 7 | import {Loader} from './Loader' 8 | 9 | @Loader.decorate 10 | export default class JsonLoader extends Loader { 11 | async run(content: string) { 12 | if (!this.lc.query.path) return content 13 | 14 | this.lc.cacheable() 15 | let contentPath = path.resolve(this.lc.query.path) 16 | this.lc.addDependency(contentPath) 17 | let obj = JSON.parse(fs.readFileSync(contentPath, 'utf8')) 18 | 19 | let sass = json2sass(obj) 20 | return sass ? sass + '\n' + content : content 21 | } 22 | } 23 | 24 | function json2sass(obj: any, indent?: number) { 25 | // Make object root properties into sass variables 26 | let sass = '' 27 | for (let key in obj) { 28 | if (obj.hasOwnProperty(key)) { 29 | sass += '$' + key + ': ' + JSON.stringify(obj[key], null, indent) + ';\n' 30 | } 31 | } 32 | if (!sass) return sass 33 | 34 | // Store string values (so they remain unaffected) 35 | let storedStrings: any[] = [] 36 | sass = sass.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g, function(str) { 37 | let id = '___JTS' + storedStrings.length 38 | storedStrings.push({id, value: str}) 39 | return id 40 | }) 41 | 42 | // Convert js lists and objects into sass lists and maps 43 | sass = sass.replace(/[{[]/g, '(').replace(/[}\]]/g, ')') 44 | 45 | // Put string values back (now that we're done converting) 46 | storedStrings.forEach(function(str) { 47 | str.value = str.value.replace(/["']/g, '') 48 | sass = sass.replace(str.id, str.value) 49 | }) 50 | 51 | return sass 52 | } 53 | -------------------------------------------------------------------------------- /packages/minapp-example-mobx-ts/src/pages/index/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {pagify, wxp, MyPage} from 'base/' 7 | 8 | // 把这个 class 转化成 微信的 Page 参数,并且注入全局 store 9 | @pagify() 10 | export default class extends MyPage { 11 | data = { 12 | count: 10, 13 | npmToast: false, 14 | demoToast: false, 15 | 16 | motto: '', 17 | canIUseOpenButton: wxp.canIUse('button.open-type.getUserInfo') 18 | } 19 | 20 | onShow() { 21 | this.setDataSmart({motto: 'See you again'}) 22 | } 23 | 24 | onClickAvatarImage() { 25 | // 跳转到 logs 页面 26 | this.app.$url.logs.go({id: 1}) 27 | this.setDataSmart({motto: '开始跳转到 logs 页面'}) 28 | } 29 | 30 | onClickOpenButton(e: any) { 31 | // 轻松修改全局数据 32 | this.store.userInfo = e.detail.userInfo 33 | 34 | // 组件内数据还是用 setData 35 | this.setDataSmart({motto: '点击了『获取头像昵称』按钮'}) 36 | } 37 | 38 | showToast() { 39 | console.log('showToast') 40 | this.setDataSmart({npmToast: true}) 41 | } 42 | hideToast() { 43 | console.log('hideToast') 44 | this.setDataSmart({npmToast: false}) 45 | } 46 | 47 | toggleDemoToast() { 48 | this.setDataSmart({demoToast: !this.data.demoToast}) 49 | } 50 | 51 | increase() { 52 | this.setDataSmart({count: this.data.count + 1}) 53 | } 54 | 55 | async onLoad(options: any) { 56 | // 使用 require 加载图片 57 | console.log('可以使用 require 的方法加载图片: %o', require('images/heart@3x.png')) 58 | // 轻松读取全局数据 59 | console.log('当前 Store: %o', this.store) 60 | if (!this.store.userInfo && !this.data.canIUseOpenButton) { 61 | // 在没有 open-type=getUserInfo 版本的兼容处理 62 | let {userInfo} = await wxp.getUserInfo() 63 | this.store.userInfo = userInfo 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /schema/page.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema", 3 | "description": "微信小程序 page.json 的 schema", 4 | "type": "object", 5 | "properties": { 6 | "usingComponents": { 7 | "type": "object" 8 | }, 9 | "navigationBarBackgroundColor": { 10 | "type": "string", 11 | "default": "#000000", 12 | "description": "导航栏背景颜色,HexColor" 13 | }, 14 | "navigationBarTextStyle": { 15 | "type": "string", 16 | "description": "导航栏标题颜色,仅支持 black/white", 17 | "default": "white", 18 | "enum": [ 19 | "white", "black" 20 | ] 21 | }, 22 | "navigationBarTitleText": { 23 | "type": "string", 24 | "description": "导航栏标题文字内容" 25 | }, 26 | "backgroundColor": { 27 | "type": "string", 28 | "default": "#ffffff", 29 | "description": "窗口的背景色, HexColor" 30 | }, 31 | "backgroundTextStyle": { 32 | "type": "string", 33 | "default": "dark", 34 | "enum": [ 35 | "dark", "light" 36 | ], 37 | "description": "下拉背景字体、loading 图的样式,仅支持 dark/light" 38 | }, 39 | "enablePullDownRefresh": { 40 | "type": "boolean", 41 | "default": false, 42 | "description": "是否开启下拉刷新" 43 | }, 44 | "onReachBottomDistance": { 45 | "type": "number", 46 | "default": 50, 47 | "description": "页面上拉触底事件触发时距页面底部距离,单位为px" 48 | }, 49 | "pageOrientation": { 50 | "type": "string", 51 | "description": "屏幕旋转设置,2.4.0 (auto) / 2.5.0 (landscape)", 52 | "default": "portrait", 53 | "enum": [ 54 | "auto", 55 | "portrait", 56 | "landscape" 57 | ] 58 | }, 59 | "disableScroll": { 60 | "type": "boolean", 61 | "description": "设置为 true 则页面整体不能上下滚动。 只在页面配置中有效", 62 | "default": false 63 | }, 64 | "disableSwipeBack": { 65 | "type": "boolean", 66 | "description": "禁止页面右滑手势返回,微信客户端 7.0.0", 67 | "default": false 68 | }, 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /packages/minapp-common/src/lib/ConditionalCacheableFile.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import {CacheableFile} from './CacheableFile' 7 | 8 | export class ConditionalCacheableFile { 9 | public filename?: string 10 | public cached?: boolean 11 | 12 | private cacheableFile?: CacheableFile 13 | private cachedParseContent?: any 14 | constructor(private getFilePathFn: () => string | undefined | Promise, private parseFileContent?: (filename: string, buffer: Buffer) => any) {} 15 | 16 | private async getFile() { 17 | let filepath = await this.getFilePathFn() 18 | this.cacheableFile = filepath ? new CacheableFile(filepath) : undefined 19 | this.filename = filepath 20 | return this.cacheableFile 21 | } 22 | 23 | private async tryGetFileContent() { 24 | let file = await this.getFile() 25 | return file ? (await file.getContent()) : undefined 26 | } 27 | 28 | async getContent() { 29 | this.cached = false 30 | let content: Buffer | undefined 31 | if (this.cacheableFile) { 32 | try { 33 | content = await this.cacheableFile.getContent() 34 | this.cached = this.cacheableFile.cached 35 | } catch (e) { 36 | if (e.code === 'ENOENT') { // 缓存的文件可能被删除了,重新获取 37 | content = await this.tryGetFileContent() 38 | } else { 39 | throw e 40 | } 41 | } 42 | } else { 43 | content = await this.tryGetFileContent() 44 | } 45 | 46 | if (content === undefined || !this.parseFileContent) return content 47 | 48 | if (!this.cached || this.cachedParseContent === undefined) { 49 | this.cachedParseContent = await this.parseFileContent(this.filename as string, content) 50 | } 51 | 52 | return this.cachedParseContent 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/minapp-common/src/__tests__/custom.test.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Mora (https://github.com/qiu8310) 4 | *******************************************************************/ 5 | 6 | import * as path from 'path' 7 | import {getCustomComponents, Component} from '../custom' 8 | 9 | const root = path.resolve(__dirname, 'fixtures', 'custom') 10 | const fixture = (key: string) => path.resolve(root, key) 11 | 12 | describe('basic', () => { 13 | test('should have no json', async () => { 14 | expect(await getComponents('no.js')).toEqual([]) 15 | }) 16 | test('should have component', async () => { 17 | expect(await getComponents('comp.js')).toEqual([]) 18 | }) 19 | test('should have usingComponents', async () => { 20 | let comps = await getComponents('using-comp.cjson') 21 | expect(comps).toHaveLength(3) 22 | expect(comps).toContainEqual({ name: 'no' }) 23 | expect(comps).toContainEqual({ name: 'xx' }) 24 | expect(comps).toContainEqual({ name: 'comp', desc: ['test desc'] }) 25 | }) 26 | }) 27 | 28 | describe('complex', () => { 29 | test('should not die when circle usingComponents', async () => { 30 | let json1 = await getComponents('circle1.json') 31 | let json2 = await getComponents('circle2.json') 32 | expect(json1).toEqual([ { name: 'circle2' } ]) 33 | expect(json2).toEqual([ { name: 'circle1' } ]) 34 | }) 35 | 36 | test('should support alias and resolves', async () => { 37 | let comps = await getComponents('alias.json', [path.dirname(root)]) 38 | expect(comps).toHaveLength(3) 39 | expect(comps).toContainEqual({ name: 'comp3' }) 40 | expect(comps).toContainEqual({ name: 'comp2', desc: ['this is test'] }) 41 | expect(comps).toContainEqual({ name: 'comp', desc: ['test desc'] }) 42 | }) 43 | }) 44 | 45 | 46 | function getComponents(key: string, resolves: string[] = []): Promise { 47 | return getCustomComponents({filename: fixture(key), resolves}) 48 | } 49 | -------------------------------------------------------------------------------- /website/blog/2018-03-05-redefine-2.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 重新定义小程序开发 — 框架篇 3 | author: Mora 4 | authorURL: https://github.com/qiu8310 5 | --- 6 | 7 | > 在 [补全篇](/minapp/blog/2018/03/03/redefine-1.html) 中,主要介绍了 minapp 是如何实现各类语言的自动补全的,这一篇主要介绍使用 `@minapp/core` 开发框架。 8 | 9 | 10 | 11 | 小程序开发中,JS 中主要有三大模块:App、Page、Component。 12 | 在 `@minapp/core` 中,用 class 和对应的装饰器函数对它们进行封装了。如: 13 | class `BaseApp` 和 装饰器函数 `appily` 可以创建出一个小程序的 App。 14 | 15 | ```js 16 | import {BaseApp, appily} from '@minapp/core' 17 | 18 | @appily({/* 这是是配置 */}) 19 | class MyApp extends BaseApp {} 20 | ``` 21 | 22 | 同理,`BasePage` 和 `pagily` 对应于小程序的 Page; 23 | `BaseComponent` 和 `comily` 对应于小程序的 Component。 24 | 其中,`appily`、`pagily` 和 `comily` 主要是将 class 转化成 object,并调用对应的小程序的全局函数 `App`,`Page` 和 `Component`。 25 | 所以,被装饰器装饰过的类,不能再被继承。如,下面的写法是**不对的**: 26 | 27 | ```js 28 | @pagily() 29 | class ParentPage extends BasePage {} 30 | 31 | // 下面写法错了 32 | // ParentPage 将无法再被继承了,它实际上只是一个微信原生的 Page 函数调用 33 | class ChildPage extends ParentPage { 34 | 35 | } 36 | ``` 37 | 38 | **本来只是一个函数的调用,现在确需要写一个类和装饰器两部分,这样写的优势到底在哪里?** 39 | 40 | 1. 避免暴露全局函数:微信将它的 `App()`、`Page()`、`Component()` 全都暴露在全局中,而 `@minapp/core` 将它的这些类和装饰器都放在模块中,需要引入才能使用 41 | 2. 利用类的继承原理,可以赋予对应类更多的功能:比如,实现双向绑定就给 Page 和 Component 中注入了不少函数 42 | 3. 装饰器函数可以给使用者个性化定制的机会:可以在装饰器中可以传入 mixins 配置,另外在 @minapp/mobx 中还可以传入 store 及定制监听 43 | 4. 扩展更方便:如 @minapp/mobx 是对 `@minapp/core` 的一个扩展,它支持全局的数据管理;如果可能,以后可能还会有更多的类似框架,如 @minapp/redux ... 44 | 5. 更好的自动补全:由于是基于 class,所以在编辑器中,可以有更好的自动补全体验 45 | 46 | 当然这样写也有一个致命的缺点:由于这你写的虽然是个类,但最后这个类会转化成一个 Object, 47 | 所有类上的方法都会重新绑定到那个 Object 上,所以在写类上的方法的时候, 48 | 有些东西是不能写的,可以参考[这里](/minapp/docs/doc-coding-rule.html) 49 | 50 | **最后,要说下用 `@minapp/core` 框架去开发小程序的一个最佳实践:** 51 | 52 | 当你安装了 `@minapp/cli` 后,用它 `minapp init` 创建的项目中,都会有一个 `src/base` 文件夹, 53 | 在文件夹类,定义了你自己的基类 `MyApp`,`MyPage`,`MyComponent`,它们分别继承了 `@minapp/core` 54 | 中定义的类;而在实际的页面或组件中,都继承你自己的基类,而不是 `@minapp/core` 中的基类。 55 | 56 | 这样写的好处是,你可以轻松的给你的 Page 或 Component 添加一些全局的新功能, 57 | 比如,你可以像 @minapp/mobx 中那样,在基类中实现一个你自己的全局状态管理的功能; 58 | 另外,如果你是用 TypeScript 写的话,它还可以跨类感知到你定义的这些新功能, 59 | 如,在 `SomePage` 中可以感知到你的 `MyApp` 中定义的所有方法和属性。 60 | -------------------------------------------------------------------------------- /packages/minapp-wxml-parser/src/__tests__/fixtures/a.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "comment": "a.xml" 4 | }, 5 | { 6 | "name": "view", 7 | "attrs": { 8 | "class": "container" 9 | }, 10 | "children": [ 11 | { 12 | "name": "view", 13 | "attrs": { 14 | "class": "userinfo" 15 | }, 16 | "children": [ 17 | { 18 | "name": "button", 19 | "attrs": { 20 | "wx:if": "{{!hasUserInfo && canIUse}}", 21 | "open-type": "getUserInfo", 22 | "bindgetuserinfo": "getUserInfo" 23 | }, 24 | "children": [ 25 | { 26 | "content": "获取头像昵称" 27 | } 28 | ] 29 | }, 30 | { 31 | "name": "block", 32 | "attrs": { 33 | "wx:else": true 34 | }, 35 | "children": [ 36 | { 37 | "name": "image", 38 | "attrs": { 39 | "bindtap": "bindViewTap", 40 | "class": "userinfo-avatar", 41 | "src": "../../images/heart.copy@3x.png", 42 | "background-size": "cover" 43 | } 44 | }, 45 | { 46 | "name": "text", 47 | "attrs": { 48 | "class": "userinfo-nickname" 49 | }, 50 | "children": [ 51 | { 52 | "content": "{{userInfo.nickName}}" 53 | } 54 | ] 55 | } 56 | ] 57 | } 58 | ] 59 | }, 60 | { 61 | "name": "view", 62 | "attrs": { 63 | "class": "usermotto" 64 | }, 65 | "children": [ 66 | { 67 | "name": "text", 68 | "attrs": { 69 | "class": "user-motto" 70 | }, 71 | "children": [ 72 | { 73 | "content": "{{motto}}" 74 | } 75 | ] 76 | } 77 | ] 78 | } 79 | ] 80 | } 81 | ] 82 | -------------------------------------------------------------------------------- /website/i18n/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment": "This file is auto-generated by write-translations.js", 3 | "localized-strings": { 4 | "next": "Next", 5 | "previous": "Previous", 6 | "tagline": "重新定义微信小程序的开发", 7 | "api-core-BaseApp": "BaseApp", 8 | "api-core-BaseComponent": "BaseComponent", 9 | "api-core-BasePage": "BasePage", 10 | "api-core-Location": "Location", 11 | "api-core-Url": "Url", 12 | "api-core-wxp": "wxp", 13 | "api-index": "说明", 14 | "api-mobx-MobxApp": "MobxApp", 15 | "api-mobx-MobxComponent": "MobxComponent", 16 | "api-mobx-MobxPage": "MobxPage", 17 | "api-mobx-MobxStore": "MobxStore", 18 | "doc-about-component": "关于 Component", 19 | "doc-about-json-file": "关于 json 文件", 20 | "doc-about-page": "关于 Page", 21 | "doc-about-style": "关于样式", 22 | "doc-attention-on-build": "编译时的注意事项", 23 | "doc-autocomplete": "代码自动补全", 24 | "doc-basic-code": "基本代码", 25 | "doc-coding-rule": "编码准则", 26 | "doc-custom-webpack": "自定义 webpack 配置", 27 | "doc-data-bind": "数据双向绑定", 28 | "doc-develop-npm-component": "组件化开发实战", 29 | "doc-difference-with-wepy": "和 wepy 的对比", 30 | "doc-how-to-realize-two-way-data-bind": "如何在原生的微信小程序中实现数据双向绑定", 31 | "doc-how-to-use-wxp-in-other-project": "如何在其它项目中复用 wx 及 wxp 自动补全", 32 | "doc-install": "安装", 33 | "doc-require-other-files-in-script": "在脚本中 require 其它文件", 34 | "doc-unit-in-style": "样式中的单位", 35 | "doc-update-v1-to-v2": "v1.x -> v2.x 升级指南", 36 | "doc-use-setDataSmart-not-setData": "使用 setDataSmart 而不是 setData", 37 | "doc-warn": "重要提醒", 38 | "文档": "文档", 39 | "API": "API", 40 | "帮助": "帮助", 41 | "博客": "博客", 42 | "Github": "Github", 43 | "入门指南": "入门指南", 44 | "基本功能": "基本功能", 45 | "进阶功能": "进阶功能", 46 | "minapp 1.x": "minapp 1.x", 47 | "@minapp/core": "@minapp/core", 48 | "@minapp/mobx": "@minapp/mobx" 49 | }, 50 | "pages-strings": { 51 | "Help Translate|recruit community translators for your project": "Help Translate", 52 | "Edit this Doc|recruitment message asking to edit the doc source": "Edit", 53 | "Translate this Doc|recruitment message asking to translate the docs": "Translate" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /schema/component.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema", 3 | "description": "微信小程序 自定义组件 的 schema", 4 | "type": "object", 5 | "required": ["component"], 6 | 7 | "properties": { 8 | "component": { 9 | "type": "boolean", 10 | "default": true 11 | }, 12 | "usingComponents": { 13 | "type": "object" 14 | }, 15 | "minapp": { 16 | "type": "object", 17 | "properties": { 18 | "component": { 19 | "type": "object", 20 | "description": "关于此组件的文档", 21 | "properties": { 22 | "docLink": { 23 | "type": "string", 24 | "description": "线上文档链接" 25 | }, 26 | "desc": { 27 | "type": "array", 28 | "description": "组件的描述,支持 markdown 语法", 29 | "items": { 30 | "type": "string" 31 | } 32 | }, 33 | "attrs": { 34 | "type": "array", 35 | "description": "组件属性列表", 36 | "items": { 37 | "$ref": "#/definitions/attr" 38 | } 39 | } 40 | } 41 | } 42 | } 43 | } 44 | }, 45 | "definitions": { 46 | "attr": { 47 | "required": ["name", "type"], 48 | "type": "object", 49 | "properties": { 50 | "name": { 51 | "type": "string", 52 | "description": "属性名字" 53 | }, 54 | "type": { 55 | "type": "object", 56 | "description": "属性类型", 57 | "required": ["name"], 58 | "default": {"name": "string"}, 59 | "properties": { 60 | "name": { 61 | "type": "string" 62 | } 63 | } 64 | }, 65 | "desc": { 66 | "type": "array", 67 | "description": "属性的描述,支持 markdown 语法", 68 | "items": { 69 | "type": "string" 70 | } 71 | }, 72 | "required": { 73 | "type": "boolean", 74 | "description": "是否必填" 75 | }, 76 | "defaultValue": { 77 | "description": "属性默认值" 78 | } 79 | } 80 | } 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /packages/minapp-common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@minapp/common", 3 | "version": "2.3.0", 4 | "description": "minapp 内部组件通用的一个库", 5 | "main": "dist/index.js", 6 | "typings": "dist/index.d.ts", 7 | "scripts": { 8 | "test": "jest", 9 | "lint": "tslint src/**/*.ts", 10 | "postpublish": "sync-taobao", 11 | "clear": "remove-all dist", 12 | "build": "npm run clear && tsc && wget https://raw.githubusercontent.com/wx-minapp/minapp-generator/master/gen/tpl/components.json -O res/components.json", 13 | "watch": "tsc -w", 14 | "prepare": "npm run lint && npm run test && npm run build" 15 | }, 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "jest": { 20 | "roots": [ 21 | "src" 22 | ], 23 | "verbose": true, 24 | "testURL": "http://localhost/", 25 | "collectCoverage": true, 26 | "coverageReporters": [ 27 | "text", 28 | "html" 29 | ], 30 | "coveragePathIgnorePatterns": [ 31 | "/node_modules/", 32 | "/__tests__/helper/" 33 | ], 34 | "coverageDirectory": "./coverage", 35 | "transform": { 36 | "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" 37 | }, 38 | "testRegex": "(/__tests__/.*\\.(test|spec))\\.(ts|tsx)$", 39 | "moduleFileExtensions": [ 40 | "ts", 41 | "tsx", 42 | "js", 43 | "json" 44 | ] 45 | }, 46 | "license": "MIT", 47 | "author": "Mora (https://github.com/qiu8310)", 48 | "bugs": "https://github.com/qiu8310/minapp/issues", 49 | "homepage": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-common", 50 | "repository": { 51 | "type": "git", 52 | "url": "https://github.com/qiu8310/minapp/tree/master/packages/minapp-common" 53 | }, 54 | "devDependencies": { 55 | "@types/fs-extra": "^5.0.1", 56 | "@types/jest": "^22.1.1", 57 | "@types/json5": "^0.0.29", 58 | "fs-extra": "^5.0.0", 59 | "jest": "^22.1.4", 60 | "mora-scripts": "^1.6.28", 61 | "ts-jest": "^22.0.2", 62 | "ts-lint": "^4.5.1", 63 | "tslib": "^1.9.0", 64 | "typescript": "^2.7.1" 65 | }, 66 | "dependencies": { 67 | "json5": "^0.5.1", 68 | "mora-common": "^1.0.12" 69 | } 70 | } 71 | --------------------------------------------------------------------------------