-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add support for manifest and packaging of Legacy Script En…
…gine plugins
- Loading branch information
Showing
17 changed files
with
397 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
# Legacy Script Engine Scaffold | ||
|
||
A utility for assisting in the development of Legacy Script Engine plugins, supporting a native development experience on the Node.js platform. | ||
|
||
> Only TypeScript projects are supported at the moment. | ||
## 📦 Prepare | ||
|
||
It is a non-intrusive tool, meaning it does not require any mandatory files to be kept in your project. However, it is recommended to add it as a development dependency to your environment for convenient usage: | ||
|
||
```bash | ||
npm install legacy-script-engine-scaffold --save-dev | ||
``` | ||
|
||
## 🚀 Usage | ||
|
||
Generate manifest.json for the Legacy Script Engine plugin: | ||
|
||
```bash | ||
npx lses manifest | ||
``` | ||
|
||
Package the Legacy Script Engine plugin: | ||
|
||
```bash | ||
npx lses pack | ||
``` |
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,41 @@ | ||
import { CliLoggableError } from "./CliLoggableError"; | ||
|
||
|
||
export class CliLogger { | ||
private static TOOL_NAME: string = "legacy-script-engine-scaffold"; | ||
|
||
private readonly methodName: string; | ||
|
||
public constructor(methodName: string) { | ||
this.methodName = methodName; | ||
} | ||
|
||
public success(msg: string): void { | ||
console.log( | ||
`✅ ${CliLogger.TOOL_NAME}::${this.methodName}: ${msg}` | ||
) | ||
} | ||
|
||
public error(error: CliLoggableError): void { | ||
let suggestionString: string = ""; | ||
|
||
if (error.getSuggestion().length === 1) { | ||
suggestionString += `Suggestion: ${error.getSuggestion()[0]}`; | ||
} else { | ||
suggestionString += "Suggestions:\n"; | ||
|
||
let solutionIndex: number = 1; | ||
|
||
for (const solution of error.getSuggestion()) { | ||
suggestionString += ` ${solutionIndex}. ${solution}\n`; | ||
solutionIndex++; | ||
} | ||
|
||
suggestionString = suggestionString.slice(0, -2); // Remove the last newline. | ||
} | ||
|
||
console.error( | ||
`❌ ${CliLogger.TOOL_NAME}::${this.methodName}: ${error.constructor.name} - ${error.getMessage()}\n ${suggestionString}` | ||
); | ||
} | ||
} |
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,55 @@ | ||
#!/usr/bin/env node | ||
|
||
|
||
import { program } from "commander"; | ||
|
||
import { CliLogger } from "./CliLogger"; | ||
import { TypeScriptProject } from "../project/TypeScriptProject"; | ||
import { CliLoggableError } from "./CliLoggableError"; | ||
import { Packager } from "../packager/Packager"; | ||
|
||
|
||
program | ||
.name("lses") | ||
.version("0.1.0") | ||
.description("A utility for assisting in the development of Legacy Script Engine plugins."); | ||
|
||
program | ||
.command("manifest") | ||
.description("generate manifest.json for the Legacy Script Engine plugin") | ||
.action((): void => { | ||
const logger: CliLogger = new CliLogger("manifest"); | ||
|
||
try { | ||
const project: TypeScriptProject = TypeScriptProject.getInstance(); | ||
|
||
const successMessage: string = project.getManifest().generate(); | ||
logger.success(successMessage); | ||
} catch (error) { | ||
logger.error(error as CliLoggableError); | ||
} | ||
}); | ||
|
||
program | ||
.command("pack") | ||
.description("package the Legacy Script Engine plugin") | ||
.action(async (): Promise<void> => { | ||
const logger = new CliLogger("pack"); | ||
|
||
try { | ||
const project: TypeScriptProject = TypeScriptProject.getInstance(); | ||
const packager: Packager = new Packager(project); | ||
|
||
const successMessage: string = await packager.package(); | ||
logger.success(successMessage); | ||
} catch (error) { | ||
logger.error(error as CliLoggableError); | ||
} | ||
}); | ||
|
||
program.on("command:*", (): void => { | ||
console.error(`Error: Invalid command lses ${program.args.join(" ")}`); | ||
program.help(); | ||
}); | ||
|
||
program.parse(process.argv); |
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,25 @@ | ||
import { CliLoggableError } from "../cli/CliLoggableError"; | ||
|
||
|
||
export class NodeJsConfigurationFileNotFoundError extends Error implements CliLoggableError { | ||
private readonly msg: string; | ||
|
||
public constructor(fileDirectory: string) { | ||
const message: string = `Could not find package.json in ${fileDirectory}.`; | ||
|
||
super(message); | ||
|
||
this.msg = message; | ||
} | ||
|
||
public getMessage(): string { | ||
return this.msg; | ||
} | ||
|
||
public getSuggestion(): Array<string> { | ||
const suggestion: Array<string> = new Array<string>(); | ||
suggestion.push("Try `npm init` to initialize the project."); | ||
|
||
return suggestion; | ||
} | ||
} |
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,27 @@ | ||
import { CliLoggableError } from "../cli/CliLoggableError"; | ||
|
||
|
||
export class NodeJsConfigurationMissingError extends Error implements CliLoggableError { | ||
private readonly msg: string; | ||
private readonly missingProperty: string; | ||
|
||
public constructor(filePath: string, missingProperty: string) { | ||
const message: string = `${filePath} is missing the required property \`${missingProperty}\`.`; | ||
|
||
super(message); | ||
|
||
this.msg = message; | ||
this.missingProperty = missingProperty; | ||
} | ||
|
||
public getMessage(): string { | ||
return this.msg; | ||
} | ||
|
||
public getSuggestion(): Array<string> { | ||
const suggestion: Array<string> = new Array<string>(); | ||
suggestion.push(`Try checking if package.json includes the \`${this.missingProperty}\` configuration.`); | ||
|
||
return suggestion; | ||
} | ||
} |
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,25 @@ | ||
import { CliLoggableError } from "../cli/CliLoggableError"; | ||
|
||
|
||
export class TypeScriptConfigurationFileNotFoundError extends Error implements CliLoggableError { | ||
private readonly msg: string; | ||
|
||
public constructor(fileDirectory: string) { | ||
const message: string = `Could not find tsconfig.json in ${fileDirectory}.`; | ||
|
||
super(message); | ||
|
||
this.msg = message; | ||
} | ||
|
||
public getMessage(): string { | ||
return this.msg; | ||
} | ||
|
||
public getSuggestion(): Array<string> { | ||
const suggestion: Array<string> = new Array<string>(); | ||
suggestion.push("Try `npx tsc --init` to initialize the TypeScript project."); | ||
|
||
return suggestion; | ||
} | ||
} |
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,27 @@ | ||
import { CliLoggableError } from "../cli/CliLoggableError"; | ||
|
||
|
||
export class TypeScriptConfigurationMissingError extends Error implements CliLoggableError { | ||
private readonly msg: string; | ||
private readonly missingProperty: string; | ||
|
||
public constructor(filePath: string, missingProperty: string) { | ||
const message: string = `${filePath} is missing the required property \`${missingProperty}\`.`; | ||
|
||
super(message); | ||
|
||
this.msg = message; | ||
this.missingProperty = missingProperty; | ||
} | ||
|
||
public getMessage(): string { | ||
return this.msg; | ||
} | ||
|
||
public getSuggestion(): Array<string> { | ||
const suggestion: Array<string> = new Array<string>(); | ||
suggestion.push(`Try checking if tsconfig.json includes the \`${this.missingProperty}\` configuration.`); | ||
|
||
return suggestion; | ||
} | ||
} |
Oops, something went wrong.