Skip to content

Commit

Permalink
local-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
LAMMUpro committed Jan 7, 2024
1 parent 5ecf13b commit a92c94d
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 13 deletions.
3 changes: 3 additions & 0 deletions packages/local-cli/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface BaseObj<T = string | number> {
[key: string]: T
}
5 changes: 0 additions & 5 deletions packages/local-cli/index.js

This file was deleted.

35 changes: 35 additions & 0 deletions packages/local-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "local-cli",
"version": "1.0.0",
"description": "本地执行脚手架,通过脚手架来设置一些东西",
"main": "index.js",
"author": "lammu",
"type": "module",
"bin": {
"local-cli": "./dist/index.esm.js"
},
"dependencies": {
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.1",
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.10.0",
"rollup": "^3.25.2",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.5.3",
"typescript": "^5.1.3"
},
"license": "MIT",
"scripts": {
"dev": "rollup -w -c",
"build:lib": "tsc -b ./tsconfig.lib.json",
"build": "rollup -c"
}
}
8 changes: 0 additions & 8 deletions packages/local-cli/package.yaml

This file was deleted.

26 changes: 26 additions & 0 deletions packages/local-cli/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import { terser } from "rollup-plugin-terser";
import cleanup from "rollup-plugin-cleanup";

export default [
{
input: "./src/index.ts",
output: {
dir: "dist",
format: "cjs",
entryFileNames: "[name].cjs.js",
},
plugins: [resolve(), commonjs(), typescript(), terser(), cleanup()],
},
{
input: "./src/index.ts",
output: {
dir: "dist",
format: "esm",
entryFileNames: "[name].esm.js",
},
plugins: [resolve(), commonjs(), typescript(), terser(), cleanup()],
},
];
31 changes: 31 additions & 0 deletions packages/local-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
import * as yaml from 'js-yaml';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import { ConfigDto, ConfigZod } from './types';

// process.cwd()

function main(config: ConfigDto) {
/**
* 设置软链接
*/
if (config.symlink) {
for (let i = 0; i < config.symlink.length; i++) {
const link = config.symlink[i];
fse.ensureSymlinkSync(link.from, link.to);
}
}
/**
* 设置硬链接
*/
}

try {
console.log('>>> local-cli脚手架启动');
const config = yaml.load(fs.readFileSync('./monorepo.yaml', 'utf8')) as ConfigDto;
main(ConfigZod.parse(config));
console.log('>>> local-cli脚手架结束');
} catch (e) {
console.log(e);
}
18 changes: 18 additions & 0 deletions packages/local-cli/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { z } from 'zod';

/** 链接配置 */
const linkZod = z.object({
/** 源目录 */
from: z.string(),
/** 目标目录 */
to: z.string(),
})

export const ConfigZod = z.object({
/** 软链接配置 */
symlink: z.array(linkZod).optional(),
/** 硬链接配置 */
hardlink: z.array(linkZod).optional(),
})
export type ConfigDto = z.infer<typeof ConfigZod>;

1 change: 1 addition & 0 deletions packages/local-cli/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

18 changes: 18 additions & 0 deletions packages/local-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "esnext", // esnext, es2020
"target": "es5",
"lib": ["esnext", "dom"],
"outDir": "dist",
"strict": true,
"sourceMap": false,
"declaration": true,
"declarationDir": "dist/types",
"skipLibCheck": true,
"moduleResolution": "Node",
"baseUrl": "./",
"paths": {},
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"],
}
14 changes: 14 additions & 0 deletions packages/local-cli/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "esnext", // esnext, es2020
"target": "es5",
"strict": true,
"lib": ["esnext", "dom"],
"outDir": "lib",
"sourceMap": false,
"declaration": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit a92c94d

Please sign in to comment.