Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit 33bee0e

Browse files
committed
refactor project with typescript
1 parent 45dd122 commit 33bee0e

68 files changed

Lines changed: 2774 additions & 3981 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 29 deletions
This file was deleted.

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
*.log
21
node_modules
32
dist
3+
*.log
4+
.DS_Store
5+
mock/*
6+
!mock/readme.md
7+
8+
/src/**/*.js

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"**/.git": true,
5+
"**/.DS_Store": true,
6+
"dist": true,
7+
"**/*.js": {
8+
"when": "$(basename).ts"
9+
},
10+
"**/*?.js": {
11+
"when": "$(basename).tsx"
12+
}
13+
},
14+
"typescript.tsdk": "./node_modules/typescript/lib",
15+
"editor.trimAutoWhitespace": true
16+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fork this repo, choose tasks to complete and once you are done send pull request
77

88
### Tasks
99

10-
#### Redux / React
10+
#### Flux / React
1111

1212
* When "Add Contact" button is clicked, new contact card should appear with following fields:
1313
* Name

layout/default.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = (data) =>
2+
3+
`<!DOCTYPE html>
4+
<html>
5+
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
6+
<head>
7+
<title>Contact App</title>
8+
</head>
9+
<body>
10+
<div id="app">
11+
There is something wrong with your js engine
12+
</div>
13+
</body>
14+
<script type="text/javascript">
15+
(function () {
16+
var match = navigator.userAgent.match(/Chrome\\/(\\d+)/)
17+
if (!match || !+match[1] || +match[1] < 58) {
18+
var div = document.createElement('div')
19+
div.style = 'position: fixed;top: 60px;text-align: center;width: 100%;z-index: 1000;background-color: #fff;padding: 10px;font-weight: bold;font-size: 16px;color: #f00;'
20+
div.innerHTML = 'Please download the latest Chrome:<a href="https://www.google.com/chrome/" target="_blank">https://www.google.com/chrome/</a>'
21+
document.body.insertBefore(div, document.body.firstChild)
22+
}
23+
})()
24+
</script>
25+
<script type="text/javascript" src="${data.vendor}"></script>
26+
<script type="text/javascript" src="${data.page}"></script>
27+
</html>`;

nofile.js

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,88 @@
1-
let kit = require('nokit');
1+
var kit = require('nokit');
2+
var br = kit.require('brush');
23

