|
1 | 1 | const path = require('path'); |
2 | 2 | const fs = require('fs'); |
| 3 | +const upperCamelCase = require('uppercamelcase'); |
3 | 4 |
|
4 | 5 | function getBlockEntries(dir, material) { |
5 | | - const result = {}; |
| 6 | + let result = {}; |
6 | 7 | const blockDirs = fs.readdirSync(path.join(dir, material, 'blocks')); |
7 | 8 | const layoutDirs = fs.readdirSync(path.join(dir, material, 'layouts')); |
8 | 9 |
|
9 | 10 | blockDirs.forEach((dirName) => { |
10 | 11 | const fullPath = path.join(dir, material, 'blocks', dirName); |
11 | 12 | if (fs.existsSync(fullPath) && isDirectory(fullPath)) { |
12 | | - result[`${material}/blocks/${dirName}`] = path.join( |
13 | | - fullPath, |
14 | | - 'src/index.js' |
15 | | - ); |
| 13 | + const pkgData = require(path.join(fullPath, 'package.json')); |
| 14 | + result[pkgData.blockConfig.name] = { |
| 15 | + type: 'block', |
| 16 | + material: material, |
| 17 | + className: upperCamelCase(pkgData.blockConfig.name), |
| 18 | + name: pkgData.blockConfig.name, |
| 19 | + title: pkgData.blockConfig.title, |
| 20 | + categories: pkgData.blockConfig.categories, |
| 21 | + snapshot: pkgData.blockConfig.snapshot, |
| 22 | + description: pkgData.description, |
| 23 | + author: pkgData.author, |
| 24 | + [`${material}/blocks/${dirName}`]: path.join(fullPath, 'src/index.js'), |
| 25 | + }; |
16 | 26 | } |
17 | 27 | }); |
18 | 28 |
|
19 | 29 | layoutDirs.forEach((dirName) => { |
20 | 30 | const fullPath = path.join(dir, material, 'layouts', dirName); |
21 | 31 | if (fs.existsSync(fullPath) && isDirectory(fullPath)) { |
22 | | - result[`${material}/layouts/${dirName}`] = path.join( |
23 | | - fullPath, |
24 | | - 'src/index.js' |
25 | | - ); |
| 32 | + const pkgData = require(path.join(fullPath, 'package.json')); |
| 33 | + result[pkgData.layoutConfig.name] = { |
| 34 | + type: 'layout', |
| 35 | + material: material, |
| 36 | + className: upperCamelCase(pkgData.layoutConfig.name), |
| 37 | + name: pkgData.layoutConfig.name, |
| 38 | + title: pkgData.layoutConfig.title, |
| 39 | + categories: pkgData.layoutConfig.categories, |
| 40 | + snapshot: pkgData.layoutConfig.snapshot, |
| 41 | + description: pkgData.description, |
| 42 | + author: pkgData.author, |
| 43 | + [`${material}/layouts/${dirName}`]: path.join(fullPath, 'src/index.js'), |
| 44 | + }; |
26 | 45 | } |
27 | 46 | }); |
28 | 47 | return result; |
|
0 commit comments