Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Jun 23, 2015
0 parents commit 44a4ae3
Show file tree
Hide file tree
Showing 24 changed files with 520 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.DS_Store
tmp
spm_modules
node_modules
demo/dist
7 changes: 7 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
coverage
test/fixtures
test/expected
tmp
demo
spm_modules
32 changes: 32 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"expr": true,
"eqeqeq": true,
"eqnull": true,
"indent": 2,
"latedef": "nofunc",
"newcap": true,
"quotmark": true,
"trailing": true,
"undef": true,
"unused": true,
"lastsemic": true,
"boss": true,
"funcscope": true,
"loopfunc": true,
"smarttabs": true,
"sub": true,
"strict": true,
"node": true,
"esnext": true,
"globals": {
"describe": false,
"xdescribe": false,
"it": false,
"xit": false,
"before": false,
"beforeEach": false,
"after": false,
"afterEach": false,
"define": false
}
}
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.DS_Store
tmp
spm_modules
node_modules
demo
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# History

---
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# antd

[![NPM version](https://img.shields.io/npm/v/antd.svg?style=flat)](https://npmjs.org/package/antd)

Development tool for ant.design .

----

## 使用说明

### 安装

```bash
$ npm i antd -g
```

### 脚手架

```bash
$ antd init
```

这会创建一个 package.json,此外你还需要在 package.json 中配置 entry 声明哪些是入口文件,格式详见:http://webpack.github.io/docs/configuration.html#entry

### 本地调试

```bash
$ antd server
```

然后访问 http://127.0.0.1:8000

### 构建

```bash
$ antd build
```
42 changes: 42 additions & 0 deletions bin/antd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

var spawn = require('win-spawn');
var join = require('path').join;
var exists = require('fs').existsSync;
var program = require('commander');

program
.version(require('../package').version, '-v, --version')
.usage('<command> [options]')
.on('--help', printHelp)
.parse(process.argv);

var subcmd = program.args[0];
var args = process.argv.slice(3);

if (!subcmd) {
program.help();
} else {
var bin = executable(subcmd);
if (bin) {
spawn(bin, args, {stdio: 'inherit', customFds: [0, 1, 2]});
} else {
printHelp();
}
}

function printHelp() {
console.log(' Commands:');
console.log();
console.log(' init initialize');
console.log(' build build entry files specified in package.json');
console.log(' server debug with server');
console.log();
}

function executable(subcmd) {
var file = join(__dirname, 'antd-' + subcmd);
if (exists(file)) {
return file;
}
}
9 changes: 9 additions & 0 deletions bin/antd-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

var program = require('commander');
require('gnode');

program
.parse(process.argv);

require('../lib/build')();
33 changes: 33 additions & 0 deletions bin/antd-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

var vfs = require('vinyl-fs');
var through = require('through2');
var join = require('path').join;
var basename = require('path').basename;

var cwd = join(__dirname, '../boilerplate');
var dest = process.cwd();

vfs.src('**/*', {cwd: cwd, cwdbase: true, dot: true})
.pipe(template(dest))
.pipe(vfs.dest(dest))
.on('end', function() {

})
.resume();

function template(dest) {
return through.obj(function (file, enc, cb) {
if (!file.stat.isFile()) {
return cb();
}

console.log('Write %s', simplifyFilename(join(dest, basename(file.path))));
this.push(file);
cb();
});
}

function simplifyFilename(filename) {
return filename.replace(process.cwd(), ".");
}
12 changes: 12 additions & 0 deletions bin/antd-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

var program = require('commander');
require('gnode');

program
.option('-p, --port <port>', 'port')
.parse(process.argv);

require('../lib/server')({
port: program.port
});
5 changes: 5 additions & 0 deletions boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"ant-design": "https://github.com/ant-design/ant-design.git"
}
}
31 changes: 31 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# demo

----

## 使用方法

### 安装 antd

```bash
$ npm install antd -g
```

### 安装依赖

```bash
$ npm install
```

### 本地调试

```bash
$ antd server
```

然后访问 http://127.0.0.1:8000/a.html

### 构建

```bash
$ antd build
```
19 changes: 19 additions & 0 deletions demo/a.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>antd demo</title>
<link rel="stylesheet" href="a.css" />
</head>
<body>

<h1>antd demo</h1>
<br /><br />

<div id="components-progress-demo-circle-dynamic"></div>

<script src="https://a.alipayobjects.com/react/0.13.2/react.js"></script>
<script src="a.js"></script>

</body>
</html>
31 changes: 31 additions & 0 deletions demo/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

require('antd/style/index.less');

var ProgressCircle = require('antd/components/progress').Circle;

var MyProgress = React.createClass({
getInitialState() {
return {
percent: 0
};
},
componentDidMount: function() {
var self = this;
setInterval(function() {
if (self.state.percent < 100) {
self.state.percent += 4;
}
self.setState({
percent: self.state.percent
});
}, 200);
},
render() {
return <ProgressCircle percent={this.state.percent} />;
}
});

React.render(
<MyProgress />
, document.getElementById('components-progress-demo-circle-dynamic'));
8 changes: 8 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"entry": {
"a": "./a.js"
},
"dependencies": {
"ant-design": "https://github.com/ant-design/ant-design.git"
}
}
27 changes: 27 additions & 0 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var shelljs = require('shelljs');
var join = require('path').join;
var webpack = require('webpack');

module.exports = function() {
var printResult = require('../lib/printResult');

var cwd = process.cwd();
shelljs.rm('-rf', join(cwd, './dist'));

var webpackConfig;
try {
webpackConfig = require(join(cwd, 'webpack.config.js'));
} catch(e) {
webpackConfig = require('../lib/webpack.config.js');
}

webpack(webpackConfig, function(err, stats) {
printResult(stats);
console.log(stats.toString());
if (err) {
console.error(err);
}
});
};
22 changes: 22 additions & 0 deletions lib/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var join = require('path').join;
var webpack = require('webpack');
var printResult = require('./printResult');

module.exports = function () {
var webpackConfig;

try {
webpackConfig = require(join(process.cwd(), 'config/webpack.dev.config.js'));
} catch (e) {
webpackConfig = require('./webpack.dev.config.js');
}

var compiler = webpack(webpackConfig);
compiler.plugin('done', printResult);

return require('koa-webpack-dev-middleware')(compiler, {
publicPath: '/'
});
};
23 changes: 23 additions & 0 deletions lib/printResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = function(stats) {
stats = stats.toJson();

if (stats.errors && stats.errors.length) {
var hasChildError = false;
stats.children.forEach(function(item) {
if (item.errors) {
hasChildError = true;
item.errors.forEach(function(err) {
console.error('error', err);
});
}
});
if (!hasChildError) {
stats.errors.forEach(function(err) {
console.error('error', err);
});
}
console.log();
}
};
Loading

0 comments on commit 44a4ae3

Please sign in to comment.