3-
module.exports = (task, option) => {
4-
option('--port <number>, -p', 'the port of dev server', 7000)
5-
6-
task('dev default', 'run on dev mode', ['devServe'])
4+
/**
5+
* option 收录了 no 命令主要的参数。函数 option 接收三个参数,最后一个是默认值。
6+
* 例如,启动时修改基础模板页配置:`no --port 12345`.
7+
*
8+
* 请阅读每个 option 配置,具体说明几个配置。
9+
*
10+
* - port
11+
*
12+
* 本地 mock 数据服务端口号。本地 mock 服务用于提供 mock 数据的数据服务。在 mock 目录 index.js
13+
* 配置的数据和路由就是针对该服务的。使用 127.0.0.1:${port} 访问。
14+
*
15+
* - pacPort
16+
*
17+
* 用作 PAC 代理的服务器端口号,PAC 代理是指 proxy auto configuration,
18+
* 其详细含义可以参考: [PAC](https://en.wikipedia.org/wiki/Proxy_auto-config)
19+
*
20+
* 在用no命令启动后,可以通过地址 http://127.0.0.1:${pacPort} 查看PAC配置具体内容。
21+
*
22+
* - devHost
23+
*
24+
* 用于配置PAC方式要代理掉得域名。例如要代理掉本地访问 www.demo.com 地址的数据时,需要配置
25+
* devHost 为 demo.com。
26+
*
27+
* - ethernet
28+
*
29+
* 在使用PAC方式代理的时候,需要指定网络配置,默认是WI-FI。命令行输入 networksetup -listallnetworkservices
30+
* 可以查看安装的网络配置,选择你正在使用的作为配置内容。
31+
*
32+
*/
733

8-
task('devServe', ['devBuild'], 'run the dev server', kit.async(function * (opts) {
9-
const { flow, static, select, serverHelper, url } = kit.require('proxy')
10-
const app = flow()
11-
const handler = serverHelper()
34+
module.exports = (task, option) => {
35+
/*
36+
* option('参数表达式', '注释', '默认值');
37+
*/
38+
option('--port <num>', '本地 mock 数据服务端口号', '8732');
39+
option('--devHost <host>', '线上域名,结合 pac 代理', 'demo.com');
40+
option('--pacPort <num>', '代理服务器端口', '58733');
41+
option('--pac <on|off>', '是否动设置全局 pac 代理: on 或 off', 'off');
42+
option('--ethernet <str>', '网络设置', 'Wi-Fi');
1243

13-
handler.watch('dist/app.js')
44+
option('--cdnPrefix <url>', 'CDN 前缀,多个用逗号', '');
45+
option('--mock <path>', 'mock 配置入口', 'mock/index.js');
46+
option('--vane <on|off>', '是否开启 vane', 'off');
47+
option('--vaneToken <str>', 'vane mock 的 token', 'mock');
48+
option('--layout <path>', '页面模板文件夹', 'layout');
49+
option('--dist <path>', '编译输出文件夹', 'dist');
50+
option('--page <path>', '页面的编译输出文件夹', 'page');
51+
option('--src <path>', '源代码所在的文件夹', 'src');
52+
option('--srcPage <path>', '入口页面源代码所在的文件夹', 'src/page');
53+
option('--favicon <path>', 'favicon 路径', 'src/img/favicon.ico');
54+
option('--hashMap <path>', '编译的 hashmap 输出路径', 'dist/hash-map.json');
55+
option('--preload <path>', '编译出的图片预载器文件路径', 'dist/preload.js');
56+
option('--hashPath <on|off>', '编译时是否 hash 路径', 'on');
57+
option('--hashExclude <regex>', '匹配的路径将不被 hash', '$ ^');
58+
option('--lang <str>', '选择主语言与处理器 js, babel 或 typescript', 'js');
59+
option('--webpack <on|off>', '是否开启 webpack', 'on');
60+
option('--autoOpen <on|off>', '是否自动打开页面', 'on');
61+
option('--liveReload <on|off>', '是否启动自动刷新页面: on 或 off', 'on');
1462

15-
app.push(handler)
63+
task('default dev', ['clean'], 'start dev server', kit.async(function * (opts) {
64+
yield kit.spawn('tsc');
65+
kit.spawn('tsc', ['-w']);
66+
return require('febone-kit/lib/dev')(opts)
67+
}));
1668

17-
app.push($ => {
18-
if (/text\/html/.test($.req.headers['accept']))
19-
$.body = kit.readFileSync('src/index.html') + handler.browserHelper
20-
else
21-
return $.next()
22-
})
69+
task('build', ['build-js'], '以产品模式编译项目到 dist 文件夹', kit.async(function *(opts) {
70+
yield require('febone-kit/lib/build')(opts)
71+
}));
2372

24-
app.push(select('/', static('dist')))
73+
task('build-js', ['clean'], '编译 js', kit.async(function * (opts) {
74+
process.env['febone-opts'] = JSON.stringify(opts);
75+
yield kit.spawn('tsc');
76+
return kit.spawn('webpack');
77+
}));
2578

26-
yield app.listen(opts.port)
27-
kit.logs(`listen on port ${opts.port}`)
28-
kit.xopen(`http://127.0.0.1:${opts.port}`)
29-
}))
79+
task('clean', 'clean project', opts =>
80+
kit.remove(opts.dist)
81+
);
3082

31-
task('devBuild', 'dev build project to dist directory', kit.async(function * () {
32-
const webpackConf = 'tools/webpack/development.js'
33-
const webpackLogPrefix = 'webpack | :blue'
83+
task('deps');
3484

35-
// webpack: the first cold build
36-
yield kit.spawn('webpack', ['--config', webpackConf], {
37-
prefix: webpackLogPrefix
38-
})
85+
task('pac-off', '关闭 pac 代理配置', require('febone-kit/lib/pac-set').off);
3986

40-
// webpack: watch files changes
41-
kit.spawn('webpack', ['--config', webpackConf, '-w'], {
42-
prefix: webpackLogPrefix
43-
})
44-
}))
45-
}
87+
task('update-bone', '升级脚手架', require('febone-kit/lib/update-bone'));
88+
};

0 commit comments

Comments
 (0)