-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added metrics disabled console logging as default updates and cleanups added documentation added typedoc for documentation generation added plugins dir for nodejs tied plugins
- Loading branch information
Showing
72 changed files
with
8,674 additions
and
4,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
import { ServiceBase } from "@bettercorp/service-base"; | ||
import {join} from "node:path"; | ||
|
||
const runApp = async () => { | ||
const CWD = join(__dirname, "../"); | ||
const SB = new ServiceBase(false, true, CWD); | ||
await SB.init(); | ||
await SB.run(); | ||
process.exit(0); | ||
}; | ||
runApp(); |
73 changes: 73 additions & 0 deletions
73
nodejs-plugins/core-cli/src/plugins/service-bsb-git/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import {join} from "node:path"; | ||
import {z} from "zod"; | ||
import { | ||
BSBPluginConfig, | ||
BSBPluginEvents, | ||
BSBService, | ||
BSBServiceConstructor, | ||
ServiceEventsBase, | ||
} from "@bettercorp/service-base"; | ||
import {exec} from "child_process"; | ||
import {existsSync} from "node:fs"; | ||
|
||
export const secSchema = z.object({}); | ||
|
||
export class Config | ||
extends BSBPluginConfig<typeof secSchema> { | ||
validationSchema = secSchema; | ||
|
||
migrate( | ||
toVersion: string, | ||
fromVersion: string | null, | ||
fromConfig: any | null, | ||
) { | ||
return fromConfig; | ||
} | ||
} | ||
|
||
export interface ServiceTypes | ||
extends BSBPluginEvents { | ||
onEvents: ServiceEventsBase; | ||
emitEvents: ServiceEventsBase; | ||
onReturnableEvents: { | ||
gitIsInitialized: (workingDir: string) => Promise<boolean>; | ||
gitInit: (workingDir: string) => Promise<boolean>; | ||
}; | ||
emitReturnableEvents: ServiceEventsBase; | ||
onBroadcast: ServiceEventsBase; | ||
emitBroadcast: ServiceEventsBase; | ||
} | ||
|
||
export class Plugin | ||
extends BSBService<Config, ServiceTypes> { | ||
public static PLUGIN_CLIENT = { | ||
name: "service-bsb-git", | ||
}; | ||
public initBeforePlugins?: string[] | undefined; | ||
public initAfterPlugins?: string[] | undefined; | ||
public runBeforePlugins?: string[] | undefined; | ||
public runAfterPlugins?: string[] | undefined; | ||
public methods = {}; | ||
|
||
dispose?(): void; | ||
|
||
constructor(config: BSBServiceConstructor) { | ||
super(config); | ||
} | ||
|
||
public async init() { | ||
await this.events.onReturnableEvent("gitIsInitialized", async (workingDir: string) => | ||
existsSync(join(workingDir, ".git")), | ||
); | ||
await this.events.onReturnableEvent("gitInit", async (workingDir: string) => new Promise<boolean>(async (resolve) => { | ||
exec("git init", {encoding: "utf-8", cwd: workingDir}, function (error, stdout, stderr) { | ||
return resolve(( | ||
stdout + stderr | ||
).includes("Initialized empty Git repository")); | ||
}); | ||
})); | ||
} | ||
|
||
public async run() { | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
nodejs-plugins/core-cli/src/plugins/service-bsb-init/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import {existsSync} from "node:fs"; | ||
import {z} from "zod"; | ||
import { | ||
BSBPluginConfig, | ||
BSBPluginEvents, | ||
BSBService, | ||
BSBServiceConstructor, ServiceClient, | ||
ServiceEventsBase, | ||
} from "@bettercorp/service-base"; | ||
import {confirm, input} from "@inquirer/prompts"; | ||
import {Plugin as GITPlugin} from "../service-bsb-git/plugin"; | ||
import {Plugin as NPMPlugin} from "../service-bsb-npm/plugin"; | ||
|
||
export const secSchema = z.object({}); | ||
|
||
export class Config | ||
extends BSBPluginConfig<typeof secSchema> { | ||
validationSchema = secSchema; | ||
|
||
migrate( | ||
toVersion: string, | ||
fromVersion: string | null, | ||
fromConfig: any | null, | ||
) { | ||
return fromConfig; | ||
} | ||
} | ||
|
||
export interface ServiceTypes | ||
extends BSBPluginEvents { | ||
onEvents: ServiceEventsBase; | ||
emitEvents: ServiceEventsBase; | ||
onReturnableEvents: {}; | ||
emitReturnableEvents: ServiceEventsBase; | ||
onBroadcast: ServiceEventsBase; | ||
emitBroadcast: ServiceEventsBase; | ||
} | ||
|
||
export class Plugin | ||
extends BSBService<Config, ServiceTypes> { | ||
public initBeforePlugins?: string[] | undefined; | ||
public initAfterPlugins?: string[] | undefined; | ||
public runBeforePlugins?: string[] | undefined; | ||
public runAfterPlugins?: string[] | undefined; | ||
public methods = {}; | ||
private git: ServiceClient<GITPlugin>; | ||
private npm: ServiceClient<NPMPlugin>; | ||
|
||
dispose?(): void; | ||
|
||
constructor(config: BSBServiceConstructor) { | ||
super(config); | ||
this.git = new ServiceClient(GITPlugin, this); | ||
this.npm = new ServiceClient(NPMPlugin, this); | ||
} | ||
|
||
public async init() { | ||
} | ||
|
||
private projectInfo = { | ||
workingkingDir: process.cwd(), | ||
gitSetup: false, | ||
gitRemoteSetup: false, | ||
npmSetup: false, | ||
projectName: "", | ||
plugins: [] as string[], | ||
}; | ||
|
||
/*private async gitHubProcess() { | ||
// const setupGH = await confirm({ | ||
// message: "Do you want to setup GitHub? (requires GitHub CLI installed and setup)", | ||
// default: false, | ||
// }); | ||
// | ||
// if (setupGH) { | ||
// await this.gitHubProcess(); | ||
// } | ||
}*/ | ||
private async gitProcess() { | ||
this.projectInfo.gitSetup = await this.git.events.emitEventAndReturn("gitIsInitialized", 5, this.projectInfo.workingkingDir); | ||
if (!this.projectInfo.gitSetup) { | ||
const setupGit = await confirm({ | ||
message: "Do you want to setup git?", | ||
}); | ||
if (setupGit) { | ||
const wasSetup = await this.git.events.emitEventAndReturn("gitInit", 5, this.projectInfo.workingkingDir); | ||
if (!wasSetup) { | ||
console.error("Failed to setup git - you can handle this manually."); | ||
return; | ||
} | ||
//await this.gitHubProcess(); | ||
} | ||
} | ||
} | ||
|
||
private async npmProcess() { | ||
this.projectInfo.npmSetup = await this.npm.events.emitEventAndReturn("isNPMInitialized", 5, this.projectInfo.workingkingDir); | ||
if (!this.projectInfo.npmSetup) { | ||
const setupNPM = await confirm({ | ||
message: "Do you want to init a new project?", | ||
}); | ||
if (setupNPM) { | ||
const wasSetup = await this.npm.events.emitEventAndReturn("npmInit", 5, this.projectInfo.workingkingDir); | ||
if (!wasSetup) { | ||
console.error("Failed to setup npm - you can handle this manually."); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public async run() { | ||
if (!await confirm({ | ||
message: `Use ${this.projectInfo.workingkingDir} as the working directory?`, | ||
default: true, | ||
})) { | ||
this.projectInfo.workingkingDir = await input({ | ||
message: "Enter the path", | ||
default: this.projectInfo.workingkingDir, | ||
}); | ||
if (!existsSync(this.projectInfo.workingkingDir)) { | ||
console.error(`Path does not exist (${this.projectInfo.workingkingDir})`); | ||
return; | ||
} | ||
} | ||
|
||
await this.gitProcess(); | ||
await this.npmProcess(); | ||
|
||
// const answer = await input({message: "Enter your name"}); | ||
// console.log(answer); | ||
console.log(); | ||
console.log(await this.npm.events.emitEventAndReturn("isNPMInitialized", 5, process.cwd())); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
nodejs-plugins/core-cli/src/plugins/service-bsb-npm/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import {existsSync} from "node:fs"; | ||
import {join} from "node:path"; | ||
import {z} from "zod"; | ||
import { | ||
BSBPluginConfig, | ||
BSBPluginEvents, | ||
BSBService, | ||
BSBServiceConstructor, | ||
ServiceEventsBase, | ||
} from "@bettercorp/service-base"; | ||
import {writeFileSync} from "node:fs"; | ||
|
||
export type NPMConfig = { | ||
"name": string; | ||
"license": string; | ||
"repository": { | ||
"url": string; | ||
} | undefined, | ||
"engines": { | ||
"npm": string; | ||
"node": string; | ||
} | undefined, | ||
"scripts": Record<string, string> | undefined, | ||
"files": string[] | undefined, | ||
"main": string | undefined, | ||
"version": string | undefined, | ||
"devDependencies": Record<string, string> | undefined, | ||
"dependencies": Record<string, string> | undefined, | ||
} | ||
|
||
|
||
export const secSchema = z.object({}); | ||
|
||
export class Config | ||
extends BSBPluginConfig<typeof secSchema> { | ||
validationSchema = secSchema; | ||
|
||
migrate( | ||
toVersion: string, | ||
fromVersion: string | null, | ||
fromConfig: any | null, | ||
) { | ||
return fromConfig; | ||
} | ||
} | ||
|
||
export interface ServiceTypes | ||
extends BSBPluginEvents { | ||
onEvents: ServiceEventsBase; | ||
emitEvents: ServiceEventsBase; | ||
onReturnableEvents: { | ||
isNPMInitialized: (workingDir: string) => Promise<boolean>; | ||
initNPM: (workingDir: string) => Promise<boolean>; | ||
getNPMConfig: (workingDir: string) => Promise<NPMConfig>; | ||
updateNPMConfig: (workingDir: string, config: NPMConfig) => Promise<void>; | ||
}; | ||
emitReturnableEvents: ServiceEventsBase; | ||
onBroadcast: ServiceEventsBase; | ||
emitBroadcast: ServiceEventsBase; | ||
} | ||
|
||
export class Plugin | ||
extends BSBService<Config, ServiceTypes> { | ||
public static PLUGIN_CLIENT = { | ||
name: "service-bsb-npm", | ||
}; | ||
public initBeforePlugins?: string[] | undefined; | ||
public initAfterPlugins?: string[] | undefined; | ||
public runBeforePlugins?: string[] | undefined; | ||
public runAfterPlugins?: string[] | undefined; | ||
public methods = {}; | ||
|
||
dispose?(): void; | ||
|
||
constructor(config: BSBServiceConstructor) { | ||
super(config); | ||
} | ||
|
||
private getNPMFilePath(workingDir: string) { | ||
return join(workingDir, "package.json"); | ||
} | ||
public async init() { | ||
await this.events.onReturnableEvent("isNPMInitialized", async (workingDir: string) => | ||
existsSync(join(workingDir, "package.json")), | ||
); | ||
await this.events.onReturnableEvent("initNPM", async (workingDir: string) => | ||
writeFileSync(this.getNPMFilePath(workingDir), JSON.stringify({}, null, 2)), | ||
); | ||
await this.events.onReturnableEvent("getNPMConfig", async (workingDir: string) => | ||
this.getNPMConfig(workingDir), | ||
); | ||
await this.events.onReturnableEvent("updateNPMConfig", async (workingDir: string, config: NPMConfig) => | ||
this.updateNPMConfig(workingDir, config), | ||
); | ||
} | ||
|
||
public async run() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": [ | ||
"ES2022" | ||
], | ||
"module": "CommonJS", | ||
"target": "ES2022", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": [ | ||
"types/*" | ||
] | ||
}, | ||
"noImplicitAny": true, | ||
"removeComments": true, | ||
"preserveConstEnums": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"sourceMap": true, | ||
"outDir": "lib", | ||
"rootDir": "src", | ||
"strict": true, | ||
"declaration": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"esModuleInterop": false, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"linterOptions": { | ||
}, | ||
"compileOnSave": true, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# don't ever lint node_modules | ||
node_modules | ||
# don't lint build output (make sure it's set to your correct build folder name) | ||
lib | ||
_exports | ||
src/plugins/-*/*.* | ||
templates | ||
docker | ||
build |
Oops, something went wrong.