-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#296: first draft of the cli with build command
- Loading branch information
1 parent
c8e1446
commit 26c05f8
Showing
21 changed files
with
264 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,4 @@ | ||
|
||
# Changelog | ||
|
||
This package doesn't keep a changelog. See the changelog in the [github repository](https://github.com/MaskingTechnology/jitar/blob/main/CHANGELOG.md) |
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 @@ | ||
|
||
# Jitar Caching | ||
|
||
This package contains the components for creating the runtime cache for [Jitar](https://jitar.dev) applications. | ||
|
||
For more information about Jitar: | ||
|
||
* [Visit our website](https://jitar.dev) | ||
* [Read the documentation](https://docs.jitar.dev). |
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,45 @@ | ||
{ | ||
"name": "@jitar/cli", | ||
"version": "0.7.4", | ||
"description": "JavaScript CLI library for the Jitar runtime.", | ||
"author": "Masking Technology <[email protected]> (https://jitar.dev)", | ||
"license": "MIT", | ||
"type": "module", | ||
"types": "dist/lib.d.ts", | ||
"exports": { | ||
".": "./dist/lib.js" | ||
}, | ||
"files": [ | ||
"CHANGELOG.md", | ||
"README.md", | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"test-coverage": "vitest run --coverage", | ||
"lint": "eslint . --ext .ts", | ||
"build": "tsc -p tsconfig.json", | ||
"clean": "rm -rf dist", | ||
"prepublishOnly": "npm run clean && npm run build" | ||
}, | ||
"dependencies": { | ||
"@jitar/caching": "*", | ||
"@jitar/server-nodejs": "*" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/MaskingTechnology/jitar.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/MaskingTechnology/jitar/issues" | ||
}, | ||
"homepage": "https://jitar.dev", | ||
"keywords": [ | ||
"javascript", | ||
"cli", | ||
"jitar" | ||
] | ||
} |
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,23 @@ | ||
|
||
import { ArgumentManager } from './arguments'; | ||
import { CommandManager } from './commands'; | ||
|
||
export default class CliManager | ||
{ | ||
#argumentManager: ArgumentManager; | ||
#commandManager: CommandManager; | ||
|
||
constructor() | ||
{ | ||
this.#argumentManager = new ArgumentManager(process.argv); | ||
this.#commandManager = new CommandManager(); | ||
} | ||
|
||
manage(): Promise<void> | ||
{ | ||
const command = this.#argumentManager.getCommand(); | ||
const args = this.#argumentManager.getArguments(); | ||
|
||
return this.#commandManager.execute(command, args); | ||
} | ||
} |
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,33 @@ | ||
|
||
const COMMAND_INDEX = 2; | ||
|
||
export default class ArgumentManager | ||
{ | ||
#args: string[]; | ||
|
||
constructor(args: string[]) | ||
{ | ||
this.#args = args; | ||
} | ||
|
||
getCommand(): string | ||
{ | ||
return this.#args[COMMAND_INDEX]; | ||
} | ||
|
||
getArguments(): Map<string, string> | ||
{ | ||
const args = this.#args.slice(COMMAND_INDEX + 1); | ||
|
||
const map = new Map<string, string>(); | ||
|
||
args.forEach((arg) => | ||
{ | ||
const [key, value] = arg.split('='); | ||
|
||
map.set(key.trim(), value.trim()); | ||
}); | ||
|
||
return map; | ||
} | ||
} |
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,2 @@ | ||
|
||
export { default as ArgumentManager } from './ArgumentManager'; |
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,26 @@ | ||
|
||
import Command from './interfaces/Command'; | ||
|
||
import BuildCache from './implementations/BuildCache'; | ||
|
||
export default class CommandManager | ||
{ | ||
#commands: Map<string, Command> = new Map<string, Command>(); | ||
|
||
constructor() | ||
{ | ||
this.#commands.set('build', new BuildCache()); | ||
} | ||
|
||
execute(name: string, args: Map<string, string>): Promise<void> | ||
{ | ||
const command = this.#commands.get(name); | ||
|
||
if (command === undefined) | ||
{ | ||
throw new Error(`Command ${name} not found`); | ||
} | ||
|
||
return command.execute(args); | ||
} | ||
} |
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,17 @@ | ||
|
||
import { LocalFileManager } from '@jitar/server-nodejs'; | ||
import { CacheManager } from '@jitar/caching'; | ||
|
||
import Command from '../interfaces/Command'; | ||
|
||
export default class BuildCache implements Command | ||
{ | ||
async execute(args: Map<string, string>): Promise<void> | ||
{ | ||
const projectFileManager = new LocalFileManager('./'); | ||
const appFileManager = new LocalFileManager('./dist'); | ||
|
||
const cacheManager = new CacheManager(projectFileManager, appFileManager); | ||
cacheManager.build(); | ||
} | ||
} |
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,2 @@ | ||
|
||
export { default as CommandManager } from './CommandManager'; |
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,5 @@ | ||
|
||
export default interface Command | ||
{ | ||
execute(args: Map<string, string>): Promise<void>; | ||
} |
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,2 @@ | ||
|
||
export { default as CliManager } from './CliManager'; |
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,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "es2022", | ||
"rootDir": "./src/", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"removeComments": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": [ | ||
"vite.config.ts", | ||
"node_modules", | ||
"dist", | ||
"test" | ||
] | ||
} |
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,10 @@ | ||
// vite.config.ts | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
coverage: { | ||
provider: 'v8' | ||
}, | ||
}, | ||
}); |
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
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
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,6 @@ | ||
#!/usr/bin/env node | ||
|
||
import { CliManager } from '@jitar/cli'; | ||
|
||
const cliManager = new CliManager(); | ||
cliManager.manage(); |
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
Oops, something went wrong.