@pubinfo/cli 0.6.10 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { fileURLToPath } from 'node:url'
4
+ import { runMain } from '../dist/index.mjs'
5
+
6
+ global.__pubinfo_cli__ = {
7
+ startTime: Date.now(),
8
+ entry: fileURLToPath(import.meta.url),
9
+ }
10
+
11
+ runMain()
@@ -0,0 +1,31 @@
1
+ import { build } from '@pubinfo/vite';
2
+ import { defineCommand, runMain } from 'citty';
3
+ import { loadConfig } from 'unconfig';
4
+ import command$1 from './generate.mjs';
5
+ import 'node:fs/promises';
6
+ import 'pathe';
7
+ import 'node:fs';
8
+ import 'node:module';
9
+ import 'node:path';
10
+
11
+ const command = defineCommand({
12
+ meta: {
13
+ name: "build",
14
+ description: "Build the application for production"
15
+ },
16
+ async run() {
17
+ await runMain(command$1);
18
+ const { config } = await loadConfig({
19
+ sources: [
20
+ { files: "pubinfo.config" }
21
+ ],
22
+ merge: false
23
+ });
24
+ const inlineConfig = typeof config.vite === "function" ? await config.vite({ mode: "production", command: "build" }) : config.vite;
25
+ await build({
26
+ ...inlineConfig
27
+ });
28
+ }
29
+ });
30
+
31
+ export { command as default };
@@ -0,0 +1,36 @@
1
+ import { createServer } from '@pubinfo/vite';
2
+ import { defineCommand, runMain } from 'citty';
3
+ import { loadConfig } from 'unconfig';
4
+ import command$1 from './generate.mjs';
5
+ import 'node:fs/promises';
6
+ import 'pathe';
7
+ import 'node:fs';
8
+ import 'node:module';
9
+ import 'node:path';
10
+
11
+ const command = defineCommand({
12
+ meta: {
13
+ name: "dev",
14
+ description: "Run Pubinfo development server"
15
+ },
16
+ async run() {
17
+ await runMain(command$1);
18
+ const { config } = await loadConfig({
19
+ sources: [
20
+ { files: "pubinfo.config" }
21
+ ],
22
+ merge: false
23
+ });
24
+ const inlineConfig = typeof config.vite === "function" ? await config.vite({ mode: "development", command: "serve" }) : config.vite;
25
+ const server = await createServer({
26
+ ...inlineConfig,
27
+ mode: "development",
28
+ configFile: false
29
+ });
30
+ await server.listen();
31
+ server.printUrls();
32
+ server.bindCLIShortcuts({ print: true });
33
+ }
34
+ });
35
+
36
+ export { command as default };
@@ -0,0 +1,87 @@
1
+ import { rm, mkdir } from 'node:fs/promises';
2
+ import { defineCommand } from 'citty';
3
+ import { resolve } from 'pathe';
4
+ import { writeFileSync } from 'node:fs';
5
+ import { createRequire } from 'node:module';
6
+ import { join } from 'node:path';
7
+
8
+ function writeTsconfig(filePath) {
9
+ const require = createRequire(import.meta.url);
10
+ const resolveDeps = (name, path) => join(require.resolve(name), path);
11
+ writeFileSync(filePath, `/* eslint-disable */
12
+ /* prettier-ignore */
13
+ // Generated by pubinfo
14
+ {
15
+ "$schema": "https://json.schemastore.org/tsconfig",
16
+ "display": "Base",
17
+ "compilerOptions": {
18
+ "target": "ESNext",
19
+ "jsx": "preserve",
20
+ "jsxImportSource": "vue",
21
+ "lib": [
22
+ "ESNext",
23
+ "DOM",
24
+ "DOM.Iterable"
25
+ ],
26
+ "useDefineForClassFields": true,
27
+ "baseUrl": ".",
28
+ "module": "ESNext",
29
+ "moduleResolution": "Bundler",
30
+ "paths": {
31
+ "@/*": ["../src/*"],
32
+ "#/*": ["../types/*"],
33
+
34
+ // deps
35
+ "vue": ["${resolveDeps("vue", "../")}"],
36
+ "vue-router": ["${resolveDeps("vue-router", "../")}"],
37
+ "pinia": ["${resolveDeps("pinia", "../")}"],
38
+ "unocss": ["${resolveDeps("unocss", "../")}"],
39
+ },
40
+ "resolveJsonModule": true,
41
+ "types": [
42
+ "pubinfo/types"
43
+ ],
44
+ "allowImportingTsExtensions": true,
45
+ "allowJs": false,
46
+ "strict": true,
47
+ "noEmit": true,
48
+ "sourceMap": true,
49
+ "esModuleInterop": true,
50
+ "isolatedModules": true,
51
+ "skipLibCheck": true
52
+ },
53
+ "include": [
54
+ "../src/**/*.ts",
55
+ "../src/**/*.tsx",
56
+ "../src/**/*.vue",
57
+ "../pubinfo.config.ts",
58
+ "../.pubinfo/**/*.ts",
59
+ "../.pubinfo/**/*.tsx",
60
+ "../.pubinfo/**/*.vue",
61
+ "../.pubinfo/**/*.d.ts",
62
+ "../types/**/*.d.ts",
63
+ "../**/*",
64
+ ".."
65
+ ],
66
+ "exclude": [
67
+ "dist",
68
+ "node_modules",
69
+ "assets"
70
+ ],
71
+ }`);
72
+ }
73
+
74
+ const command = defineCommand({
75
+ meta: {
76
+ name: "generate",
77
+ description: "Generate Pubinfo static site"
78
+ },
79
+ async run() {
80
+ const cwd = resolve(".");
81
+ await rm(resolve(cwd, ".pubinfo"), { recursive: true, force: true });
82
+ await mkdir(resolve(cwd, ".pubinfo"), { recursive: true });
83
+ writeTsconfig(resolve(cwd, ".pubinfo/tsconfig.app.json"));
84
+ }
85
+ });
86
+
87
+ export { command as default };
@@ -0,0 +1,7 @@
1
+ import * as citty from 'citty';
2
+
3
+ declare const main: citty.CommandDef<citty.ArgsDef>;
4
+
5
+ declare const runMain: () => Promise<void>;
6
+
7
+ export { main, runMain };
@@ -0,0 +1,7 @@
1
+ import * as citty from 'citty';
2
+
3
+ declare const main: citty.CommandDef<citty.ArgsDef>;
4
+
5
+ declare const runMain: () => Promise<void>;
6
+
7
+ export { main, runMain };
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { defineCommand, runMain as runMain$1 } from 'citty';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ const name = "@pubinfo/cli";
5
+ const version = "2.0.0-beta.2";
6
+ const description = "CLI for Pubinfo";
7
+ const cliPkg = {
8
+ name: name,
9
+ version: version,
10
+ description: description};
11
+
12
+ const _rDefault = (r) => r.default || r;
13
+ const commands = {
14
+ dev: () => import('./chunks/dev.mjs').then(_rDefault),
15
+ build: () => import('./chunks/build.mjs').then(_rDefault),
16
+ generate: () => import('./chunks/generate.mjs').then(_rDefault)
17
+ };
18
+
19
+ const main = defineCommand({
20
+ meta: {
21
+ name: cliPkg.name,
22
+ version: cliPkg.version,
23
+ description: cliPkg.description
24
+ },
25
+ subCommands: commands
26
+ });
27
+
28
+ globalThis.__pubinfo_cli__ = globalThis.__pubinfo_cli__ || {
29
+ // Programmatic usage fallback
30
+ startTime: Date.now(),
31
+ entry: fileURLToPath(
32
+ new URL(
33
+ import.meta.url.endsWith(".ts") ? "../bin/pubinfo.mjs" : "../../bin/pubinfo.mjs",
34
+ import.meta.url
35
+ )
36
+ )
37
+ };
38
+ const runMain = () => runMain$1(main);
39
+
40
+ export { main, runMain };
package/package.json CHANGED
@@ -1,30 +1,36 @@
1
1
  {
2
2
  "name": "@pubinfo/cli",
3
3
  "type": "module",
4
- "version": "0.6.10",
4
+ "version": "2.0.0-beta.2",
5
+ "description": "CLI for Pubinfo",
6
+ "exports": {
7
+ ".": "./bin/pubinfo.mjs"
8
+ },
9
+ "types": "./dist/index.d.ts",
5
10
  "bin": {
6
- "pubinfo": "./dist/cli.cjs"
11
+ "pubinfo": "./bin/pubinfo.mjs"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "dist"
16
+ ],
17
+ "peerDependencies": {
18
+ "@pubinfo/vite": "2.0.0-beta.2"
7
19
  },
8
20
  "dependencies": {
9
- "cfonts": "^3.3.0",
10
- "chalk": "^5.3.0",
11
- "commander": "^12.1.0",
12
- "consola": "^3.2.3",
13
- "execa": "^9.3.0",
14
- "fast-glob": "^3.3.2",
15
- "lodash-es": "^4.17.21",
16
- "mlly": "^1.7.1",
21
+ "citty": "^0.1.6",
17
22
  "pathe": "^1.1.2",
18
- "pkg-types": "^1.1.3",
19
- "tsx": "^4.16.2"
23
+ "unconfig": "^7.3.0"
20
24
  },
21
25
  "devDependencies": {
22
- "@types/lodash-es": "^4.17.12"
26
+ "@types/node": "^22.13.9",
27
+ "unbuild": "^3.5.0",
28
+ "unplugin-purge-polyfills": "^0.0.7",
29
+ "@pubinfo/vite": "2.0.0-beta.2"
23
30
  },
24
31
  "scripts": {
25
- "clean": "pnpm rimraf node_modules && pnpm rimraf dist && pnpm rimraf .turbo",
26
- "build": "unbuild --minify",
27
32
  "stub": "unbuild --stub",
28
- "lint": "eslint . --cache --fix"
33
+ "build": "unbuild",
34
+ "pubinfo": "node ./bin/pubinfo.mjs dev"
29
35
  }
30
36
  }
