提交 4450d611e6b5072637e5d2a50b9da10fda077acd

作者 sorrycc
1 个父辈 4eb0759d

refact: new block data source

正在显示 33 个修改的文件 包含 83 行增加146 行删除
1   -# Logs
2   -logs
3   -*.log
4   -npm-debug.log*
5   -yarn-debug.log*
6   -yarn-error.log*
7 1
8   -# Runtime data
9   -pids
10   -*.pid
11   -*.seed
12   -*.pid.lock
  2 +# npm related
  3 +/yarn.lock
  4 +/node_modules
  5 +/blocks/**/node_modules
  6 +/blocks/**/yarn.lock
  7 +/templates/**/node_modules
  8 +/templates/**/yarn.lock
13 9
14   -# Directory for instrumented libs generated by jscoverage/JSCover
15   -lib-cov
  10 +# doc
  11 +/dist
16 12
17   -# Coverage directory used by tools like istanbul
18   -coverage
19   -
20   -# nyc test coverage
21   -.nyc_output
22   -
23   -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24   -.grunt
25   -
26   -# Bower dependency directory (https://bower.io/)
27   -bower_components
28   -
29   -# node-waf configuration
30   -.lock-wscript
31   -
32   -# Compiled binary addons (https://nodejs.org/api/addons.html)
33   -build/Release
34   -
35   -# Dependency directories
36   -node_modules/
37   -jspm_packages/
38   -
39   -# TypeScript v1 declaration files
40   -typings/
41   -
42   -# Optional npm cache directory
43   -.npm
44   -
45   -# Optional eslint cache
46   -.eslintcache
47   -
48   -# Optional REPL history
49   -.node_repl_history
50   -
51   -# Output of 'npm pack'
52   -*.tgz
53   -
54   -# Yarn Integrity file
55   -.yarn-integrity
56   -
57   -# dotenv environment variables file
58   -.env
59   -
60   -# next.js build output
61   -.next
62   -
63   -# umi
64   -pages
  13 +# umi related
65 14 .umi
66 15 .umi-production
67   -
68   -# MacOS
69   -.DS_Store
70   -yarn.lock
... ...
  1 +const { readdirSync, readFileSync, writeFileSync, existsSync } = require('fs');
  2 +const { join, basename } = require('path');
  3 +const mkdirp = require('mkdirp');
  4 +
  5 +function parseJSON(root) {
  6 + const dirs = readdirSync(root);
  7 + const type = basename(root);
  8 + return dirs.reduce((memo, dir) => {
  9 + if (dir.charAt(0) === '.') return;
  10 + const absDirPath = join(root, dir);
  11 + const pkg = require(join(absDirPath, 'package.json'));
  12 + const url = `https://github.com/umijs/umi-blocks/tree/master/${type}/${dir}`;
  13 + memo.push({
  14 + name: pkg.name,
  15 + description: pkg.description,
  16 + url,
  17 + tags: [],
  18 + img: `${url}/snapshot.png?raw=true`,
  19 + previewUrl: '',
  20 + features: [],
  21 + });
  22 + return memo;
  23 + }, []);
  24 +}
  25 +
  26 +function generate(root) {
  27 + const dist = join(root, '..', 'dist');
  28 + const type = basename(root);
  29 +
  30 + console.log(`Generate json for ${type}`);
  31 + mkdirp.sync(dist);
  32 +
  33 + const json = parseJSON(root);
  34 + writeFileSync(
  35 + join(dist, `${type}.json`),
  36 + JSON.stringify(json, null, 2),
  37 + 'utf-8',
  38 + );
  39 +}
  40 +
  41 +generate(join(__dirname, '..', 'templates'));
  42 +generate(join(__dirname, '..', 'blocks'));
... ...
1   -/yarn.lock
2   -/package-lock.json
3   -/dist
4   -/node_modules
5   -/pages
6   -.umi
7   -.umi-production
1 1 {
2   - "name": "@umi-block/blank",
  2 + "name": "Blank",
3 3 "description": "A blank block for quick start a umi page develop.",
4 4 "dependencies": {
5 5 "umi-request": "^1.0.0"
6   - },
7   - "blockConfig": {
8   - "specVersion": "0.1"
9 6 }
10   -}
\ No newline at end of file
  7 +}
