Skip to content

Commit ea3b37d

Browse files
committed
feat(alita): 完善 js, ts init 初始化项目
1 parent 27a3e5f commit ea3b37d

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

rn-template/src/HelloWorld.js

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import { StyleSheet, Text, View, Platform } from "react-native"
77
*/
88
import {AnimatedImage, createAnimation} from '@areslabs/wx-animated'
99

10+
/**
11+
* @areslabs/stringutil-rn 由于在alita.config.js 的dependencies字段有对应配置,所有在微信小程序平台,会把替换为
12+
* '@areslabs/stringutil-wx'。 语句将变成 :import {camelCase} from '@areslabs/stringutil-wx'
13+
*
14+
* 对于不能直接在小程序运行的npm包,需要做类似处理。详情参考:
15+
* 普通npm包:https://areslabs.github.io/alita/npm%E5%8C%85%E8%AF%B4%E6%98%8E.html
16+
* 组件包: https://areslabs.github.io/alita/%E7%AC%AC%E4%B8%89%E6%96%B9%E7%BB%84%E4%BB%B6%E5%BA%93%E6%89%A9%E5%B1%95.html
17+
*
18+
*/
19+
import {camelCase} from '@areslabs/stringutil-rn'
20+
1021
import rnLogoPng from './rn_logo.png'
1122

1223
export default class HelloWorld extends Component {

rn-typescript-template/src/HelloWorld.tsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { Component } from "react";
1+
import * as React from 'react'
2+
import {Component} from 'react'
3+
24
import { StyleSheet, Text, View, Platform } from "react-native"
35

46
/**
@@ -7,9 +9,26 @@ import { StyleSheet, Text, View, Platform } from "react-native"
79
*/
810
import {AnimatedImage, createAnimation} from '@areslabs/wx-animated'
911

12+
13+
/**
14+
* @areslabs/stringutil-rn 由于在alita.config.js 的dependencies字段配置,所有在微信小程序平台,会把替换为
15+
* '@areslabs/stringutil-wx'。 语句将变成 :import {camelCase} from '@areslabs/stringutil-wx'
16+
*
17+
* 对于不能直接在小程序运行的npm包,需要做类似处理。详情参考:
18+
* 普通npm包:https://areslabs.github.io/alita/npm%E5%8C%85%E8%AF%B4%E6%98%8E.html
19+
* 组件包: https://areslabs.github.io/alita/%E7%AC%AC%E4%B8%89%E6%96%B9%E7%BB%84%E4%BB%B6%E5%BA%93%E6%89%A9%E5%B1%95.html
20+
*
21+
*/
22+
import {camelCase} from '@areslabs/stringutil-rn'
23+
1024
import rnLogoPng from './rn_logo.png'
1125

12-
export default class HelloWorld extends Component {
26+
27+
interface IState {
28+
logoAni: object,
29+
}
30+
31+
export default class HelloWorld extends Component<{}, IState> {
1332

1433
state = {
1534
logoAni: null,
@@ -30,7 +49,7 @@ export default class HelloWorld extends Component {
3049
/>
3150

3251
<Text>
33-
Hello {Platform.OS}!
52+
{camelCase(`Hello ${Platform.OS}!`)}
3453
</Text>
3554
</View>
3655

src/util/initProject.js

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export default function initProject(operands, typescript) {
4040
child_process.execSync('yarn add @areslabs/wx-animated', {
4141
cwd: targetpath,
4242
})
43+
child_process.execSync('yarn add @areslabs/stringutil-rn', {
44+
cwd: targetpath,
45+
})
4346

4447
if (typescript) {
4548
child_process.execSync('yarn add --dev @types/react-native', {
@@ -53,6 +56,9 @@ export default function initProject(operands, typescript) {
5356
child_process.execSync('npm install --save @areslabs/wx-animated', {
5457
cwd: targetpath,
5558
})
59+
child_process.execSync('npm install --save @areslabs/stringutil-rn', {
60+
cwd: targetpath,
61+
})
5662

5763
if (typescript) {
5864
child_process.execSync('npm install --save-dev @types/react-native', {

0 commit comments

Comments
 (0)