Skip to content

Commit

Permalink
feat($cmd): layout finish
Browse files Browse the repository at this point in the history
  • Loading branch information
iq9891 committed Mar 21, 2022
1 parent 73829e1 commit ccf1084
Show file tree
Hide file tree
Showing 23 changed files with 414 additions and 45 deletions.
9 changes: 9 additions & 0 deletions demos/biu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "demo-biu",
"scripts": {
"start": "biu"
},
"devDependencies": {
"@fe6/biu": "workspace:*"
}
}
14 changes: 8 additions & 6 deletions docs/introduce/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $ pnpm i

### 启动 start 命令

BIU 用 turbo 同时检测所有 packages 中 src 的变化。

本地开发 BIU 必开命令,用于编译 src 下的 TypeScript 文件到 dist 目录,同时监听文件变更,有变更时增量编译。

```bash
Expand All @@ -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
```

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions packages/biu/bin/biu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
/** @format */

try {
require('../dist/cli/index.js').run();
} catch (error) {
console.error(error);
process.exit(1);
}
11 changes: 8 additions & 3 deletions packages/biu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -35,5 +37,8 @@
"externals": {
"commander": "$$LOCAL"
}
},
"dependencies": {
"@fe6/biu-utils": "workspace:*"
}
}
38 changes: 38 additions & 0 deletions packages/biu/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -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('<command> [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();
}
};
6 changes: 4 additions & 2 deletions packages/biu/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"resolveJsonModule": true,
"rootDir": "./src",
"outDir": "dist"
},
"include": ["src"]
"include": ["src"],
"exclude": ["node_modules"]
}
21 changes: 21 additions & 0 deletions packages/utils/compiled/cross-spawn/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Made With MOXY Lda <hello@moxy.studio>

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.
36 changes: 36 additions & 0 deletions packages/utils/compiled/cross-spawn/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Type definitions for cross-spawn 6.0
// Project: https://github.com/moxystudio/node-cross-spawn
// Definitions by: Alorel <https://github.com/Alorel>
// ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />

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<string>,
options?: child_process.SpawnOptions,
): child_process.ChildProcess;

export = spawn;
1 change: 1 addition & 0 deletions packages/utils/compiled/cross-spawn/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/utils/compiled/cross-spawn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"cross-spawn","version":"7.0.3","author":"André Cruz <andre@moxy.studio>","license":"MIT"}
14 changes: 9 additions & 5 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
5 changes: 3 additions & 2 deletions packages/utils/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "./src",
"outDir": "dist"
},
"include": ["src"]
Expand Down
Loading

0 comments on commit ccf1084

Please sign in to comment.