Skip to content

Up #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Up #491

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions packages/lllink/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bun run link-workspaces.ts <workspaceDir1> <workspaceDir2> ...
*/

import { readdir, readFile, stat, rm, symlink } from 'node:fs/promises'
import { readdir, readFile, stat, rm, symlink, rename, mkdir } from 'node:fs/promises'
import { homedir } from 'node:os'
import { join, relative, resolve } from 'node:path'

Expand Down Expand Up @@ -63,22 +63,46 @@ async function findLocalPackages(rootDir: string): Promise<Record<string, string
}

async function linkPackages(localPackages: Record<string, string>) {
const backupDir = join(process.cwd(), 'node_modules', '.cache', 'lllink', 'moved')
await mkdir(backupDir, { recursive: true })
for (const pkgName of Object.keys(localPackages)) {
const nmPath = join(process.cwd(), 'node_modules', ...pkgName.split('/'))
try {
const existingStat = await stat(nmPath)
if (existingStat) {
await rm(nmPath, { recursive: true, force: true })
const localPath = localPackages[pkgName]
console.info(`${relative(process.cwd(), nmPath)} -> ${localPath.replace(homedir(), '~')}`)
await symlink(localPath, nmPath, 'dir')
if (existingStat && (existingStat.isDirectory() || existingStat.isSymbolicLink())) {
await rename(nmPath, join(backupDir, pkgName.replace('/', '__')))
}
const localPath = localPackages[pkgName]
console.info(`${relative(process.cwd(), nmPath)} -> ${localPath.replace(homedir(), '~')}`)
await symlink(localPath, nmPath, 'dir')
} catch {}
}
}

async function undoLinks() {
const backupDir = join(process.cwd(), 'node_modules', '.cache', 'lllink', 'moved')
let movedItems: string[]
try {
movedItems = await readdir(backupDir)
} catch {
console.info('Nothing to undo.')
return
}
for (const item of movedItems) {
const originalName = item.replace('__', '/')
const nmPath = join(process.cwd(), 'node_modules', ...originalName.split('/'))
await rm(nmPath, { recursive: true, force: true }).catch(() => {})
await rename(join(backupDir, item), nmPath).catch(() => {})
console.info(`Restored: ${originalName}`)
}
}

async function main() {
const args = process.argv.slice(2)
if (args.includes('--unlink')) {
await undoLinks()
process.exit(0)
}
if (args.length === 0) {
console.info('No workspace directories provided.')
process.exit(0)
Expand Down
1 change: 1 addition & 0 deletions packages/one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"@vxrn/resolve": "workspace:*",
"@vxrn/tslib-lite": "workspace:*",
"@vxrn/universal-color-scheme": "workspace:*",
"@vxrn/up": "workspace:*",
"@vxrn/use-isomorphic-layout-effect": "workspace:*",
"babel-dead-code-elimination": "^1.0.6",
"citty": "^0.1.6",
Expand Down
14 changes: 14 additions & 0 deletions packages/one/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,21 @@ const patch = defineCommand({
},
})

const up = defineCommand({
meta: {
name: 'up',
version: '0.0.0',
description: '',
},
args: {},
async run({ args }) {
const { run } = await import('./cli/up')
await run(args)
},
})

const subCommands = {
up,
dev,
clean,
build: buildCommand,
Expand Down
5 changes: 5 additions & 0 deletions packages/one/src/cli/up.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { up } from '@vxrn/up'

export function run(args: {}) {
up()
}
4 changes: 4 additions & 0 deletions packages/one/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ function subscribeToNavigationChanges() {
nextState = undefined

if (state && state !== rootState) {
if (process.env.NODE_ENV === 'development') {
console.info(` [one] router`, state)
}

updateState(state, undefined)
shouldUpdateSubscribers = true
}
Expand Down
44 changes: 44 additions & 0 deletions packages/one/types/cli/up.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export declare function run(args: {}): void;
interface DockerConfig {
socketPath?: string;
host?: string;
port?: number;
protocol?: string;
containerFilters?: string;
}
interface HostInfo {
Containers: number;
ContainersRunning: number;
ContainersPaused: number;
ContainersStopped: number;
Images: number;
OperatingSystem: string;
Architecture: string;
MemTotal: number;
Host: string;
ServerVersion: string;
ApiVersion: string;
}
declare const createDockerBridge: (config: DockerConfig) => {
ping: () => Promise<unknown>;
listImages: () => Promise<unknown>;
systemDf: () => Promise<unknown>;
listContainers: () => Promise<unknown>;
listServices: () => Promise<unknown>;
stopAllContainers: () => Promise<any>;
removeAllContainers: () => Promise<any>;
removeAllImages: () => Promise<any>;
getInfo: () => Promise<HostInfo>;
getContainer: (containerId: string) => Promise<unknown>;
getService: (serviceId: string) => Promise<unknown>;
getImage: (imageId: string) => Promise<unknown>;
restartContainer: (containerId: string) => Promise<unknown>;
stopContainer: (containerId: string) => Promise<unknown>;
removeContainer: (containerId: string) => Promise<unknown>;
removeImage: (imageId: string) => Promise<unknown>;
getContainerStats: (containerId: string) => Promise<unknown>;
getContainerLogs: (containerId: string) => Promise<unknown>;
getServiceLogs: (serviceId: string) => Promise<unknown>;
};
export default createDockerBridge;
//# sourceMappingURL=up.d.ts.map
78 changes: 78 additions & 0 deletions packages/up/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.1/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"ignore": ["**/*/generated-new.ts", "**/*/generated-v2.ts", ".tamagui"],
"rules": {
"correctness": {
"useExhaustiveDependencies": "off",
"noInnerDeclarations": "off",
"noUnnecessaryContinue": "off",
"noConstructorReturn": "off"
},
"suspicious": {
"noImplicitAnyLet": "off",
"noConfusingVoidType": "off",
"noEmptyInterface": "off",
"noExplicitAny": "off",
"noArrayIndexKey": "off",
"noDoubleEquals": "off",
"noConsoleLog": "error",
"noAssignInExpressions": "off",
"noRedeclare": "off"
},
"style": {
"noParameterAssign": "off",
"noNonNullAssertion": "off",
"noArguments": "off",
"noUnusedTemplateLiteral": "off",
"useDefaultParameterLast": "off",
"useConst": "off",
"useEnumInitializers": "off",
"useTemplate": "off",
"useSelfClosingElements": "off"
},
"security": {
"noDangerouslySetInnerHtml": "off",
"noDangerouslySetInnerHtmlWithChildren": "off"
},
"performance": {
"noDelete": "off",
"noAccumulatingSpread": "off"
},
"complexity": {
"noForEach": "off",
"noBannedTypes": "off",
"useLiteralKeys": "off",
"useSimplifiedLogicExpression": "off",
"useOptionalChain": "off"
},
"a11y": {
"noSvgWithoutTitle": "off",
"useMediaCaption": "off",
"noHeaderScope": "off",
"useAltText": "off",
"useButtonType": "off"
}
}
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 100,
"ignore": ["**/*/generated-new.ts", "**/*/generated-v2.ts", ".tamagui"]
},
"javascript": {
"formatter": {
"trailingComma": "es5",
"jsxQuoteStyle": "double",
"semicolons": "asNeeded",
"quoteStyle": "single"
}
}
}
42 changes: 42 additions & 0 deletions packages/up/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import esbuild from 'esbuild'

async function main() {
const watch = process.argv.includes('--watch')

const buildOptions = {
entryPoints: ['./src/index.tsx'],
outdir: 'dist',
outExtension: {
'.js': '.cjs',
},
bundle: true,
format: 'cjs',
platform: 'node',
target: 'esnext',
external: ['dockerode', 'mono-layout/wasm', 'yogini/wasm', 'vscode-oniguruma', 'node-pty'],
sourcemap: true,
loader: {
'.ts': 'ts',
'.tsx': 'tsx',
},
} satisfies esbuild.BuildOptions

if (watch) {
const context = await esbuild.context(buildOptions)
await context.watch()
console.info('Watching...')

// Handle process exit
process.on('SIGTERM', async () => {
await context.dispose()
process.exit(0)
})
} else {
await esbuild.build(buildOptions)
}
}

main().catch((err) => {
console.error(err)
process.exit(1)
})
50 changes: 50 additions & 0 deletions packages/up/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@vxrn/up",
"version": "1.1.437",
"license": "BSD-3-Clause",
"sideEffects": [
"setup.mjs",
"setup.js"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./src/index.tsx",
"default": "./dist/index.cjs"
}
},
"main": "dist/index.cjs",
"source": "src/index.ts",
"files": [
"src",
"types",
"dist",
"vendor",
"LICENSE"
],
"scripts": {
"build": "bun ./build.ts",
"clean": "bun ./build.ts --watch",
"clean:build": "rm -r dist || true",
"typecheck": "tsc --noEmit",
"lint:fix": "../../node_modules/.bin/biome check --write --unsafe src",
"watch": "yarn build --watch"
},
"dependencies": {
"@onreza/docker-api-typescript": "^0.5.1-0",
"fast-glob": "^3.3.3",
"js-yaml": "^4.1.0",
"react": "18.3.1",
"react-reconciler": "0.23.0",
"terminosaurus": "^3.0.0-rc.5",
"valtio": "^2.1.3",
"zod": "^3.24.1"
},
"devDependencies": {
"@tamagui/build": "^1.124.1",
"@types/react": "^18"
},
"publishConfig": {
"access": "public"
}
}
Loading
Loading