forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0acf1e0
commit a9e27a7
Showing
13 changed files
with
2,865 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env node | ||
let target = process.argv[2]; | ||
const packageConfig = require('../package.json'); | ||
if (!target) { | ||
console.error('缺少 nutui or nutui-taro 参数!'); | ||
return; | ||
} | ||
let copyfile = ['dist', 'README.md', 'LICENSE', 'CHANGELOG.md']; | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
// 清空 dist | ||
fs.emptyDirSync(path.resolve(__dirname, `../publish/${target}/dist`)); | ||
copyfile.forEach((filename) => { | ||
fs.copy(path.resolve(__dirname, `../${filename}`), path.resolve(__dirname, `../publish/${target}/${filename}`)).then( | ||
(res) => { | ||
console.log(`publish/${target}/${filename} 写入成功`); | ||
} | ||
); | ||
}); | ||
const targetPkgPath = path.resolve(__dirname, `../publish/${target}/package.json`); | ||
const targetPkgStr = fs.readFileSync(targetPkgPath); | ||
const targetPkgObj = JSON.parse(targetPkgStr); | ||
targetPkgObj.version = packageConfig.version; | ||
fs.outputFile(targetPkgPath, JSON.stringify(targetPkgObj, null, 2), 'utf8', () => { | ||
console.log(`${targetPkgPath} 写入成功`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const config = require('../src/config.json'); | ||
const packageConfig = require('../package.json'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
|
||
// 获取依赖关系 | ||
const styleMap = new Map(); | ||
const tasks = []; | ||
let outputFileEntry = ``; | ||
let components = []; | ||
// import Locale from './packages/locale';\n | ||
config.nav.forEach((item) => { | ||
item.packages.forEach((element) => { | ||
styleMap.set(element.name, { | ||
name: element.name, | ||
children: element.styleDeps | ||
}); | ||
// gen entry | ||
if (element.exclude != true) { | ||
let outputMjs = ''; | ||
if (element.type == 'methods') { | ||
outputMjs = `import _${element.name} from '../_es/${element.name}.js'; | ||
import { show${element.name} } from '../_es/${element.name}.js'; | ||
const treeshaking = (t) => t; | ||
const ${element.name} = treeshaking(_${element.name}); | ||
export { ${element.name}, show${element.name} };`; | ||
} else { | ||
outputMjs = `import _${element.name} from '../_es/${element.name}.js'; | ||
const treeshaking = (t) => t; | ||
const ${element.name} = treeshaking(_${element.name}); | ||
export { ${element.name} };`; | ||
} | ||
tasks.push( | ||
fs.outputFile(path.resolve(__dirname, `../dist/packages/${element.name}/index.mjs`), outputMjs, 'utf8', () => { | ||
// console.log('') | ||
}) | ||
); | ||
let folderName = element.name.toLowerCase(); | ||
outputFileEntry += `export * from "./packages/${folderName}/index.mjs";\n`; | ||
components.push(element.name); | ||
} | ||
}); | ||
}); | ||
outputFileEntry += components.map((name) => `import { ${name} } from "./packages/${name}/index.mjs";`).join('\n'); | ||
outputFileEntry += `\nimport { Locale } from "./packages/locale/lang"; | ||
function install(app) { | ||
const packages = [${components.join(',')}]; | ||
packages.forEach((item) => { | ||
if (item.install) { | ||
app.use(item); | ||
} else if (item.name) { | ||
app.component(item.name, item); | ||
} | ||
}); | ||
} | ||
const version = '${packageConfig.version}'; | ||
var stdin_default = { | ||
install, | ||
version, | ||
Locale | ||
}; | ||
export { | ||
stdin_default as default, | ||
install, | ||
version, | ||
Locale | ||
};`; | ||
|
||
tasks.push( | ||
fs.outputFile(path.resolve(__dirname, `../dist/nutui.es.js`), outputFileEntry, 'utf8', () => { | ||
// console.log('') | ||
}) | ||
); | ||
|
||
styleMap.forEach((value) => { | ||
if (value.children && value.children.length > 0) { | ||
value.children.forEach((item, index) => { | ||
value.children[index] = styleMap.get(item); | ||
}); | ||
} | ||
}); | ||
|
||
const getAllDeps = (styleObj, key) => { | ||
const value = styleObj; | ||
if (value.children?.length === 0) { | ||
return [value.name]; | ||
} else { | ||
let deps = []; | ||
value.children?.forEach((item) => { | ||
if (key === item.name) { | ||
console.error('generate-style-deps: 存在循环引用', key); | ||
return []; | ||
} | ||
deps = deps.concat(getAllDeps(item, key)); | ||
}); | ||
deps.unshift(value.name); | ||
return [...new Set(deps)]; | ||
} | ||
}; | ||
|
||
Promise.all(tasks); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.