@liangmi/mo 0.0.5

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.
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@liangmi/mo",
3
+ "version": "0.0.5",
4
+ "description": "Manage your Opensource projects",
5
+ "homepage": "https://github.com/liangmiQwQ/mo#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/liangmiQwQ/mo/issues"
8
+ },
9
+ "license": "MIT",
10
+ "author": "Liang Mi <hi@liangmi.dev>",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/liangmiQwQ/mo.git"
14
+ },
15
+ "bin": {
16
+ "mo": "./bin/mo.mjs",
17
+ "mo-inner": "./bin/mo-inner.mjs"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "bin",
22
+ "scripts",
23
+ "config_schema.json"
24
+ ],
25
+ "type": "module",
26
+ "exports": {
27
+ "./package.json": "./package.json"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {
33
+ "jsonc-parser": "^3.3.1"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^25.5.0",
37
+ "@types/prompts": "^2.4.9",
38
+ "@types/which": "^3.0.4",
39
+ "@typescript/native-preview": "7.0.0-dev.20260316.1",
40
+ "bumpp": "^11.0.1",
41
+ "cac": "^7.0.0",
42
+ "picocolors": "^1.1.1",
43
+ "prompts": "^2.4.2",
44
+ "tinyexec": "^1.0.4",
45
+ "tsx": "^4.21.0",
46
+ "typescript": "^6.0.2",
47
+ "untildify": "^6.0.0",
48
+ "vite-plus": "^0.1.15",
49
+ "vitest": "npm:@voidzero-dev/vite-plus-test@^0.1.15",
50
+ "which": "^6.0.1"
51
+ },
52
+ "inlinedDependencies": {
53
+ "cac": "7.0.0",
54
+ "picocolors": "1.1.1",
55
+ "untildify": "6.0.0"
56
+ },
57
+ "scripts": {
58
+ "build": "vp pack",
59
+ "dev:i": "tsx scripts/install.ts",
60
+ "dev:uni": "tsx scripts/uninstall.ts",
61
+ "preview": "node bin/cli.mjs",
62
+ "test": "vp test run",
63
+ "check": "vp check",
64
+ "clean": "rm -rf .root/*",
65
+ "release": "bumpp"
66
+ }
67
+ }
@@ -0,0 +1,63 @@
1
+ import { chmod, mkdir, writeFile } from 'node:fs/promises'
2
+ import { existsSync } from 'node:fs'
3
+ import { homedir } from 'node:os'
4
+ import { basename, resolve } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import pc from 'picocolors'
7
+
8
+ const managedMarker = 'mo-dev-wrapper:managed'
9
+ const binDir = resolve(homedir(), '.local/bin')
10
+ const repoRoot = resolve(fileURLToPath(new URL('..', import.meta.url)))
11
+ const tsxBin = resolve(repoRoot, 'node_modules/.bin/tsx')
12
+ const entries = [
13
+ { name: 'mo', entry: resolve(repoRoot, 'src/mo.ts') },
14
+ { name: 'mo-inner', entry: resolve(repoRoot, 'src/mo-inner.ts') },
15
+ ]
16
+
17
+ function shellQuote(input: string): string {
18
+ return `'${input.replace(/'/g, `'"'"'`)}'`
19
+ }
20
+
21
+ function isPathContains(pathname: string): boolean {
22
+ const pathValue = process.env.PATH ?? ''
23
+ return pathValue.split(':').includes(pathname)
24
+ }
25
+
26
+ function createWrapperContent(entryPath: string): string {
27
+ return [
28
+ '#!/usr/bin/env sh',
29
+ `# ${managedMarker}`,
30
+ `case "$PWD" in ${shellQuote(repoRoot)}|${shellQuote(`${repoRoot}/*`)}) ;;`,
31
+ `*) echo ${shellQuote(`mo dev wrapper can only run inside ${repoRoot}`)} >&2; exit 78 ;;`,
32
+ 'esac',
33
+ `exec ${shellQuote(tsxBin)} ${shellQuote(entryPath)} "$@"`,
34
+ '',
35
+ ].join('\n')
36
+ }
37
+
38
+ async function installWrapper(name: string, entryPath: string): Promise<void> {
39
+ const target = resolve(binDir, name)
40
+ await writeFile(target, createWrapperContent(entryPath), 'utf8')
41
+ await chmod(target, 0o755)
42
+ console.log(pc.green(`Installed ${name} -> ${target}`))
43
+ }
44
+
45
+ async function main() {
46
+ if (!existsSync(tsxBin)) {
47
+ console.error(pc.red(`Missing ${basename(tsxBin)} at ${tsxBin}. Run "vp install" first.`))
48
+ process.exit(1)
49
+ }
50
+
51
+ await mkdir(binDir, { recursive: true })
52
+ for (const item of entries) {
53
+ await installWrapper(item.name, item.entry)
54
+ }
55
+
56
+ if (!isPathContains(binDir)) {
57
+ console.log(
58
+ pc.yellow(`Add ${binDir} to PATH so "mo" and "mo-inner" are available in new shells.`),
59
+ )
60
+ }
61
+ }
62
+
63
+ await main()
@@ -0,0 +1,34 @@
1
+ import { readFile, rm } from 'node:fs/promises'
2
+ import { existsSync } from 'node:fs'
3
+ import { homedir } from 'node:os'
4
+ import { resolve } from 'node:path'
5
+ import pc from 'picocolors'
6
+
7
+ const managedMarker = 'mo-dev-wrapper:managed'
8
+ const binDir = resolve(homedir(), '.local/bin')
9
+ const wrapperNames = ['mo', 'mo-inner']
10
+
11
+ async function removeIfManaged(name: string): Promise<void> {
12
+ const target = resolve(binDir, name)
13
+ if (!existsSync(target)) {
14
+ console.log(pc.gray(`Skipped ${name}: not found at ${target}`))
15
+ return
16
+ }
17
+
18
+ const content = await readFile(target, 'utf8')
19
+ if (!content.includes(managedMarker)) {
20
+ console.log(pc.yellow(`Skipped ${name}: ${target} is not managed by dev:i`))
21
+ return
22
+ }
23
+
24
+ await rm(target)
25
+ console.log(pc.green(`Removed ${name} wrapper at ${target}`))
26
+ }
27
+
28
+ async function main() {
29
+ for (const name of wrapperNames) {
30
+ await removeIfManaged(name)
31
+ }
32
+ }
33
+
34
+ await main()