... ...
  1 +{
  2 + "name": "Demo",
  3 + "description": "A demo block of umi.",
  4 + "dependencies": {
  5 + "antd": "^3.10.9"
  6 + }
  7 +}
... ...
1 1 .container {
2 2 color: blue;
3   -}
\ No newline at end of file
  3 +}
... ...
1   -{
2   - "name": "@umi-blocks/demo-with-dependencies",
3   - "description": "a demo block with dependencies",
4   - "scripts": {
5   - "dev": "umi dev"
6   - },
7   - "dependencies": {
8   - "antd": "^3.10.9"
9   - },
10   - "devDependencies": {
11   - "umi": "^2.3.0",
12   - "umi-plugin-react": "^1.3.0",
13   - "umi-plugin-block-dev": "^2.0.0"
14   - },
15   - "blockConfig": {
16   - "dependencies": ["demo"]
17   - }
18   -}
1   -import React from 'react';
2   -import { Row, Col } from 'antd';
3   -import Demo from './Demo';
4   -import styles from './index.less';
5   -
6   -export default () => {
7   - return (
8   - <div className={styles.container}>
9   - <Row><Col span={24}>I am a block with dependencies.</Col></Row>
10   - <Row>
11   - <Col span={12}><Demo /></Col>
12   - <Col span={12}><Demo /></Col>
13   - </Row>
14   - </div>
15   - )
16   -}
1   -.container {
2   - color: red;
3   -}
\ No newline at end of file
1   -export default {
2   - plugins: [
3   - ['umi-plugin-block-dev', {
4   - layout: 'ant-design-pro',
5   - }],
6   - ['umi-plugin-react', {
7   - antd: true,
8   - }],
9   - ],
10   -}
1   -{
2   - "name": "@umi-blocks/demo",
3   - "description": "a demo block of umi",
4   - "scripts": {
5   - "dev": "umi dev"
6   - },
7   - "dependencies": {
8   - "antd": "^3.10.9"
9   - },
10   - "devDependencies": {
11   - "umi": "^2.3.0",
12   - "umi-plugin-react": "^1.3.0",
13   - "umi-plugin-block-dev": "^2.0.0"
14   - }
15   -}
  1 +{
  2 + "name": "blocks",
  3 + "version": 2,
  4 + "scope": "umijs",
  5 + "builds": [
  6 + {
  7 + "src": "./package.json",
  8 + "use": "@now/static-build",
  9 + "config": {
  10 + "distDir": "./dist"
  11 + }
  12 + }
  13 + ],
  14 + "alias": ["blocks.umijs.org"]
  15 +}
... ...
... ... @@ -6,7 +6,8 @@
6 6 "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style",
7 7 "lint-staged": "lint-staged",
8 8 "lint-staged:js": "eslint --ext .js",
9   - "prettier": "node ./_scripts/prettier.js"
  9 + "prettier": "node ./_scripts/prettier.js",
  10 + "build": "node ./_scripts/generate.js"
10 11 },
11 12 "devDependencies": {
12 13 "babel-eslint": "^10.0.1",
... ... @@ -22,6 +23,7 @@
22 23 "glob": "^7.1.3",
23 24 "husky": "^1.2.0",
24 25 "lint-staged": "^8.1.0",
  26 + "mkdirp": "^0.5.1",
25 27 "prettier": "1.15.2",
26 28 "stylelint": "^9.8.0",
27 29 "stylelint-config-prettier": "^4.0.0",
... ...
1 1 {
2   - "name": "@umi-block/user-dashboard",
  2 + "name": "UserDashboard",
3 3 "description": "User dashboard example.",
4 4 "dependencies": {
  5 + "antd": "^3.23.4",
5 6 "umi-request": "^1.0.0"
6   - },
7   - "blockConfig": {
8   - "specVersion": "0.1"
9 7 }
10   -}
\ No newline at end of file
  8 +}
... ...
注册登录 后发表评论