@sapphire/cli 0.0.2-next.1c6703c.0 → 0.0.2-next.326520a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/commands/generate.js +25 -5
- package/dist/functions/CreateFileFromTemplate.js +10 -1
- package/oclif.manifest.json +1 -1
- package/package.json +6 -5
- package/templates/.sapphirerc.json.sapphire +14 -0
- package/templates/components/argument.js.sapphire +15 -0
- package/templates/components/argument.ts.sapphire +11 -0
- package/templates/components/command.js.sapphire +17 -0
- package/templates/components/command.ts.sapphire +14 -0
- package/templates/components/listener.js.sapphire +15 -0
- package/templates/components/listener.ts.sapphire +9 -0
- package/templates/components/precondition.js.sapphire +11 -0
- package/templates/components/precondition.ts.sapphire +16 -0
package/README.md
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://github.com/sapphiredev/cli/blob/main/LICENSE.md)
|
|
10
10
|
[](https://www.npmjs.com/package/@sapphire/cli)
|
|
11
|
-
[](https://depfu.com/github/sapphiredev/cli?project_id=31779)
|
|
12
11
|
|
|
13
12
|
</div>
|
|
14
13
|
|
|
@@ -9,16 +9,21 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const promises_1 = require("fs/promises");
|
|
10
10
|
const ora_1 = (0, tslib_1.__importDefault)(require("ora"));
|
|
11
11
|
const path_1 = require("path");
|
|
12
|
+
const promises_2 = require("timers/promises");
|
|
12
13
|
class Generate extends command_1.Command {
|
|
13
14
|
async run() {
|
|
14
15
|
const { args } = this.parse(Generate);
|
|
15
16
|
const spinner = (0, ora_1.default)(`Creating a ${args.component.toLowerCase()}`).start();
|
|
16
|
-
const
|
|
17
|
+
const fail = (error) => {
|
|
18
|
+
spinner.fail(error);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
};
|
|
21
|
+
const configLoc = await this.fetchConfig();
|
|
17
22
|
if (!configLoc)
|
|
18
|
-
return;
|
|
23
|
+
return fail("Can't find the Sapphire CLI config.");
|
|
19
24
|
const config = JSON.parse(await (0, promises_1.readFile)(configLoc, 'utf8'));
|
|
20
25
|
if (!config)
|
|
21
|
-
return;
|
|
26
|
+
return fail("Can't parse the Sapphire CLI config.");
|
|
22
27
|
await this.createComponent(args.component, args.name, config, configLoc.replace('.sapphirerc.json', '')).catch((err) => {
|
|
23
28
|
spinner.fail();
|
|
24
29
|
console.log((0, chalk_1.red)(err.message));
|
|
@@ -36,15 +41,30 @@ class Generate extends command_1.Command {
|
|
|
36
41
|
const corePath = `${__dirname}/../../templates/components/${template}`;
|
|
37
42
|
const userPath = config.customFileTemplates.enabled ? (0, path_1.join)(configLoc, config.customFileTemplates.location, template) : null;
|
|
38
43
|
const target = (0, path_1.join)(configLoc, config.locations.base, '%L%', `${name}.${projectLanguage}`);
|
|
44
|
+
const params = { name: (0, path_1.basename)(name) };
|
|
39
45
|
if (userPath && (0, fs_1.existsSync)(userPath)) {
|
|
40
|
-
return (0, _functions_1.CreateFileFromTemplate)(userPath, target, config,
|
|
46
|
+
return (0, _functions_1.CreateFileFromTemplate)(userPath, target, config, params, true, true).then(resolve).catch(reject);
|
|
41
47
|
}
|
|
42
48
|
else if ((0, fs_1.existsSync)(corePath)) {
|
|
43
|
-
return (0, _functions_1.CreateFileFromTemplate)(`components/${template}`, target, config,
|
|
49
|
+
return (0, _functions_1.CreateFileFromTemplate)(`components/${template}`, target, config, params, false, true).then(resolve).catch(reject);
|
|
44
50
|
}
|
|
45
51
|
return reject(new Error("Can't find the template."));
|
|
46
52
|
});
|
|
47
53
|
}
|
|
54
|
+
timeout(ms) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
// false positive
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
58
|
+
return (0, promises_2.setTimeout)(ms)
|
|
59
|
+
.then(() => {
|
|
60
|
+
resolve(null);
|
|
61
|
+
})
|
|
62
|
+
.catch(reject);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
fetchConfig() {
|
|
66
|
+
return Promise.race([(0, find_up_1.default)('.sapphirerc.json', { cwd: '.' }), this.timeout(5000)]);
|
|
67
|
+
}
|
|
48
68
|
}
|
|
49
69
|
exports.default = Generate;
|
|
50
70
|
Object.defineProperty(Generate, "description", {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateFileFromTemplate = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const promises_1 = require("fs/promises");
|
|
7
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
6
8
|
function CreateFileFromTemplate(template, target, config, params, custom = false, component = false) {
|
|
7
9
|
return new Promise(async (resolve, reject) => {
|
|
8
10
|
const location = custom ? template : `${__dirname}/../../templates/${template}`;
|
|
@@ -26,7 +28,7 @@ function CreateFileFromTemplate(template, target, config, params, custom = false
|
|
|
26
28
|
const ta = component ? target.replace('%L%', dir) : target;
|
|
27
29
|
if ((0, fs_1.existsSync)(ta))
|
|
28
30
|
reject(new Error('Component already exists'));
|
|
29
|
-
await (
|
|
31
|
+
await writeFileRecursive(ta, output.f).catch(reject);
|
|
30
32
|
return resolve(true);
|
|
31
33
|
});
|
|
32
34
|
}
|
|
@@ -37,4 +39,11 @@ function getComponentTemplateWithConfig(path) {
|
|
|
37
39
|
return [JSON.parse(fa[0]), fa[2]];
|
|
38
40
|
});
|
|
39
41
|
}
|
|
42
|
+
function writeFileRecursive(target, data) {
|
|
43
|
+
return new Promise(async (resolve, reject) => {
|
|
44
|
+
const dir = path_1.default.dirname(path_1.default.resolve(target));
|
|
45
|
+
await (0, promises_1.mkdir)(dir, { recursive: true }).catch(reject);
|
|
46
|
+
return (0, promises_1.writeFile)(path_1.default.resolve(target), data).then(resolve).catch(reject);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
40
49
|
//# sourceMappingURL=CreateFileFromTemplate.js.map
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.0.2-next.
|
|
1
|
+
{"version":"0.0.2-next.326520a.0","commands":{"generate":{"id":"generate","description":"generate a component (command, listener, etc.)","pluginName":"@sapphire/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"component","required":true},{"name":"name","required":true}]},"new":{"id":"new","description":"create a new Sapphire project","pluginName":"@sapphire/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"verbose":{"name":"verbose","type":"boolean","char":"v","allowNo":false}},"args":[{"name":"ProjectName","default":"NewSapphireProject"}]}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/cli",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.326520a.0",
|
|
4
4
|
"description": "CLI for Sapphire Framework",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"!dist/**/*.js.map",
|
|
21
21
|
"!dist/**/*.d.ts",
|
|
22
22
|
"!dist/**/*.d.ts.map",
|
|
23
|
-
"oclif.manifest.json"
|
|
23
|
+
"oclif.manifest.json",
|
|
24
|
+
"templates"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"lint": "eslint src --ext ts --fix",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"@sapphire/eslint-config": "^3.2.3",
|
|
55
56
|
"@sapphire/prettier-config": "^1.1.6",
|
|
56
57
|
"@sapphire/ts-config": "^3.0.0",
|
|
57
|
-
"@types/node": "^16.
|
|
58
|
+
"@types/node": "^16.10.1",
|
|
58
59
|
"@types/prompts": "^2.0.14",
|
|
59
60
|
"@typescript-eslint/eslint-plugin": "^4.31.2",
|
|
60
61
|
"@typescript-eslint/parser": "^4.31.2",
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"prettier": "^2.4.1",
|
|
69
70
|
"pretty-quick": "^3.1.1",
|
|
70
71
|
"standard-version": "^9.3.1",
|
|
71
|
-
"ts-node": "^10.2.
|
|
72
|
+
"ts-node": "^10.2.1",
|
|
72
73
|
"typescript": "^4.4.2"
|
|
73
74
|
},
|
|
74
75
|
"engines": {
|
|
@@ -115,7 +116,7 @@
|
|
|
115
116
|
"kind-of": "^6.0.3",
|
|
116
117
|
"dot-prop": "^6.0.1",
|
|
117
118
|
"lodash": "^4.17.21",
|
|
118
|
-
"marked": "^2.
|
|
119
|
+
"marked": "^2.1.3",
|
|
119
120
|
"merge": "^2.1.1",
|
|
120
121
|
"trim": "^1.0.1",
|
|
121
122
|
"trim-newlines": "^3.0.1"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projectLanguage": "{{language}}",
|
|
3
|
+
"locations": {
|
|
4
|
+
"base": "src",
|
|
5
|
+
"arguments": "arguments",
|
|
6
|
+
"commands": "commands",
|
|
7
|
+
"listeners": "listeners",
|
|
8
|
+
"preconditions": "preconditions"
|
|
9
|
+
},
|
|
10
|
+
"customFileTemplates": {
|
|
11
|
+
"enabled": false,
|
|
12
|
+
"location": ""
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{ "category": "arguments" }
|
|
2
|
+
---
|
|
3
|
+
import { Argument } from "@sapphire/framework";
|
|
4
|
+
|
|
5
|
+
export class UserArgument extends Argument {
|
|
6
|
+
constructor(context, options) {
|
|
7
|
+
super(context, {
|
|
8
|
+
...options
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run(parameter) {
|
|
13
|
+
return this.ok(parameter);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{ "category": "arguments" }
|
|
2
|
+
---
|
|
3
|
+
import { ApplyOptions } from '@sapphire/decorators';
|
|
4
|
+
import { Argument, ArgumentOptions } from "@sapphire/framework";
|
|
5
|
+
|
|
6
|
+
@ApplyOptions<ArgumentOptions>({})
|
|
7
|
+
export class UserArgument extends Argument<string> {
|
|
8
|
+
async run(parameter: string) {
|
|
9
|
+
return this.ok(parameter);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{ "category": "commands" }
|
|
2
|
+
---
|
|
3
|
+
const { SubCommandPluginCommand } = require('@sapphire/plugin-subcommands');
|
|
4
|
+
|
|
5
|
+
class UserCommand extends SubCommandPluginCommand {
|
|
6
|
+
constructor(context, options) {
|
|
7
|
+
super(context, {
|
|
8
|
+
...options
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run(message) {
|
|
13
|
+
return msg.channel.send('Hello world!');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.UserCommand = UserCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{ "category": "commands" }
|
|
2
|
+
---
|
|
3
|
+
import { ApplyOptions } from '@sapphire/decorators';
|
|
4
|
+
import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
|
|
5
|
+
import { Message } from 'discord.js';
|
|
6
|
+
|
|
7
|
+
@ApplyOptions<SubCommandPluginCommandOptions>({
|
|
8
|
+
description: 'A basic command'
|
|
9
|
+
})
|
|
10
|
+
export class UserCommand extends SubCommandPluginCommand {
|
|
11
|
+
public async run(message: Message) {
|
|
12
|
+
return message.channel.send('Hello world!');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{ "category": "listeners" }
|
|
2
|
+
---
|
|
3
|
+
const { Listener } = require('@sapphire/framework');
|
|
4
|
+
|
|
5
|
+
class UserEvent extends Listener {
|
|
6
|
+
constructor(context, options = {}) {
|
|
7
|
+
super(context, {
|
|
8
|
+
...options
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
run() {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.UserEvent = UserEvent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{ "category": "preconditions" }
|
|
2
|
+
---
|
|
3
|
+
import { Precondition } from '@sapphire/framework';
|
|
4
|
+
import type { Message } from 'discord.js';
|
|
5
|
+
|
|
6
|
+
export class UserPrecondition extends Precondition {
|
|
7
|
+
public run(message: Message) {
|
|
8
|
+
return this.ok();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module '@sapphire/framework' {
|
|
13
|
+
interface Preconditions {
|
|
14
|
+
{{name}}: never;
|
|
15
|
+
}
|
|
16
|
+
}
|