diff --git a/demos/biu/package.json b/demos/biu/package.json new file mode 100644 index 0000000..80c49cf --- /dev/null +++ b/demos/biu/package.json @@ -0,0 +1,9 @@ +{ + "name": "demo-biu", + "scripts": { + "start": "biu" + }, + "devDependencies": { + "@fe6/biu": "workspace:*" + } +} diff --git a/docs/introduce/contributing.md b/docs/introduce/contributing.md index eacc44c..382ea2c 100644 --- a/docs/introduce/contributing.md +++ b/docs/introduce/contributing.md @@ -27,6 +27,8 @@ $ pnpm i ### 启动 start 命令 +BIU 用 turbo 同时检测所有 packages 中 src 的变化。 + 本地开发 BIU 必开命令,用于编译 src 下的 TypeScript 文件到 dist 目录,同时监听文件变更,有变更时增量编译。 ```bash @@ -40,12 +42,12 @@ $ cd packages/biu $ pnpm start ``` -### 跑 example +### 跑 demo -demos 目录下保存了各种用于测试的例子,跑 demo 是开发 Umi 时确认功能正常的常用方式。每个 example 都配了 dev script,所以进入 example 然后执行 `pnpm start` 即可。 +demos 目录下保存了各种用于测试的例子,跑 demo 是开发 BIU 时确认功能正常的常用方式。每个 demo 都配了 start script,所以进入 demo 然后执行 `pnpm start` 即可。 ```bash -$ cd demos/hello-word +$ cd demos/biu $ pnpm start ``` @@ -61,15 +63,15 @@ $ pnpm doc:dev ### 新增 package -新增 package 有封装脚本,无需手动复制 package.json 等文件。分两步,1)创建目录 2)执行 `pnpm bootstrap`。 +新增 package 有封装脚本,无需手动复制 package.json 等文件。 -- 直接创建 biu 文件夹,并生成新的 package +- 一个命令搞定新 package ```bash $ pnpm bootstrap biu ``` -- 手动创建文件夹,自动生成新是 package +- 手动创建文件夹,自动生成新是 package 。分两步,1)创建目录 2)执行 `pnpm bootstrap`。 ```bash $ mkdir packages/foo diff --git a/package.json b/package.json index 853d3e7..6d75a16 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "description": "Pluggable enterprise-level application framework.", "scripts": { "bootstrap": "esno scripts/bootstrap.ts", + "start": "esno scripts/turbo.ts --cmd start", "build": "pnpm build:pkg", "build:pkg": "pnpm run --filter=@fe6/biu build && pnpm run --filter=@fe6/* --filter=!@fe6/biu --parallel build", "docs:dev": "vitepress dev docs --host", @@ -43,7 +44,7 @@ "resolve": "^1.22.0", "ts-node": "^10.7.0", "ts-transform-paths": "^2.0.3", - "ttypescript": "^1.5.13", + "turbo": "^1.1.6", "typescript": "^4.6.2", "vitepress": "^0.22.3", "zx": "4.3.0" diff --git a/packages/biu/bin/biu.js b/packages/biu/bin/biu.js new file mode 100755 index 0000000..099d943 --- /dev/null +++ b/packages/biu/bin/biu.js @@ -0,0 +1,9 @@ +#!/usr/bin/env node +/** @format */ + +try { + require('../dist/cli/index.js').run(); +} catch (error) { + console.error(error); + process.exit(1); +} diff --git a/packages/biu/package.json b/packages/biu/package.json index 680e467..15b43a4 100644 --- a/packages/biu/package.json +++ b/packages/biu/package.json @@ -5,12 +5,14 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "dist" + "dist", + "bin" ], + "bin": "./bin/biu.js", "scripts": { - "build": "pnpm ttsc", + "build": "pnpm tsc", "build:deps": "pnpm esno ../../scripts/bundle-deps.ts", - "start": "pnpm ttsc -w" + "start": "pnpm build -- --watch" }, "repository": { "type": "git", @@ -35,5 +37,8 @@ "externals": { "commander": "$$LOCAL" } + }, + "dependencies": { + "@fe6/biu-utils": "workspace:*" } } diff --git a/packages/biu/src/cli/index.ts b/packages/biu/src/cli/index.ts new file mode 100644 index 0000000..ad87ab6 --- /dev/null +++ b/packages/biu/src/cli/index.ts @@ -0,0 +1,38 @@ +/** @format */ + +import fs from 'fs'; +import path from 'path'; +import { logger } from '@fe6/biu-utils'; +import { Command } from '../../compiled/commander'; + +export const run = () => { + const pkg = fs.readFileSync( + path.resolve(__filename, '../../../package.json'), + 'utf-8', + ); + + const program = new Command(); + + // 版本 biu --version | biu -v + const vContent = `${logger.prefixes.info('version')} ${ + JSON.parse(pkg).version + }\n`; + program.version(vContent, '-v, --version').usage(' [options]'); + + // TODO 初始化项目 biu init + + // TODO 开发 biu dev + + // TODO 打包 biu build + + // TODO 环境测试 biu serve + + // TODO 拉取远程类型文件 ( d.ts ) biu dts + + // 执行命令 + program.parse(process.argv); + + if (!program.args.length) { + program.help(); + } +}; diff --git a/packages/biu/tsconfig.json b/packages/biu/tsconfig.json index 6f80401..e64b507 100644 --- a/packages/biu/tsconfig.json +++ b/packages/biu/tsconfig.json @@ -1,8 +1,10 @@ { "extends": "../tsconfig.base.json", "compilerOptions": { - "baseUrl": ".", + "resolveJsonModule": true, + "rootDir": "./src", "outDir": "dist" }, - "include": ["src"] + "include": ["src"], + "exclude": ["node_modules"] } diff --git a/packages/utils/compiled/cross-spawn/LICENSE b/packages/utils/compiled/cross-spawn/LICENSE new file mode 100644 index 0000000..8407b9a --- /dev/null +++ b/packages/utils/compiled/cross-spawn/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 Made With MOXY Lda + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/utils/compiled/cross-spawn/index.d.ts b/packages/utils/compiled/cross-spawn/index.d.ts new file mode 100644 index 0000000..a85105b --- /dev/null +++ b/packages/utils/compiled/cross-spawn/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for cross-spawn 6.0 +// Project: https://github.com/moxystudio/node-cross-spawn +// Definitions by: Alorel +// ExE Boss +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as child_process from 'child_process'; + +declare namespace spawn { + /** + * The `spawn()` method spawns a new process using the given `command`, with + * command line arguments in `args`. If omitted, `args` defaults to an empty array. + */ + const spawn: typeof child_process.spawn; + + /** + * The `spawn.sync()` method spawns a new process using the given `command`, with + * command line arguments in `args`. If omitted, `args` defaults to an empty array. + */ + const sync: typeof child_process.spawnSync; +} + +/** + * The `spawn()` method spawns a new process using the given `command`, with + * command line arguments in `args`. If omitted, `args` defaults to an empty array. + */ +declare function spawn(command: string, options: child_process.SpawnOptions): child_process.ChildProcess; +declare function spawn( + command: string, + args?: ReadonlyArray, + options?: child_process.SpawnOptions, +): child_process.ChildProcess; + +export = spawn; diff --git a/packages/utils/compiled/cross-spawn/index.js b/packages/utils/compiled/cross-spawn/index.js new file mode 100644 index 0000000..50ef529 --- /dev/null +++ b/packages/utils/compiled/cross-spawn/index.js @@ -0,0 +1 @@ +(function(){var n={824:function(n,t,e){"use strict";const r=e(81);const s=e(280);const o=e(72);function spawn(n,t,e){const c=s(n,t,e);const i=r.spawn(c.command,c.args,c.options);o.hookChildProcess(i,c);return i}function spawnSync(n,t,e){const c=s(n,t,e);const i=r.spawnSync(c.command,c.args,c.options);i.error=i.error||o.verifyENOENTSync(i.status,c);return i}n.exports=spawn;n.exports.spawn=spawn;n.exports.sync=spawnSync;n.exports._parse=s;n.exports._enoent=o},72:function(n){"use strict";const t=process.platform==="win32";function notFoundError(n,t){return Object.assign(new Error(`${t} ${n.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${t} ${n.command}`,path:n.command,spawnargs:n.args})}function hookChildProcess(n,e){if(!t){return}const r=n.emit;n.emit=function(t,s){if(t==="exit"){const t=verifyENOENT(s,e,"spawn");if(t){return r.call(n,"error",t)}}return r.apply(n,arguments)}}function verifyENOENT(n,e){if(t&&n===1&&!e.file){return notFoundError(e.original,"spawn")}return null}function verifyENOENTSync(n,e){if(t&&n===1&&!e.file){return notFoundError(e.original,"spawnSync")}return null}n.exports={hookChildProcess:hookChildProcess,verifyENOENT:verifyENOENT,verifyENOENTSync:verifyENOENTSync,notFoundError:notFoundError}},280:function(n,t,e){"use strict";const r=e(17);const s=e(306);const o=e(572);const c=e(839);const i=process.platform==="win32";const a=/\.(?:com|exe)$/i;const u=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function detectShebang(n){n.file=s(n);const t=n.file&&c(n.file);if(t){n.args.unshift(n.file);n.command=t;return s(n)}return n.file}function parseNonShell(n){if(!i){return n}const t=detectShebang(n);const e=!a.test(t);if(n.options.forceShell||e){const e=u.test(t);n.command=r.normalize(n.command);n.command=o.command(n.command);n.args=n.args.map((n=>o.argument(n,e)));const s=[n.command].concat(n.args).join(" ");n.args=["/d","/s","/c",`"${s}"`];n.command=process.env.comspec||"cmd.exe";n.options.windowsVerbatimArguments=true}return n}function parse(n,t,e){if(t&&!Array.isArray(t)){e=t;t=null}t=t?t.slice(0):[];e=Object.assign({},e);const r={command:n,args:t,options:e,file:undefined,original:{command:n,args:t}};return e.shell?r:parseNonShell(r)}n.exports=parse},572:function(n){"use strict";const t=/([()\][%!^"`<>&|;, *?])/g;function escapeCommand(n){n=n.replace(t,"^$1");return n}function escapeArgument(n,e){n=`${n}`;n=n.replace(/(\\*)"/g,'$1$1\\"');n=n.replace(/(\\*)$/,"$1$1");n=`"${n}"`;n=n.replace(t,"^$1");if(e){n=n.replace(t,"^$1")}return n}n.exports.command=escapeCommand;n.exports.argument=escapeArgument},839:function(n,t,e){"use strict";const r=e(147);const s=e(353);function readShebang(n){const t=150;const e=Buffer.alloc(t);let o;try{o=r.openSync(n,"r");r.readSync(o,e,0,t,0);r.closeSync(o)}catch(n){}return s(e.toString())}n.exports=readShebang},306:function(n,t,e){"use strict";const r=e(17);const s=e(135);const o=e(694);function resolveCommandAttempt(n,t){const e=n.options.env||process.env;const c=process.cwd();const i=n.options.cwd!=null;const a=i&&process.chdir!==undefined&&!process.chdir.disabled;if(a){try{process.chdir(n.options.cwd)}catch(n){}}let u;try{u=s.sync(n.command,{path:e[o({env:e})],pathExt:t?r.delimiter:undefined})}catch(n){}finally{if(a){process.chdir(c)}}if(u){u=r.resolve(i?n.options.cwd:"",u)}return u}function resolveCommand(n){return resolveCommandAttempt(n)||resolveCommandAttempt(n,true)}n.exports=resolveCommand},625:function(n,t,e){var r=e(147);var s;if(process.platform==="win32"||global.TESTING_WINDOWS){s=e(871)}else{s=e(708)}n.exports=isexe;isexe.sync=sync;function isexe(n,t,e){if(typeof t==="function"){e=t;t={}}if(!e){if(typeof Promise!=="function"){throw new TypeError("callback not provided")}return new Promise((function(e,r){isexe(n,t||{},(function(n,t){if(n){r(n)}else{e(t)}}))}))}s(n,t||{},(function(n,r){if(n){if(n.code==="EACCES"||t&&t.ignoreErrors){n=null;r=false}}e(n,r)}))}function sync(n,t){try{return s.sync(n,t||{})}catch(n){if(t&&t.ignoreErrors||n.code==="EACCES"){return false}else{throw n}}}},708:function(n,t,e){n.exports=isexe;isexe.sync=sync;var r=e(147);function isexe(n,t,e){r.stat(n,(function(n,r){e(n,n?false:checkStat(r,t))}))}function sync(n,t){return checkStat(r.statSync(n),t)}function checkStat(n,t){return n.isFile()&&checkMode(n,t)}function checkMode(n,t){var e=n.mode;var r=n.uid;var s=n.gid;var o=t.uid!==undefined?t.uid:process.getuid&&process.getuid();var c=t.gid!==undefined?t.gid:process.getgid&&process.getgid();var i=parseInt("100",8);var a=parseInt("010",8);var u=parseInt("001",8);var f=i|a;var p=e&u||e&a&&s===c||e&i&&r===o||e&f&&o===0;return p}},871:function(n,t,e){n.exports=isexe;isexe.sync=sync;var r=e(147);function checkPathExt(n,t){var e=t.pathExt!==undefined?t.pathExt:process.env.PATHEXT;if(!e){return true}e=e.split(";");if(e.indexOf("")!==-1){return true}for(var r=0;r{const t=n.env||process.env;const e=n.platform||process.platform;if(e!=="win32"){return"PATH"}return Object.keys(t).reverse().find((n=>n.toUpperCase()==="PATH"))||"Path"};n.exports=pathKey;n.exports["default"]=pathKey},353:function(n,t,e){"use strict";const r=e(700);n.exports=(n="")=>{const t=n.match(r);if(!t){return null}const[e,s]=t[0].replace(/#! ?/,"").split(" ");const o=e.split("/").pop();if(o==="env"){return s}return s?`${o} ${s}`:o}},700:function(n){"use strict";n.exports=/^#!(.*)/},135:function(n,t,e){const r=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys";const s=e(17);const o=r?";":":";const c=e(625);const getNotFoundError=n=>Object.assign(new Error(`not found: ${n}`),{code:"ENOENT"});const getPathInfo=(n,t)=>{const e=t.colon||o;const s=n.match(/\//)||r&&n.match(/\\/)?[""]:[...r?[process.cwd()]:[],...(t.path||process.env.PATH||"").split(e)];const c=r?t.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"";const i=r?c.split(e):[""];if(r){if(n.indexOf(".")!==-1&&i[0]!=="")i.unshift("")}return{pathEnv:s,pathExt:i,pathExtExe:c}};const which=(n,t,e)=>{if(typeof t==="function"){e=t;t={}}if(!t)t={};const{pathEnv:r,pathExt:o,pathExtExe:i}=getPathInfo(n,t);const a=[];const step=e=>new Promise(((o,c)=>{if(e===r.length)return t.all&&a.length?o(a):c(getNotFoundError(n));const i=r[e];const u=/^".*"$/.test(i)?i.slice(1,-1):i;const f=s.join(u,n);const p=!u&&/^\.[\\\/]/.test(n)?n.slice(0,2)+f:f;o(subStep(p,e,0))}));const subStep=(n,e,r)=>new Promise(((s,u)=>{if(r===o.length)return s(step(e+1));const f=o[r];c(n+f,{pathExt:i},((o,c)=>{if(!o&&c){if(t.all)a.push(n+f);else return s(n+f)}return s(subStep(n,e,r+1))}))}));return e?step(0).then((n=>e(null,n)),e):step(0)};const whichSync=(n,t)=>{t=t||{};const{pathEnv:e,pathExt:r,pathExtExe:o}=getPathInfo(n,t);const i=[];for(let a=0;a","license":"MIT"} diff --git a/packages/utils/package.json b/packages/utils/package.json index 90562a4..3108045 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -2,8 +2,10 @@ "name": "@fe6/biu-utils", "version": "0.0.0", "description": "@fe6/biu-utils", - "main": "src/index.ts", + "main": "dist/index.js", + "typings": "dist/index.d.ts", "files": [ + "compiled", "dist" ], "scripts": { @@ -22,22 +24,24 @@ "license": "MIT", "bugs": "https://github.com/fe6/biu/issues", "publishConfig": { - "access": "public", - "main": "dist/index.js", - "typings": "dist/index.d.ts" + "access": "public" }, "devDependencies": { + "@types/cross-spawn": "^6.0.2", "@types/yargs-parser": "^21.0.0", "chalk": "^5.0.1", + "cross-spawn": "^7.0.3", "yargs-parser": "^21.0.1" }, "compiledConfig": { "deps": [ "chalk", - "yargs-parser" + "yargs-parser", + "cross-spawn" ], "externals": { "chalk": "$$LOCAL", + "cross-spawn": "$$LOCAL", "yargs-parser": "$$LOCAL" } } diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index a47df15..49da37d 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -6,6 +6,8 @@ import * as logger from './logger'; // ? deps import yParser from '../compiled/yargs-parser'; +import chalk from '../compiled/chalk'; +import crossSpawn from '../compiled/cross-spawn'; // ? deps -export { logger, yParser }; +export { logger, yParser, chalk, crossSpawn }; diff --git a/packages/utils/src/logger.ts b/packages/utils/src/logger.ts index 87a7d6c..802bc89 100644 --- a/packages/utils/src/logger.ts +++ b/packages/utils/src/logger.ts @@ -14,9 +14,10 @@ export const prefixes = { error: `${pkgName}${errorChalk('[error]')} -`, warn: `${pkgName}${warnChalk('[warn]')} -`, ready: `${pkgName}${chalk.green('[ready]')} -`, - info: `${pkgName}${chalk.blue('[info]')} -`, event: `${pkgName}${chalk.magenta('[event]')} -`, debug: `${pkgName}${chalk.gray('[debug]')} -`, + info: (type: string = 'info') => + `${pkgName}${type ? chalk.blue(`[${type}]`) : ''} -`, }; export function empty() { @@ -50,7 +51,7 @@ export function ready(...message: any[]) { } export function info(...message: any[]) { - console.log(prefixes.info, ...message); + console.log(prefixes.info(), ...message); empty(); } diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json index 6f80401..f7deca6 100644 --- a/packages/utils/tsconfig.json +++ b/packages/utils/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../tsconfig.base.json", "compilerOptions": { - "baseUrl": ".", + "rootDir": "./src", "outDir": "dist" }, "include": ["src"] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b502689..288a677 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,7 +22,7 @@ importers: resolve: ^1.22.0 ts-node: ^10.7.0 ts-transform-paths: ^2.0.3 - ttypescript: ^1.5.13 + turbo: ^1.1.6 typescript: ^4.6.2 vitepress: ^0.22.3 zx: 4.3.0 @@ -45,25 +45,38 @@ importers: resolve: registry.npmmirror.com/resolve/1.22.0 ts-node: registry.npmmirror.com/ts-node/10.7.0_e79e62fe450383fd2d418267dc75e645 ts-transform-paths: registry.npmmirror.com/ts-transform-paths/2.0.3 - ttypescript: registry.npmmirror.com/ttypescript/1.5.13_ts-node@10.7.0+typescript@4.6.2 + turbo: registry.npmmirror.com/turbo/1.1.6 typescript: registry.npmmirror.com/typescript/4.6.2 vitepress: registry.npmmirror.com/vitepress/0.22.3 zx: registry.npmmirror.com/zx/4.3.0 + demos/biu: + specifiers: + '@fe6/biu': workspace:* + devDependencies: + '@fe6/biu': link:../../packages/biu + packages/biu: specifiers: + '@fe6/biu-utils': workspace:* commander: ^9.1.0 + dependencies: + '@fe6/biu-utils': link:../utils devDependencies: commander: registry.npmmirror.com/commander/9.1.0 packages/utils: specifiers: + '@types/cross-spawn': ^6.0.2 '@types/yargs-parser': ^21.0.0 chalk: ^5.0.1 + cross-spawn: ^7.0.3 yargs-parser: ^21.0.1 devDependencies: + '@types/cross-spawn': registry.npmmirror.com/@types/cross-spawn/6.0.2 '@types/yargs-parser': registry.npmmirror.com/@types/yargs-parser/21.0.0 chalk: registry.npmmirror.com/chalk/5.0.1 + cross-spawn: registry.npmmirror.com/cross-spawn/7.0.3 yargs-parser: registry.npmmirror.com/yargs-parser/21.0.1 packages: @@ -624,6 +637,14 @@ packages: '@types/responselike': registry.npmmirror.com/@types/responselike/1.0.0 dev: true + registry.npmmirror.com/@types/cross-spawn/6.0.2: + resolution: {integrity: sha512-KuwNhp3eza+Rhu8IFI5HUXRP0LIhqH5cAjubUvGXXthh4YYBuP2ntwEX+Cz8GJoZUHlKo247wPWOfA9LYEq4cw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/cross-spawn/-/cross-spawn-6.0.2.tgz} + name: '@types/cross-spawn' + version: 6.0.2 + dependencies: + '@types/node': registry.npmmirror.com/@types/node/17.0.21 + dev: true + registry.npmmirror.com/@types/fs-extra/9.0.13: resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/fs-extra/-/fs-extra-9.0.13.tgz} name: '@types/fs-extra' @@ -3439,19 +3460,145 @@ packages: version: 1.14.1 dev: true - registry.npmmirror.com/ttypescript/1.5.13_ts-node@10.7.0+typescript@4.6.2: - resolution: {integrity: sha512-KT/RBfGGlVJFqEI8cVvI3nMsmYcFvPSZh8bU0qX+pAwbi7/ABmYkzn7l/K8skw0xmYjVCoyaV6WLsBQxdadybQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/ttypescript/-/ttypescript-1.5.13.tgz} - id: registry.npmmirror.com/ttypescript/1.5.13 - name: ttypescript - version: 1.5.13 + registry.npmmirror.com/turbo-darwin-64/1.1.6: + resolution: {integrity: sha512-xzl79T7mPKaIGhMBCAzpTvXkbFNZaMyeOMsNXxVT5dTY+d3FwLFfbqHIoG1dH745TbH6i67bxtt70lKdQa+qdQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-darwin-64/-/turbo-darwin-64-1.1.6.tgz} + name: turbo-darwin-64 + version: 1.1.6 + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-darwin-arm64/1.1.6: + resolution: {integrity: sha512-r0D+Kfwcaqec5h9Xa4T/VD6mWZ2LQr+zOEBBL6UA15htgel06B2eXiGdjRiw4i7ieV80tEBEDdz9tSWJBhAL/Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-darwin-arm64/-/turbo-darwin-arm64-1.1.6.tgz} + name: turbo-darwin-arm64 + version: 1.1.6 + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-freebsd-64/1.1.6: + resolution: {integrity: sha512-v5MJeRcyeCDF3La40TOub0+/OuGGFuLzlVHb4jYxthESbtLve1H23bDiL+4gCQgPYOsKMOvKQpuoMaKW2gxk7A==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-freebsd-64/-/turbo-freebsd-64-1.1.6.tgz} + name: turbo-freebsd-64 + version: 1.1.6 + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-freebsd-arm64/1.1.6: + resolution: {integrity: sha512-5gm3r+M5f/Idt/pggyCQ+MZSlaUdxUeb/4LtPohhWOoj4PYo1o5kwInaRlckr7uV36E4/npDvz9cDV96Pohejg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-freebsd-arm64/-/turbo-freebsd-arm64-1.1.6.tgz} + name: turbo-freebsd-arm64 + version: 1.1.6 + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-linux-32/1.1.6: + resolution: {integrity: sha512-dLc1Vd/LQP5n3NGLMf+cdaK99sMWvHdDvTUSrSwoYDy5fWFpUm0E12lAxRH3tikX2m7Kfcy2uY5xSJIuq5xzYQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-linux-32/-/turbo-linux-32-1.1.6.tgz} + name: turbo-linux-32 + version: 1.1.6 + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-linux-64/1.1.6: + resolution: {integrity: sha512-V4rb41yQUA+vPDgXc06oHmKbgrBUbwm09oRtjvmlIQU8zX8qujMPZIun8tGP4NuzErJXGzD3WDgj7VSsO23IIw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-linux-64/-/turbo-linux-64-1.1.6.tgz} + name: turbo-linux-64 + version: 1.1.6 + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-linux-arm/1.1.6: + resolution: {integrity: sha512-zAaIa0+EhRYYkM51ruB1LCUqyeigK66A+KfXZ3Y9+aiKg7EYbDvuv+ReD4srLPKoIuAxR5dYlk5RVhSKejt2Cw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-linux-arm/-/turbo-linux-arm-1.1.6.tgz} + name: turbo-linux-arm + version: 1.1.6 + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-linux-arm64/1.1.6: + resolution: {integrity: sha512-QsE7gow3WxWXKwNWJX4DIJys6xc6Up4/icjdTZCZbglPLwuG2UiUzjJ2+beXxVU4EmpQF6NwKubHCtrs8m8/kQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-linux-arm64/-/turbo-linux-arm64-1.1.6.tgz} + name: turbo-linux-arm64 + version: 1.1.6 + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-linux-mips64le/1.1.6: + resolution: {integrity: sha512-098DB9daXoI6LRCkuOv1Pqim+H4wXZrFza9Xd7zJIel1WmxEgNsHqWpSH5Jn2J92LbkWl+tfN1+myw4+a4ESfw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-linux-mips64le/-/turbo-linux-mips64le-1.1.6.tgz} + name: turbo-linux-mips64le + version: 1.1.6 + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-linux-ppc64le/1.1.6: + resolution: {integrity: sha512-U5A1mnsGM994h/1VT4FbsV/bb+I0fgvkY5/TTX7MfA9Iwt0SxsNlh+Jgofe1svPz0CKEe6Hl2WQSGHTlBPJb5Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-linux-ppc64le/-/turbo-linux-ppc64le-1.1.6.tgz} + name: turbo-linux-ppc64le + version: 1.1.6 + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-windows-32/1.1.6: + resolution: {integrity: sha512-0C+/EI11j8ABtI6O2n+NYL2osDI6moo7YL8pqiWbNrdEGI2KbeCTVQpruUH+GONsMov06pR4BouL9UT2jSpG0g==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-windows-32/-/turbo-windows-32-1.1.6.tgz} + name: turbo-windows-32 + version: 1.1.6 + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo-windows-64/1.1.6: + resolution: {integrity: sha512-O2kC+7+zuMjFIi6mpU1qz+Bv27TcHkkCczcDNVU29G52pm5lwj7BZ+/gu+EPJSnF5VrgdA6Oru6KVXPRS1q+Cg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo-windows-64/-/turbo-windows-64-1.1.6.tgz} + name: turbo-windows-64 + version: 1.1.6 + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + registry.npmmirror.com/turbo/1.1.6: + resolution: {integrity: sha512-pZTc6Sb5MtK/X/qhiDSssc8AZWoUoYf14ZqYjvDWg/aEtqgwYorVJqfRcj4XOXOqtVZ3gO/91eXwdyh/q2aQHA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turbo/-/turbo-1.1.6.tgz} + name: turbo + version: 1.1.6 hasBin: true - peerDependencies: - ts-node: '>=8.0.2' - typescript: '>=3.2.2' - dependencies: - resolve: registry.npmmirror.com/resolve/1.22.0 - ts-node: registry.npmmirror.com/ts-node/10.7.0_e79e62fe450383fd2d418267dc75e645 - typescript: registry.npmmirror.com/typescript/4.6.2 + requiresBuild: true + optionalDependencies: + turbo-darwin-64: registry.npmmirror.com/turbo-darwin-64/1.1.6 + turbo-darwin-arm64: registry.npmmirror.com/turbo-darwin-arm64/1.1.6 + turbo-freebsd-64: registry.npmmirror.com/turbo-freebsd-64/1.1.6 + turbo-freebsd-arm64: registry.npmmirror.com/turbo-freebsd-arm64/1.1.6 + turbo-linux-32: registry.npmmirror.com/turbo-linux-32/1.1.6 + turbo-linux-64: registry.npmmirror.com/turbo-linux-64/1.1.6 + turbo-linux-arm: registry.npmmirror.com/turbo-linux-arm/1.1.6 + turbo-linux-arm64: registry.npmmirror.com/turbo-linux-arm64/1.1.6 + turbo-linux-mips64le: registry.npmmirror.com/turbo-linux-mips64le/1.1.6 + turbo-linux-ppc64le: registry.npmmirror.com/turbo-linux-ppc64le/1.1.6 + turbo-windows-32: registry.npmmirror.com/turbo-windows-32/1.1.6 + turbo-windows-64: registry.npmmirror.com/turbo-windows-64/1.1.6 dev: true registry.npmmirror.com/type-fest/0.18.1: diff --git a/scripts/bootstrap.ts b/scripts/bootstrap.ts index f362c39..ee10c72 100644 --- a/scripts/bootstrap.ts +++ b/scripts/bootstrap.ts @@ -1,6 +1,7 @@ /** @format */ // Fork from https://github.com/umijs/umi-next/blob/master/scripts/utils.ts + // NOTE 所有功能($、cd、fetch等)都可以直接使用,无需任何导入。 // NOTE 或者显式导入全局变量(以便在VS代码中更好地自动完成)。 import 'zx/globals'; @@ -86,7 +87,7 @@ import { setExcludeFolder } from './utils'; `{ "extends": "../tsconfig.base.json", "compilerOptions": { - "baseUrl": ".", + "rootDir": "./src", "outDir": "dist" }, "include": ["src"] diff --git a/scripts/bundle-deps.ts b/scripts/bundle-deps.ts index 698d7a2..7d3a473 100644 --- a/scripts/bundle-deps.ts +++ b/scripts/bundle-deps.ts @@ -1,12 +1,12 @@ /** @format */ -// fork from https://github.com/umijs/umi-next/blob/master/scripts/bundleDeps.ts +// Fork from https://github.com/umijs/umi-next/blob/master/scripts/bundleDeps.ts // @ts-ignore import ncc from '@vercel/ncc'; import { Package } from 'dts-packer'; import resolve from 'resolve'; import 'zx/globals'; -import { logger } from '@fe6/biu-utils'; +import * as logger from '@fe6/biu-utils/src/logger'; export async function buildDep(opts: any) { logger.info(`Build dep ${opts.pkgName || opts.file}`); diff --git a/scripts/postinstall.ts b/scripts/postinstall.ts index f94af32..0edbf18 100644 --- a/scripts/postinstall.ts +++ b/scripts/postinstall.ts @@ -1,8 +1,10 @@ /** @format */ +// Fork https://github.com/umijs/umi-next/blob/master/scripts/postinstall.ts + import { readFileSync, writeFileSync } from 'fs'; import { join } from 'path'; -import { logger } from '@fe6/biu-utils'; +import * as logger from '@fe6/biu-utils/src/logger'; // FIX bundle deps error // ref: https://github.com/isaacs/node-graceful-fs/commit/e61a20a052b838f420b98195c232a824a6ac04ee diff --git a/scripts/turbo.ts b/scripts/turbo.ts new file mode 100644 index 0000000..c037d4b --- /dev/null +++ b/scripts/turbo.ts @@ -0,0 +1,70 @@ +/** @format */ + +// Fork from https://github.com/umijs/umi-next/blob/master/scripts/turbo.ts + +import * as logger from '@fe6/biu-utils/src/logger'; +import spawn from '@fe6/biu-utils/compiled/cross-spawn'; +import yArgs from '@fe6/biu-utils/compiled/yargs-parser'; +import { join } from 'path'; + +(async () => { + const args = yArgs(process.argv.slice(2)); + const scope = args.scope || '!@demo/*'; + const extra = (args._ || []).join(' '); + + await turbo({ + cmd: args.cmd, + scope, + extra, + cache: args.cache, + parallel: args.parallel, + }); +})(); + +/** + * Why not use zx ? + * - `zx` not support color stdin on subprocess + * - see https://github.com/google/zx/blob/main/docs/known-issues.md#colors-in-subprocess + * https://github.com/google/zx/issues/212 + */ +async function cmd(command: string) { + const result = spawn.sync(command, { + stdio: 'inherit', + shell: true, + cwd: join(__dirname, '../'), + }); + if (result.status !== 0) { + // sub package command don't stop when execute fail. + // display exit + logger.error(`Execute command error (${command})`); + process.exit(1); + } + return result; +} + +async function turbo(opts: { + scope: string; + cmd: string; + extra?: string; + cache?: boolean; + parallel?: boolean; +}) { + const extraCmd = opts.extra ? `-- -- ${opts.extra}` : ''; + const cacheCmd = opts.cache === false ? '--no-cache --force' : ''; + const parallelCmd = opts.parallel ? '--parallel' : ''; + + const options = [ + opts.cmd, + `--cache-dir=".turbo"`, + `--scope="${opts.scope}"`, + `--no-deps`, + `--include-dependencies`, + cacheCmd, + parallelCmd, + extraCmd, + ] + .filter(Boolean) + .join(' '); + + return cmd(`turbo run ${options}`); +} diff --git a/scripts/utils.ts b/scripts/utils.ts index 1dda7e7..ba6905a 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -1,9 +1,10 @@ /** @format */ // Fork from https://github.com/umijs/umi-next/blob/master/scripts/utils.ts + import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'; import { join } from 'path'; -import { logger } from '@fe6/biu-utils'; +import * as logger from '@fe6/biu-utils/src/logger'; export function getPkgs(opts?: { base?: string }): string[] { const base = opts?.base || join(__dirname, '../packages'); diff --git a/tsconfig.base.json b/tsconfig.base.json index cebe386..5a951d9 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -10,16 +10,15 @@ "strict": true, "skipLibCheck": true, "target": "es2015", - "jsx": "preserve", - "paths": { - "@fe6/biu-utils": ["./packages/utils"] - } + "jsx": "preserve" }, "exclude": [ "**/node_modules", "**/examples", "**/dist", "**/fixtures", - "**/*.test.ts" + "**/*.test.ts", + "script", + "compiled" ] } diff --git a/turbo.json b/turbo.json new file mode 100644 index 0000000..d807e4f --- /dev/null +++ b/turbo.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://turborepo.org/schema.json", + "baseBranch": "origin/master", + "pipeline": { + "build": { + "dependsOn": ["^build"], + "outputs": ["dist/**"] + }, + "build:extra": { + "cache": false + }, + "start": { + "cache": false + } + }, + "globalDependencies": ["tsconfig.base.json", "tsconfig.json"] +}