Skip to content

franken133/nger

 
 

Repository files navigation

用angular开发小程序

vue、react相继都有了小程序的开发框架,作为一个nger,也该为社区做点事情了! 很遗憾,由于ng和小程序的差异性,我们暂时没打算直接把ng项目转换成小程序,而是用ng的一套思想(依赖注入装饰器等)来规范开发小程序!已达到一套代码多平台运行。

目录规范

开发进度

命令行工具

  • yarn cli build构建打包
    • 手机h5 yarn cli build h5
    • pc网站 yarn cli build pc
    • 微信公众号 yarn cli build wechat
    • 微信小程序 yarn cli build weapp
    • 支付宝小程序 yarn cli build alipay
    • 百度智能小程序 yarn cli build swap
    • 字节跳动小程序 yarn cli build tt
    • ios客户端 yarn cli build ios
    • android客户端 yarn cli build android
  • 初始化 yarn cli init demo
  • yarn cli init初始化
  • yarn cli test单元测试
  • yarn cli start启动服务
  • yarn cli publish发布到当前src模块应用商城

核心库

任务安排

开发重点 nger-compiler 到 nger-di 目标src目录中的文件,编译到各个平台,并运行。

  • 扫描项目目录,并记录每个文件导出的有装饰器装饰的类及名称。
  • 根据运行目标,去掉没有用的或者可以去掉的一些内容,例如@It,@Command,@Option
  • @Component装饰的类生成对应的Component(ComponentInstance)
  • @Page装饰的类生成对应的Page(PageInstance)
  • 搜集配置信息生成json文件
  • 编译html生成wxml文件
  • 编译scss/less/styl生成wxss文件
  • 编译生成js文件

@Page

// TODO

@Page({
    path: `pages/index/index`,
    template: `<view></view>`
})
export class ImsPage{}

// pages/index/index.js

// pages/index/index.json

// pages/index/index.wxss

// pages/index/index.wxml

@Component

// **/ims-demo.ts
import {Component,Input,EventEmitter} from 'nger-core';

@Component({
    selector: 'ims-demo',
    template: `<view (onTap)="click"></view>`
})
export class ImsDemo {
    @Input()
    title: string;

    @Output()
    bindmyevent: EventEmitter;

    click(e){
        this.bindmyevent.emit(e);
    }
}

// to
// **/ims-demo.js
const instance = new ImsDemo();
Component({
    behaviors: [],
    data: {
        instance: instance
    },
    properties: {
        // Input
        title: instance.title
    },
    lifetimes: {
        created(){
            instance.ngOnInit()
        },
        attached() { 
            instance.onViewInit()
        },
        ready(){
            instance.onAfterViewInit()
        },
        moved() { 
            instance.onMoved()
        },
        detached() { 
            instance.onDestory()
        },
        error() { 
            instance.onError()
        },
    },
    pageLifetimes: {
        show(){
            instance.onShow()
        },
        hide(){
            instance.onHide()
        },
        resize(){
            instance.onResize()
        }
    },
    methods: {
        click: instance.click
    }
})
// **/ims-demo.json
{}
// **/ims-demo.wxss

// **/ims-demo.wxml
<view onTap="click"></view>

ngIf

<ng-template [ngIf]="condiction"></ng-template>
<!-- to -->
<ng-template wx:if="{{condiction}}"></ng-template>
<ng-template [ngIf]="condiction" [ngIfELse]="elseBlock">condiction</ng-template>
<ng-template #elseBlock>elseBlock</ng-template>
<!-- to -->
<ng-template wx:if="{{condiction}}"></ng-template>
<ng-template wx:else>elseBlock</ng-template>
<ng-template [ngIf]="condiction" [ngIfThen]="thenBlcok" [ngIfELse]="elseBlock"></ng-template>
<ng-template #thenBlcok>thenBlcok</ng-template>
<ng-template #elseBlock>elseBlock</ng-template>
<!-- to -->
<ng-template wx:if="{{condiction}}">thenBlcok</ng-template>
<ng-template wx:else>elseBlock</ng-template>

ngFor

<ng-template ngFor let-item="it" let-i="index" [ngForOf]="items"></ng-template>
<!-- to -->
<ng-template wx:for="items" wx:for-item="it" wx:for-index="i"></ng-template>

多平台SDK统一接口

用于启动测试

用于启动cli

express环境

express环境

typeorm环境

小程序运行

依赖注入实现

带色打印工具

  • Logger 接口
  • ConsoleLogger Loggerconsole实现

About

angular开发小程序

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.0%
  • Other 1.0%