|
1 | 1 | const path = require('path'); |
2 | 2 | const babel = require('@babel/core'); |
3 | | -const each = require('licia/each'); |
4 | | -const fs = require('licia/fs'); |
5 | | -const last = require('licia/last'); |
6 | | -const trim = require('licia/trim'); |
7 | | -const extractBlockCmts = require('licia/extractBlockCmts'); |
8 | | -const startWith = require('licia/startWith'); |
9 | | -const stripCmt = require('licia/stripCmt'); |
| 3 | +const { |
| 4 | + each, |
| 5 | + fs, |
| 6 | + last, |
| 7 | + trim, |
| 8 | + extractBlockCmts, |
| 9 | + startWith, |
| 10 | + stripCmt |
| 11 | +} = require('licia'); |
10 | 12 |
|
11 | 13 | const modData = require('../index.json'); |
12 | 14 | const { outdentOneSpace, rmdir, glob, mkdir, cpFile } = require('./util'); |
@@ -40,13 +42,50 @@ async function genPackage(pkgName, files) { |
40 | 42 | delete packInfo[val]; |
41 | 43 | }); |
42 | 44 |
|
| 45 | + if (pkgName === 'licia') { |
| 46 | + packInfo.main = './node.js'; |
| 47 | + packInfo.browser = './browser.js'; |
| 48 | + await genIndex(); |
| 49 | + } |
| 50 | + |
43 | 51 | await fs.writeFile( |
44 | 52 | path.resolve('packages/' + pkgName + '/package.json'), |
45 | 53 | JSON.stringify(packInfo, null, 2), |
46 | 54 | 'utf8' |
47 | 55 | ); |
48 | 56 | } |
49 | 57 |
|
| 58 | +async function genIndex() { |
| 59 | + const mods = { |
| 60 | + browser: [], |
| 61 | + node: [] |
| 62 | + }; |
| 63 | + |
| 64 | + each(modData, (mod, modName) => { |
| 65 | + if (mod.env === 'browser') { |
| 66 | + mods.browser.push(modName); |
| 67 | + } else if (mod.env === 'node') { |
| 68 | + mods.node.push(modName); |
| 69 | + } else { |
| 70 | + mods.browser.push(modName); |
| 71 | + mods.node.push(modName); |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + for (const type of ['browser', 'node']) { |
| 76 | + const modNames = mods[type]; |
| 77 | + let data = ''; |
| 78 | + each(modNames, name => { |
| 79 | + data += `exports.${name} = require('./${name}');\n`; |
| 80 | + }); |
| 81 | + await fs.writeFile( |
| 82 | + path.resolve(`packages/licia/${type}.js`), |
| 83 | + data, |
| 84 | + 'utf8' |
| 85 | + ); |
| 86 | + } |
| 87 | +} |
| 88 | + |
50 | 89 | async function genFile(file, pkgName) { |
51 | 90 | let modName = last(file.split('/')).slice(0, -3); |
52 | 91 |
|
|
0 commit comments