@@ -1,16 +0,0 @@
1
-
2
- > @pubinfo/cli@0.6.10 build /home/runner/work/pubinfo-max/pubinfo-max/packages/cli
3
- > unbuild --minify
4
-
5
- [info] Building cli
6
- [info] Cleaning dist directory: `./dist`
7
- Generated an empty chunk: "cli".
8
- Generated an empty chunk: "cli".
9
- Generated an empty chunk: "cli".
10
- [success] Build succeeded for cli
11
- [log] dist/cli.cjs (total size: 5.77 kB, chunk size: 5.77 kB)
12
-
13
- [log] dist/cli.mjs (total size: 4.69 kB, chunk size: 4.69 kB)
14
-
15
- Σ Total dist size (byte size): 10.5 kB
16
- [log]
package/build.config.ts DELETED
@@ -1,13 +0,0 @@
1
- import { defineBuildConfig } from 'unbuild';
2
-
3
- export default defineBuildConfig({
4
- entries: [
5
- 'src/cli.ts',
6
- ],
7
- outDir: 'dist',
8
- declaration: true,
9
- rollup: {
10
- emitCJS: true,
11
- },
12
- failOnWarn: false,
13
- });
package/dist/cli.cjs DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";const r=require("node:process"),commander=require("commander"),i=require("consola"),execa=require("execa"),o=require("chalk"),node_path=require("node:path"),pkgTypes=require("pkg-types"),r$1=require("fast-glob"),node_fs=require("node:fs"),pathe=require("pathe"),mlly=require("mlly"),lodashEs=require("lodash-es"),n=require("cfonts");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const r__default=_interopDefaultCompat(r),i__default=_interopDefaultCompat(i),o__default=_interopDefaultCompat(o),r__default$1=_interopDefaultCompat(r$1),n__default=_interopDefaultCompat(n);async function findWorkspaceDir(e=r__default.cwd(),l={}){const u=pathe.isAbsolute(e)?e:await mlly.resolvePath(e,l),a={startingFrom:u,...l};try{const p=await findNearestFile(".git/config",a);return pathe.resolve(p,"../..")}catch{}try{const p=await resolveLockfile(u,{...a});return pathe.dirname(p)}catch{}try{const p=await findFile(u,a);return pathe.dirname(p)}catch{}throw new Error(`Cannot detect workspace root from ${e}`)}const F=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"];async function resolveLockfile(e=r__default.cwd(),l={}){const u={startingFrom:pathe.isAbsolute(e)?e:await mlly.resolvePath(e,l),...l};try{return await findNearestFile(F,u)}catch{}throw new Error(`No lockfile found from ${e}`)}function findNearestFile(e,l={}){return findFile(e,l)}const y$1={startingFrom:".",rootPattern:/^node_modules$/,reverse:!1,test:e=>{try{if(node_fs.statSync(e).isFile())return!0}catch{}}};async function findFile(e,l={}){const u=Array.isArray(e)?e:[e],a={...y$1,...l},p=pathe.resolve(a.startingFrom),b=p[0]==="/",k=p.split("/").filter(Boolean);b&&(k[0]=`/${k[0]}`);let v=k.findIndex(h=>h.match(a.rootPattern));if(v===-1&&(v=0),a.reverse)for(let h=v+1;h<=k.length;h++)for(const $ of u){const E=pathe.join(...k.slice(0,h),$);if(await a.test(E))return E}else for(let h=k.length;h>v;h--)for(const $ of u){const E=pathe.join(...k.slice(0,h),$);if(await a.test(E))return E}throw new Error(`Cannot find matching ${e} in ${a.startingFrom} or parent directories`)}async function s(){const e=r__default.cwd();return await findWorkspaceDir(e)}async function c(e){return await pkgTypes.readPackageJSON(e)}async function f(e){const l=[];for await(const u of e){const a=await c(u),p={name:node_path.basename(u),path:u,workspaceName:a.name,description:a.description};l.push(p)}return l}async function w(e){const l=await s(),u=await r__default$1.async("*",{cwd:`${l}/${e}`,onlyDirectories:!0,absolute:!0});return await f(u)}async function getAppsWorkspace(){return await w("apps")}async function getAllWorkspace(){const e=await s(),l=await r__default$1.async(["**/package.json"],{cwd:`${e}`,absolute:!0,ignore:["**/node_modules/**",`${e}/package.json`]}),u=new Map;for await(const a of l){const p=await c(a);u.set(p.name,p)}return u}function runScript(e,l){execa.execa("pnpm",["--filter",`${e}`,"run",`${l}`],{stdio:"inherit",preferLocal:!0})}function run(e,l=[]){execa.execa("vite",[`${e}`,...l],{stdio:"inherit",preferLocal:!0})}function normalizeWorkspace(e){return e.map(({name:l,workspaceName:u,description:a})=>({value:u,label:l,hint:a}))}async function isMonorepo(){return(await r__default$1.async("**/pnpm-workspace.yaml")).length>0}async function d$1(e=[]){if(!await isMonorepo()){run("build",e);return}const l=await getAppsWorkspace(),u=normalizeWorkspace(l);try{let a;u.length===1?a=u.map(b=>b.value):a=await g(u);const p=a.map(b=>`--filter=${b}`);await execa.execa("pnpm",["turbo","run","build",...p],{stdio:"inherit",preferLocal:!0})}catch(a){i__default.error(a.shortMessage)}}async function g(e){try{return await i__default.prompt(o__default.bold.green("\u{1F370} \u8BF7\u9009\u62E9\u8981\u6267\u884C\u6253\u5305\u547D\u4EE4\u7684\u7CFB\u7EDF\uFF08\u53EF\u591A\u9009\uFF09"),{type:"multiselect",required:!1,options:e})}catch{r__default.exit(0)}}function bootstrop(){t("PUBINFO")}function t(e){n__default.say(e,{font:"simple3d",align:"left",background:"transparent",letterSpacing:1,lineHeight:1,space:!0,maxLength:0,spaceless:!1,gradient:["blue","magenta"],independentGradient:!1,transitionGradient:!1,env:"node"})}async function d(e=[]){if(!await isMonorepo()){bootstrop(),run("dev",e);return}const l=await getAppsWorkspace(),u=normalizeWorkspace(l);bootstrop();try{let a;if(u.length===1?a=u[0].value:a=await y(u),lodashEs.isSymbol(a))return;runScript(a,"dev")}catch(a){i.consola.log(a)}}async function y(e){try{return await i.consola.prompt(o__default.bold.green(`\u{1F370} \u9009\u62E9\u8981\u6267\u884C ${o__default.bold.yellow("dev")} \u547D\u4EE4\u7684\u4ED3\u5E93`),{type:"select",options:e})}catch{r__default.exit(0)}}async function m(){const e=await getAllWorkspace(),l=[...e.keys()],u=await i.consola.prompt(o__default.bold.green(`\u8BF7\u9009\u62E9\u8981\u6267\u884C\u6307\u4EE4\u7684\u4ED3\u5E93
3
- `),{type:"select",options:l.map(b=>({label:`${o__default.bold.green("\u2192")} ${b}`,value:b}))});if(lodashEs.isSymbol(u))return;const a=Object.keys(e.get(u).scripts||{});if(!a.length){i.consola.info("\u5F53\u524D\u4ED3\u5E93\u6CA1\u6709\u53EF\u6267\u884C\u7684\u811A\u672C");return}const p=await i.consola.prompt(o__default.bold.green(`\u8BF7\u9009\u62E9\u8981\u6267\u884C\u7684\u6307\u4EE4
4
- `),{type:"select",options:a});lodashEs.isSymbol(p)||runScript(u,p)}commander.program.command("dev").allowUnknownOption().action(()=>{const e=r__default.argv.slice(r__default.argv.indexOf("dev")+1);d(e)}),commander.program.command("build").allowUnknownOption().action(()=>{const e=r__default.argv.slice(r__default.argv.indexOf("build")+1);d$1(e)}),commander.program.command("version").action(()=>{bootstrop()}),commander.program.command("pub").action(()=>{m()}),commander.program.parse();
package/dist/cli.d.cts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/cli.d.mts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/cli.mjs DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- import i from"node:process";import{program as p}from"commander";import b,{consola as f}from"consola";import{execa as w}from"execa";import u from"chalk";import{basename as P}from"node:path";import{readPackageJSON as S}from"pkg-types";import y from"fast-glob";import{statSync as W}from"node:fs";import{isAbsolute as k,resolve as E,dirname as F,join as v}from"pathe";import{resolvePath as $}from"mlly";import{isSymbol as g}from"lodash-es";import M from"cfonts";async function U(t=i.cwd(),o={}){const r=k(t)?t:await $(t,o),n={startingFrom:r,...o};try{const e=await C(".git/config",n);return E(e,"../..")}catch{}try{const e=await I(r,{...n});return F(e)}catch{}try{const e=await D(r,n);return F(e)}catch{}throw new Error(`Cannot detect workspace root from ${t}`)}const G=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"];async function I(t=i.cwd(),o={}){const r={startingFrom:k(t)?t:await $(t,o),...o};try{return await C(G,r)}catch{}throw new Error(`No lockfile found from ${t}`)}function C(t,o={}){return D(t,o)}const _={startingFrom:".",rootPattern:/^node_modules$/,reverse:!1,test:t=>{try{if(W(t).isFile())return!0}catch{}}};async function D(t,o={}){const r=Array.isArray(t)?t:[t],n={..._,...o},e=E(n.startingFrom),c=e[0]==="/",s=e.split("/").filter(Boolean);c&&(s[0]=`/${s[0]}`);let m=s.findIndex(a=>a.match(n.rootPattern));if(m===-1&&(m=0),n.reverse)for(let a=m+1;a<=s.length;a++)for(const d of r){const l=v(...s.slice(0,a),d);if(await n.test(l))return l}else for(let a=s.length;a>m;a--)for(const d of r){const l=v(...s.slice(0,a),d);if(await n.test(l))return l}throw new Error(`Cannot find matching ${t} in ${n.startingFrom} or parent directories`)}async function A(){const t=i.cwd();return await U(t)}async function x(t){return await S(t)}async function q(t){const o=[];for await(const r of t){const n=await x(r),e={name:P(r),path:r,workspaceName:n.name,description:n.description};o.push(e)}return o}async function z(t){const o=await A(),r=await y.async("*",{cwd:`${o}/${t}`,onlyDirectories:!0,absolute:!0});return await q(r)}async function O(){return await z("apps")}async function H(){const t=await A(),o=await y.async(["**/package.json"],{cwd:`${t}`,absolute:!0,ignore:["**/node_modules/**",`${t}/package.json`]}),r=new Map;for await(const n of o){const e=await x(n);r.set(e.name,e)}return r}function j(t,o){w("pnpm",["--filter",`${t}`,"run",`${o}`],{stdio:"inherit",preferLocal:!0})}function B(t,o=[]){w("vite",[`${t}`,...o],{stdio:"inherit",preferLocal:!0})}function N(t){return t.map(({name:o,workspaceName:r,description:n})=>({value:r,label:o,hint:n}))}async function L(){return(await y.async("**/pnpm-workspace.yaml")).length>0}async function J(t=[]){if(!await L()){B("build",t);return}const o=await O(),r=N(o);try{let n;r.length===1?n=r.map(c=>c.value):n=await K(r);const e=n.map(c=>`--filter=${c}`);await w("pnpm",["turbo","run","build",...e],{stdio:"inherit",preferLocal:!0})}catch(n){b.error(n.shortMessage)}}async function K(t){try{return await b.prompt(u.bold.green("\u{1F370} \u8BF7\u9009\u62E9\u8981\u6267\u884C\u6253\u5305\u547D\u4EE4\u7684\u7CFB\u7EDF\uFF08\u53EF\u591A\u9009\uFF09"),{type:"multiselect",required:!1,options:t})}catch{i.exit(0)}}function h(){Q("PUBINFO")}function Q(t){M.say(t,{font:"simple3d",align:"left",background:"transparent",letterSpacing:1,lineHeight:1,space:!0,maxLength:0,spaceless:!1,gradient:["blue","magenta"],independentGradient:!1,transitionGradient:!1,env:"node"})}async function R(t=[]){if(!await L()){h(),B("dev",t);return}const o=await O(),r=N(o);h();try{let n;if(r.length===1?n=r[0].value:n=await T(r),g(n))return;j(n,"dev")}catch(n){f.log(n)}}async function T(t){try{return await f.prompt(u.bold.green(`\u{1F370} \u9009\u62E9\u8981\u6267\u884C ${u.bold.yellow("dev")} \u547D\u4EE4\u7684\u4ED3\u5E93`),{type:"select",options:t})}catch{i.exit(0)}}async function V(){const t=await H(),o=[...t.keys()],r=await f.prompt(u.bold.green(`\u8BF7\u9009\u62E9\u8981\u6267\u884C\u6307\u4EE4\u7684\u4ED3\u5E93
3
- `),{type:"select",options:o.map(c=>({label:`${u.bold.green("\u2192")} ${c}`,value:c}))});if(g(r))return;const n=Object.keys(t.get(r).scripts||{});if(!n.length){f.info("\u5F53\u524D\u4ED3\u5E93\u6CA1\u6709\u53EF\u6267\u884C\u7684\u811A\u672C");return}const e=await f.prompt(u.bold.green(`\u8BF7\u9009\u62E9\u8981\u6267\u884C\u7684\u6307\u4EE4
4
- `),{type:"select",options:n});g(e)||j(r,e)}p.command("dev").allowUnknownOption().action(()=>{const t=i.argv.slice(i.argv.indexOf("dev")+1);R(t)}),p.command("build").allowUnknownOption().action(()=>{const t=i.argv.slice(i.argv.indexOf("build")+1);J(t)}),p.command("version").action(()=>{h()}),p.command("pub").action(()=>{V()}),p.parse();
package/src/cli.ts DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- import process from 'node:process';
3
- import { program } from 'commander';
4
- import build from './command/build';
5
- import dev from './command/dev';
6
- import version from './command/version';
7
- import pub from './command/pub';
8
-
9
- program
10
- .command('dev')
11
- .allowUnknownOption()
12
- .action(() => {
13
- const args = process.argv.slice(process.argv.indexOf('dev') + 1);
14
- dev(args);
15
- });
16
-
17
- program
18
- .command('build')
19
- .allowUnknownOption()
20
- .action(() => {
21
- const args = process.argv.slice(process.argv.indexOf('build') + 1);
22
- build(args);
23
- });
24
-
25
- program
26
- .command('version')
27
- .action(() => {
28
- version();
29
- });
30
-
31
- program
32
- .command('pub')
33
- .action(() => {
34
- pub();
35
- });
36
-
37
- program.parse();
@@ -1,50 +0,0 @@
1
- import process from 'node:process';
2
- import consola from 'consola';
3
- import { execa } from 'execa';
4
- import chalk from 'chalk';
5
- import { getAppsWorkspace } from '../utils/workspace';
6
- import { isMonorepo, normalizeWorkspace, run } from '../utils';
7
-
8
- export default async function main(args: string[] = []) {
9
- if (!await isMonorepo()) {
10
- run('build', args);
11
- return;
12
- }
13
-
14
- const workspace = await getAppsWorkspace();
15
- const options = normalizeWorkspace(workspace);
16
-
17
- try {
18
- let selected: string[];
19
-
20
- if (options.length === 1) {
21
- selected = options.map(e => e.value);
22
- }
23
- else {
24
- selected = await selectedWorkspace(options);
25
- }
26
-
27
- const adaptationTurbo = selected.map(item => `--filter=${item}`);
28
-
29
- await execa('pnpm', ['turbo', 'run', 'build', ...adaptationTurbo], {
30
- stdio: 'inherit',
31
- preferLocal: true,
32
- });
33
- }
34
- catch (error) {
35
- consola.error(error.shortMessage);
36
- }
37
- }
38
-
39
- async function selectedWorkspace(options: any[]) {
40
- try {
41
- return await consola.prompt(chalk.bold.green('🍰 请选择要执行打包命令的系统(可多选)'), {
42
- type: 'multiselect',
43
- required: false,
44
- options,
45
- }) as unknown as string[];
46
- }
47
- catch (error) {
48
- process.exit(0);
49
- }
50
- }
@@ -1,51 +0,0 @@
1
- import process from 'node:process';
2
- import { consola } from 'consola';
3
- import chalk from 'chalk';
4
- import { isSymbol } from 'lodash-es';
5
- import { getAppsWorkspace } from '../utils/workspace';
6
- import { isMonorepo, normalizeWorkspace, run, runScript } from '../utils/index';
7
- import { bootstrop } from '../log';
8
-
9
- export default async function main(args: string[] = []) {
10
- if (!await isMonorepo()) {
11
- bootstrop();
12
- run('dev', args);
13
- return;
14
- }
15
-
16
- const workspace = await getAppsWorkspace();
17
- const options = normalizeWorkspace(workspace);
18
- bootstrop();
19
-
20
- try {
21
- let selected: string;
22
-
23
- if (options.length === 1) {
24
- selected = options[0].value;
25
- }
26
- else {
27
- selected = await selectedWorkspace(options);
28
- }
29
-
30
- if (isSymbol(selected)) {
31
- return;
32
- }
33
-
34
- runScript(selected, 'dev');
35
- }
36
- catch (error) {
37
- consola.log(error);
38
- }
39
- }
40
-
41
- async function selectedWorkspace(options: any[]) {
42
- try {
43
- return await consola.prompt(chalk.bold.green(`🍰 选择要执行 ${chalk.bold.yellow('dev')} 命令的仓库`), {
44
- type: 'select',
45
- options,
46
- }) as unknown as string;
47
- }
48
- catch (error) {
49
- process.exit(0);
50
- }
51
- }
@@ -1,42 +0,0 @@
1
- import { consola } from 'consola';
2
- import chalk from 'chalk';
3
- import { isSymbol } from 'lodash-es';
4
- import { getAllWorkspace } from '../utils/workspace';
5
- import { runScript } from '../utils';
6
-
7
- export default async function main() {
8
- const workspace = await getAllWorkspace();
9
- const nameScope = [...workspace.keys()];
10
-
11
- const selectedWorkspace = await consola.prompt(chalk.bold.green(`请选择要执行指令的仓库\n`), {
12
- type: 'select',
13
- options: nameScope.map((item) => {
14
- return {
15
- label: `${chalk.bold.green('→')} ${item}`,
16
- value: item,
17
- };
18
- }),
19
- }) as unknown as string;
20
-
21
- if (isSymbol(selectedWorkspace)) {
22
- return;
23
- }
24
-
25
- const scripts = Object.keys(workspace.get(selectedWorkspace).scripts || {});
26
-
27
- if (!scripts.length) {
28
- consola.info(`当前仓库没有可执行的脚本`);
29
- return;
30
- }
31
-
32
- const selectedScript = await consola.prompt(chalk.bold.green(`请选择要执行的指令\n`), {
33
- type: 'select',
34
- options: scripts,
35
- }) as unknown as string;
36
-
37
- if (isSymbol(selectedScript)) {
38
- return;
39
- }
40
-
41
- runScript(selectedWorkspace, selectedScript);
42
- }
@@ -1,3 +0,0 @@
1
- import { bootstrop } from '../log';
2
-
3
- export default bootstrop;
package/src/log.ts DELETED
@@ -1,22 +0,0 @@
1
- import fonts from 'cfonts';
2
-
3
- export function bootstrop() {
4
- printLoGo('PUBINFO');
5
- }
6
-
7
- function printLoGo(logo: string) {
8
- fonts.say(logo, {
9
- font: 'simple3d',
10
- align: 'left',
11
- background: 'transparent',
12
- letterSpacing: 1,
13
- lineHeight: 1,
14
- space: true,
15
- maxLength: 0,
16
- spaceless: false,
17
- gradient: ['blue', 'magenta'],
18
- independentGradient: false,
19
- transitionGradient: false,
20
- env: 'node',
21
- });
22
- }
@@ -1,32 +0,0 @@
1
- import { execa } from 'execa';
2
- import fg from 'fast-glob';
3
- import type { PackagesWorkspaceInfo } from './workspace';
4
-
5
- export function runScript(workspace: string, command: string) {
6
- execa('pnpm', ['--filter', `${workspace}`, 'run', `${command}`], {
7
- stdio: 'inherit',
8
- preferLocal: true,
9
- });
10
- }
11
-
12
- export function run(command: string, args: string[] = []) {
13
- execa('vite', [`${command}`, ...args], {
14
- stdio: 'inherit',
15
- preferLocal: true,
16
- });
17
- }
18
-
19
- export function normalizeWorkspace(workspace: PackagesWorkspaceInfo[]) {
20
- return workspace.map(({ name, workspaceName, description }) => {
21
- return {
22
- value: workspaceName,
23
- label: name,
24
- hint: description,
25
- };
26
- });
27
- }
28
-
29
- export async function isMonorepo() {
30
- const files = await fg.async('**/pnpm-workspace.yaml');
31
- return files.length > 0;
32
- }
@@ -1,160 +0,0 @@
1
- // 重写 `pkg-types` 的 `findWorkspaceDir`
2
- import process from 'node:process';
3
- import { statSync } from 'node:fs';
4
- import { dirname, isAbsolute, join, resolve } from 'pathe';
5
- import type { FindFileOptions, ResolveOptions } from 'pkg-types';
6
- import { resolvePath } from 'mlly';
7
-
8
- /**
9
- * Detects the workspace directory based on common project markers (`.git`, lockfiles, `package.json`).
10
- * Throws an error if the workspace root cannot be detected.
11
- * @param id - The base path to search, defaults to the current working directory.
12
- * @param options - Options to modify the search behaviour. See {@link ResolveOptions}.
13
- * @returns a promise resolving to the path of the detected workspace directory.
14
- */
15
- export async function findWorkspaceDir(
16
- id: string = process.cwd(),
17
- options: ResolveOptions = {},
18
- ): Promise<string> {
19
- const resolvedPath = isAbsolute(id) ? id : await resolvePath(id, options);
20
- const _options = { startingFrom: resolvedPath, ...options };
21
-
22
- // Lookup for .git/config
23
- try {
24
- const r = await findNearestFile('.git/config', _options);
25
- return resolve(r, '../..');
26
- }
27
- catch {
28
- // Ignore
29
- }
30
-
31
- // Lookdown for lockfile
32
- try {
33
- const r = await resolveLockfile(resolvedPath, {
34
- ..._options,
35
- // reverse: true,
36
- });
37
- return dirname(r);
38
- }
39
- catch {
40
- // Ignore
41
- }
42
-
43
- // Lookdown for package.json
44
- try {
45
- const r = await findFile(resolvedPath, _options);
46
- return dirname(r);
47
- }
48
- catch {
49
- // Ignore
50
- }
51
-
52
- throw new Error(`Cannot detect workspace root from ${id}`);
53
- }
54
-
55
- const lockFiles = [
56
- 'yarn.lock',
57
- 'package-lock.json',
58
- 'pnpm-lock.yaml',
59
- 'npm-shrinkwrap.json',
60
- 'bun.lockb',
61
- ];
62
-
63
- export async function resolveLockfile(
64
- id: string = process.cwd(),
65
- options: ResolveOptions = {},
66
- ): Promise<string> {
67
- const resolvedPath = isAbsolute(id) ? id : await resolvePath(id, options);
68
- const _options = { startingFrom: resolvedPath, ...options };
69
- try {
70
- return await findNearestFile(lockFiles, _options);
71
- }
72
- catch {
73
- // Ignore
74
- }
75
- throw new Error(`No lockfile found from ${id}`);
76
- }
77
-
78
- /**
79
- * Asynchronously finds the next file with the given name, starting in the given directory and moving up.
80
- * Alias for findFile without reversing the search.
81
- * @param filename - The name of the file to find.
82
- * @param _options - Options to customise the search behaviour.
83
- * @returns A promise that resolves to the path of the next file found.
84
- */
85
- export function findNearestFile(
86
- filename: string | string[],
87
- _options: FindFileOptions = {},
88
- ): Promise<string> {
89
- return findFile(filename, _options);
90
- }
91
-
92
- const defaultFindOptions: Required<FindFileOptions> = {
93
- startingFrom: '.',
94
- rootPattern: /^node_modules$/,
95
- reverse: false,
96
- test: (filePath: string) => {
97
- try {
98
- if (statSync(filePath).isFile()) {
99
- return true;
100
- }
101
- }
102
- catch {
103
- // Ignore
104
- }
105
- },
106
- };
107
-
108
- /**
109
- * Asynchronously finds a file by name, starting from the specified directory and traversing up (or down if reverse).
110
- * @param filename - The name of the file to find.
111
- * @param _options - Options to customise the search behaviour.
112
- * @returns a promise that resolves to the path of the file found.
113
- * @throws Will throw an error if the file cannot be found.
114
- */
115
- export async function findFile(
116
- filename: string | string[],
117
- _options: FindFileOptions = {},
118
- ): Promise<string> {
119
- const filenames = Array.isArray(filename) ? filename : [filename];
120
- const options = { ...defaultFindOptions, ..._options };
121
- const basePath = resolve(options.startingFrom);
122
- const leadingSlash = basePath[0] === '/';
123
- const segments = basePath.split('/').filter(Boolean);
124
-
125
- // Restore leading slash
126
- if (leadingSlash) {
127
- segments[0] = `/${segments[0]}`;
128
- }
129
-
130
- // Limit to node_modules scope if it exists
131
- let root = segments.findIndex(r => r.match(options.rootPattern));
132
- if (root === -1) {
133
- root = 0;
134
- }
135
-
136
- if (options.reverse) {
137
- for (let index = root + 1; index <= segments.length; index++) {
138
- for (const filename of filenames) {
139
- const filePath = join(...segments.slice(0, index) as [], filename);
140
- if (await options.test(filePath)) {
141
- return filePath;
142
- }
143
- }
144
- }
145
- }
146
- else {
147
- for (let index = segments.length; index > root; index--) {
148
- for (const filename of filenames) {
149
- const filePath = join(...segments.slice(0, index) as [], filename);
150
- if (await options.test(filePath)) {
151
- return filePath;
152
- }
153
- }
154
- }
155
- }
156
-
157
- throw new Error(
158
- `Cannot find matching ${filename} in ${options.startingFrom} or parent directories`,
159
- );
160
- }
@@ -1,97 +0,0 @@
1
- import process from 'node:process';
2
- import { basename } from 'node:path';
3
- import { readPackageJSON } from 'pkg-types';
4
- import fg from 'fast-glob';
5
- import { findWorkspaceDir } from './rewrite-pkg-types';
6
-
7
- type PackageJson = Awaited<ReturnType<typeof readPackageJSON>>;
8
-
9
- export interface PackagesWorkspaceInfo {
10
- name: string
11
- path: string
12
- workspaceName: string
13
- description: string
14
- }
15
-
16
- /**
17
- * 获取工作区的根目录。
18
- * @returns {Promise<string>} 一个解析为工作区根目录的 Promise。
19
- */
20
- async function getWorkspaceRoot() {
21
- const cwd = process.cwd();
22
- const root = await findWorkspaceDir(cwd);
23
- return root;
24
- }
25
-
26
- /**
27
- * 从指定路径获取包信息。
28
- * @param {string} path - 包的路径。
29
- * @returns {Promise<PackageJson>} - 一个解析为包信息的 Promise。
30
- */
31
- async function getPackageInfo(path: string): Promise<PackageJson> {
32
- const pkg = await readPackageJSON(path);
33
- return pkg;
34
- }
35
-
36
- /**
37
- * 根据给定的 areaWorkspace 迭代并获取每个 workspace 的包信息,从而对工作区信息进行规范化。
38
- * @param areaWorkspace 要规范化的 areaWorkspace。
39
- * @returns 包含规范化工作区信息的 PackagesWorkspaceInfo 对象数组。
40
- */
41
- async function normalizeWorkspaceInfo(areaWorkspace: string[]) {
42
- const packagesWorkspaceInfo: PackagesWorkspaceInfo[] = [];
43
-
44
- for await (const iterator of areaWorkspace) {
45
- const pkg = await getPackageInfo(iterator);
46
- const workspace = {
47
- name: basename(iterator),
48
- path: iterator,
49
- workspaceName: pkg.name!,
50
- description: pkg.description!,
51
- };
52
- packagesWorkspaceInfo.push(workspace);
53
- }
54
- return packagesWorkspaceInfo;
55
- }
56
-
57
- async function getPackages(workspace: string) {
58
- const workspaceRoot = await getWorkspaceRoot();
59
- const subWorkspace = await fg.async('*',
60
- {
61
- cwd: `${workspaceRoot}/${workspace}`,
62
- onlyDirectories: true,
63
- absolute: true,
64
- });
65
-
66
- return await normalizeWorkspaceInfo(subWorkspace);
67
- }
68
-
69
- export async function getAppsWorkspace() {
70
- const targetName = 'apps';
71
- return await getPackages(targetName);
72
- }
73
-
74
- /**
75
- * 获取项目中所有工作区的信息。
76
- *
77
- * @returns 包含每个工作区的包信息的映射。
78
- */
79
- export async function getAllWorkspace() {
80
- const root = await getWorkspaceRoot();
81
- const allWorkspace = await fg.async(['**/package.json'],
82
- {
83
- cwd: `${root}`,
84
- absolute: true,
85
- ignore: [
86
- '**/node_modules/**',
87
- `${root}/package.json`,
88
- ],
89
- });
90
-
91
- const allWorkspacePkgs: Map<string, PackageJson> = new Map();
92
- for await (const workspace of allWorkspace) {
93
- const pkg = await getPackageInfo(workspace);
94
- allWorkspacePkgs.set(pkg.name!, pkg);
95
- }
96
- return allWorkspacePkgs;
97
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "@pubinfo/tsconfig/server.json",
3
- "compilerOptions": {
4
- "target": "ESNext"
5
- },
6
- "include": [
7
- "package.json",
8
- "src",
9
- "src/utils"
10
- ]
11
- }