From 92df046ade785866630f646e78338c5a30c486e0 Mon Sep 17 00:00:00 2001 From: Diablohu Date: Thu, 18 Apr 2019 14:32:49 +0800 Subject: [PATCH] try fixing #99 --- package.json | 3 ++- packages/koot/CHANGELOG.md | 3 ++- publish.js | 44 ++++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index cba37f64..7b3f92f9 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "is-valid-path": "0.1.1", "inquirer": "6.3.1", "chalk": "2.4.2", - "latest-version": "5.1.0" + "latest-version": "5.1.0", + "crlf": "1.1.1" } } diff --git a/packages/koot/CHANGELOG.md b/packages/koot/CHANGELOG.md index 73d4ce44..28d01a18 100644 --- a/packages/koot/CHANGELOG.md +++ b/packages/koot/CHANGELOG.md @@ -1,9 +1,10 @@ ## 0.9.0 (Alpha) -**2019-04-18** (alpha.5) +**2019-04-??** (alpha.6) - 核心 - 配置项 - **新** `devMemoryAllocation` - 指定开发环境中 node.js 分配的内存。详情请参见文档的 [配置](https://koot.js.org/#/config?id=devmemoryallocation) 章节 + - 现在可以使用 `yarn` 安装并使用 _Koot.js_ ([#99](https://github.com/cmux/koot/issues/99)) - 渲染结果 (SSR & SPA) - 结尾现在会附带 koot 版本信息作为 HTML 代码注释 ([#64](https://github.com/cmux/koot/issues/64)) - 如果 ejs 模板中缺少关键注入项 (`inject`),现在会自动添加 ([#81](https://github.com/cmux/koot/issues/81)) diff --git a/publish.js b/publish.js index 7571d9bd..cb8e0304 100644 --- a/publish.js +++ b/publish.js @@ -1,12 +1,42 @@ const fs = require('fs-extra') const path = require('path') const inquirer = require('inquirer') +const crlf = require('crlf') const runScript = require('./libs/run-script') const logWelcome = require('./libs/log/welcome') const logAbort = require('./libs/log/abort') const logFinish = require('./libs/log/finish') +const filesChangedFromCRLFtoLF = [] + +const prePublish = async () => { + const dirKoot = path.resolve(__dirname, './packages/koot') + const { bin } = await fs.readJson(path.resolve(dirKoot, 'package.json')) + for (const pathname of bin) { + const file = path.resolve(dirKoot, pathname) + await new Promise((resolve, reject) => { + crlf.set(file, 'LF', (err, endingType) => { + if (err) return reject(err) + if (endingType === 'CRLF') + filesChangedFromCRLFtoLF.push(file) + resolve(endingType) + }) + }) + } +} + +const postPublish = async () => { + for (const file of filesChangedFromCRLFtoLF) { + await new Promise((resolve, reject) => { + crlf.set(file, 'CRLF', (err) => { + if (err) return reject(err) + resolve() + }) + }) + } +} + const run = async () => { logWelcome('Publish') @@ -79,13 +109,19 @@ const run = async () => { return } - const cmd = `lerna publish` + await prePublish() + await runScript( + `lerna publish` + ` --ignore-changes "packages/!(${selected.join('|')})/**"` + (tag ? ` --dist-tag ${tag}` : '') - - await runScript(cmd) + ) + await postPublish() logFinish() } -run().catch(e => console.error(e)) +run() + .catch(async e => { + console.error(e) + await postPublish() + })