Skip to content

Commit

Permalink
Merge pull request #72 from syfxlin/develop
Browse files Browse the repository at this point in the history
feature(depker): Re-design depker
  • Loading branch information
syfxlin authored Oct 16, 2024
2 parents c93c37d + 952a0a9 commit 326137c
Show file tree
Hide file tree
Showing 93 changed files with 6,352 additions and 5,063 deletions.
12 changes: 6 additions & 6 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
"@semantic-release/github",
{
"assets": [
{ "label": "depker.win.amd64.exe", "path": "bin/depker.win.amd64.exe" },
{ "label": "depker.win.arm64.exe", "path": "bin/depker.win.arm64.exe" },
{ "label": "depker.linux.amd64", "path": "bin/depker.linux.amd64" },
{ "label": "depker.linux.arm64", "path": "bin/depker.linux.arm64" },
{ "label": "depker.mac.amd64", "path": "bin/depker.mac.amd64" },
{ "label": "depker.mac.arm64", "path": "bin/depker.mac.arm64" }
{ "label": "depker.win.amd64.exe", "path": "bin/depker.win.amd64.exe" },
{ "label": "depker.win.arm64.exe", "path": "bin/depker.win.arm64.exe" },
{ "label": "depker.linux.amd64", "path": "bin/depker.linux.amd64" },
{ "label": "depker.linux.arm64", "path": "bin/depker.linux.arm64" },
{ "label": "depker.mac.amd64", "path": "bin/depker.mac.amd64" },
{ "label": "depker.mac.arm64", "path": "bin/depker.mac.arm64" }
]
}
]
Expand Down
37 changes: 26 additions & 11 deletions bin/depker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"crypto/md5"
"encoding/hex"
"errors"
"net/url"
"os"
Expand All @@ -18,8 +20,8 @@ func main() {
create(deno, path, os.Args[2:]...)
return
}
if len(os.Args) > 1 && os.Args[1] == "reload" {
reload(deno, path, os.Args[2:]...)
if len(os.Args) > 1 && os.Args[1] == "update" {
update(deno, path, os.Args[2:]...)
return
}

Expand Down Expand Up @@ -111,11 +113,13 @@ func create(deno string, path string, args ...string) {
}
_, err2 := file.WriteString(strings.Join(
[]string{
"import { depker } from \"https://raw.githubusercontent.com/syfxlin/depker/master/mod.ts\";",
"import { depker, nginx } from \"https://raw.githubusercontent.com/syfxlin/depker/master/mod.ts\";",
"",
"const app = depker();",
"",
"export default app;",
"depker.use(",
" nginx({",
" name: \"nginx\",",
" }),",
");",
"",
},
"\n",
Expand All @@ -129,19 +133,30 @@ func create(deno string, path string, args ...string) {
}
}

func reload(deno string, path string, args ...string) {
func update(deno string, path string, args ...string) {
execute(deno, "upgrade", "stable")
execute(deno, append([]string{"cache", "-r", path}, args...)...)
}

func depker(deno string, path string, args ...string) {
file, err1 := os.CreateTemp("", "depker-cli-")
hash := md5.Sum([]byte(path))
name := filepath.Join(os.TempDir(), "depker-cli-"+hex.EncodeToString(hash[:]))
file, err1 := os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err1 != nil {
panic(err1)
}
_, err2 := file.WriteString(strings.Join(
[]string{
"const depker = await import('" + path + "').then(mod => mod?.default ?? mod);",
"if (typeof depker.execute === 'function') {",
"const depker = await import('" + path + "');",
"if (typeof depker?.default?.execute === 'function') {",
" await depker.default.execute();",
"} else if (typeof depker?.depker?.execute === 'function') {",
" await depker.depker.execute();",
"} else if (typeof depker?.app?.execute === 'function') {",
" await depker.app.execute();",
"} else if (typeof globalThis?.depker?.execute === 'function') {",
" await globalThis.depker.execute();",
"} else if (typeof depker?.execute === 'function') {",
" await depker.execute();",
"} else {",
" throw new ReferenceError('Missing depker instance! Ensure your config file does export the Site instance as default.');",
Expand All @@ -156,7 +171,7 @@ func depker(deno string, path string, args ...string) {
if err3 != nil {
panic(err3)
}
execute(deno, append([]string{"run", "-A", file.Name()}, args...)...)
execute(deno, append([]string{"run", "--no-lock", "--allow-all", file.Name()}, args...)...)
}

func execute(name string, args ...string) {
Expand Down
17 changes: 4 additions & 13 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import config from "@syfxlin/eslint-config";

export default config({
stylistic: {
quotes: "double",
indent: 2,
semi: true,
},
rules: {
"curly": ["error", "multi-line", "consistent"],
"no-console": ["off"],
"style/brace-style": ["error", "1tbs"],
"style/member-delimiter-style": ["error", { multiline: { delimiter: "semi" }, singleline: { delimiter: "semi" } }],
"ts/ban-ts-comment": ["off"],
"ts/consistent-type-imports": ["off"],
},
jsx: true,
react: true,
typescript: true,
formatters: true,
});
45 changes: 25 additions & 20 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import { depker } from "./src/depker.ts";
import { Depker } from "./src/depker.ts";

// dependencies
export * as deps from "./src/deps.ts";

// services
// modules
export * from "./src/depker.ts";
export * from "./src/services/run/index.ts";
export * from "./src/modules/cli.module.ts";
export * from "./src/modules/log.module.ts";
export * from "./src/modules/exec.module.ts";
export * from "./src/modules/node.module.ts";
export * from "./src/modules/events.module.ts";
export * from "./src/modules/config.module.ts";

// modules
export * from "./src/modules/proxy/proxy.module.ts";
export * from "./src/modules/proxy/proxy.type.ts";
export * from "./src/modules/service/service.module.ts";
export * from "./src/modules/service/service.type.ts";
// providers
export * from "./src/providers/docker.ts";
export * from "./src/providers/types.ts";

// plugins
export * from "./src/core/app/ctx.ts";
export * from "./src/core/app/index.ts";

// packs
export * from "./src/modules/service/pack.context.ts";
export * from "./src/modules/service/packs/dockerfile/dockerfile.pack.ts";
export * from "./src/modules/service/packs/image/image.pack.ts";
export * from "./src/modules/service/packs/nginx/nginx.pack.ts";
export * from "./src/modules/service/packs/nodejs/nodejs.pack.ts";
export * from "./src/modules/service/packs/nextjs/nextjs.pack.ts";
export * from "./src/modules/service/packs/coline/coline.pack.ts";
export * from "./src/core/app/packs/nginx/index.ts";
export * from "./src/core/app/packs/image/index.ts";
export * from "./src/core/app/packs/nodejs/index.ts";
export * from "./src/core/app/packs/nextjs/index.ts";
export * from "./src/core/app/packs/selflare/index.ts";
export * from "./src/core/app/packs/nixpacks/index.ts";
export * from "./src/core/app/packs/dockerfile/index.ts";

// default
export default depker();
// depker
export const depker = Depker.create();
export default depker;
20 changes: 3 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
{
"name": "@syfxlin/depker",
"type": "module",
"version": "0.0.0-semantic-release",
"description": "docker-based cloud deployment tool.",
"keywords": [
"depker",
"docker"
],
"author": "Otstar Lin <[email protected]> (https://ixk.me)",
"license": "Apache-2.0",
"private": true,
"type": "module",
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"devDependencies": {
"@syfxlin/eslint-config": "^1.0.1",
"@types/node": "^20.10.6",
"eslint": "8.56.0",
"typescript": "^5.3.3",
"typescript-deno-plugin": "^1.31.0"
"@syfxlin/eslint-config": "^1.0.8",
"eslint": "^9.9.0"
}
}
Loading

0 comments on commit 326137c

Please sign in to comment.