@sapphire/cli 1.2.1-next.b7ba03c.0 → 1.2.1-next.d253e1c.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.
@@ -2,7 +2,7 @@ import { componentsFolder } from '#constants';
2
2
  import { CreateFileFromTemplate } from '#functions/CreateFileFromTemplate';
3
3
  import { fileExists } from '#functions/FileExists';
4
4
  import { Spinner } from '@favware/colorette-spinner';
5
- import { fromAsync, isErr } from '@sapphire/result';
5
+ import { Result } from '@sapphire/result';
6
6
  import { blueBright, red } from 'colorette';
7
7
  import findUp from 'find-up';
8
8
  import { load } from 'js-yaml';
@@ -38,8 +38,7 @@ export default async (component, name) => {
38
38
  const spinner = new Spinner(`Creating a ${component.toLowerCase()}`).start();
39
39
  const fail = (error, additionalExecution) => {
40
40
  spinner.error({ text: error });
41
- if (additionalExecution)
42
- additionalExecution();
41
+ additionalExecution?.();
43
42
  process.exit(1);
44
43
  };
45
44
  const configLoc = await fetchConfig();
@@ -50,12 +49,14 @@ export default async (component, name) => {
50
49
  if (!config) {
51
50
  return fail("Can't parse the Sapphire CLI config.");
52
51
  }
53
- const result = await fromAsync(async () => createComponent(component, name, config, configLoc.replace(/.sapphirerc.(json|yml)/g, '')));
54
- if (isErr(result)) {
55
- return fail(result.error.message, () => console.log(red(result.error.message)));
56
- }
57
- spinner.success();
58
- console.log(blueBright('Done!'));
59
- process.exit(0);
52
+ const result = await Result.fromAsync(() => createComponent(component, name, config, configLoc.replace(/.sapphirerc.(json|yml)/g, '')));
53
+ return result.match({
54
+ ok: () => {
55
+ spinner.success();
56
+ console.log(blueBright('Done!'));
57
+ process.exit(0);
58
+ },
59
+ err: (error) => fail(error.message, () => console.log(red(error.message)))
60
+ });
60
61
  };
61
62
  //# sourceMappingURL=generate.js.map
@@ -4,7 +4,7 @@ import { CreateFileFromTemplate } from '#functions/CreateFileFromTemplate';
4
4
  import { fileExists } from '#functions/FileExists';
5
5
  import { PromptNew } from '#prompts/PromptNew';
6
6
  import { Spinner } from '@favware/colorette-spinner';
7
- import { fromAsync, isErr, isOk } from '@sapphire/result';
7
+ import { Result } from '@sapphire/result';
8
8
  import { blueBright, red } from 'colorette';
9
9
  import { execa } from 'execa';
10
10
  import { cp, readFile, rm, writeFile } from 'node:fs/promises';
@@ -16,18 +16,15 @@ async function editPackageJson(location, name) {
16
16
  if (!output)
17
17
  throw new Error("Can't read file.");
18
18
  output.name = name;
19
- const result = await fromAsync(() => writeFile(pjLocation, JSON.stringify(output, null, 2)));
20
- return isOk(result);
19
+ const result = await Result.fromAsync(() => writeFile(pjLocation, JSON.stringify(output, null, 2)));
20
+ return result.isOk();
21
21
  }
22
22
  async function installDeps(location, pm, verbose) {
23
- const result = await fromAsync(() => execa(pm.toLowerCase(), ['install'], {
23
+ const value = await execa(pm.toLowerCase(), ['install'], {
24
24
  stdio: verbose ? 'inherit' : undefined,
25
25
  cwd: `./${location}/`
26
- }));
27
- if (isErr(result)) {
28
- throw result.error;
29
- }
30
- if (result.value.exitCode !== 0) {
26
+ });
27
+ if (value.exitCode !== 0) {
31
28
  throw new Error('An unknown error occurred while installing the dependencies. Try running Sapphire CLI with "--verbose" flag.');
32
29
  }
33
30
  const oppositeLockfile = `./${location}/${pm === 'npm' ? 'yarn.lock' : 'package-lock.json'}`;
@@ -41,14 +38,11 @@ async function configureYarnRc(location, name, value) {
41
38
  return true;
42
39
  }
43
40
  async function installYarnV3(location, verbose) {
44
- const result = await fromAsync(() => execa('yarn', ['set', 'version', 'berry'], {
41
+ const value = await execa('yarn', ['set', 'version', 'berry'], {
45
42
  stdio: verbose ? 'inherit' : undefined,
46
43
  cwd: `./${location}/`
47
- }));
48
- if (isErr(result)) {
49
- throw result.error;
50
- }
51
- if (result.value.exitCode !== 0) {
44
+ });
45
+ if (value.exitCode !== 0) {
52
46
  throw new Error('An unknown error occurred while installing Yarn v3. Try running Sapphire CLI with "--verbose" flag.');
53
47
  }
54
48
  await Promise.all([
@@ -68,23 +62,22 @@ async function initializeGitRepo(location) {
68
62
  }
69
63
  async function runJob(job, name) {
70
64
  const spinner = new Spinner(name).start();
71
- const result = await fromAsync(async () => job());
72
- if (isErr(result)) {
73
- spinner.error({ text: red(result.error.message) });
74
- console.error(red(result.error.message));
75
- throw result.error;
76
- }
77
- spinner.success();
78
- return true;
65
+ const result = await Result.fromAsync(() => job());
66
+ return result.match({
67
+ ok: () => {
68
+ spinner.success();
69
+ return true;
70
+ },
71
+ err: (error) => {
72
+ spinner.error({ text: red(error.message) });
73
+ console.error(red(error.message));
74
+ throw error;
75
+ }
76
+ });
79
77
  }
80
78
  async function cloneRepo(location, verbose) {
81
- const result = await fromAsync(async () => execa('git', ['clone', repoUrl, `${location}/ghr`], {
82
- stdio: verbose ? 'inherit' : undefined
83
- }));
84
- if (isErr(result)) {
85
- throw result.error;
86
- }
87
- if (result.value.exitCode !== 0) {
79
+ const value = await execa('git', ['clone', repoUrl, `${location}/ghr`], { stdio: verbose ? 'inherit' : undefined });
80
+ if (value.exitCode !== 0) {
88
81
  throw new Error('An unknown error occurred while cloning the repository. Try running Sapphire CLI with "--verbose" flag.');
89
82
  }
90
83
  return true;
@@ -22,14 +22,14 @@
22
22
  SOFTWARE.
23
23
  */
24
24
  import { fileExists } from '#functions/FileExists';
25
- import { fromAsync, isErr } from '@sapphire/result';
25
+ import { Result } from '@sapphire/result';
26
26
  import { execa } from 'execa';
27
27
  import { constants } from 'node:fs';
28
28
  import { access } from 'node:fs/promises';
29
29
  const windows = process.platform === 'win32';
30
30
  async function isExecutable(command) {
31
- const result = await fromAsync(() => access(command, constants.X_OK));
32
- return isErr(result);
31
+ const result = await Result.fromAsync(() => access(command, constants.X_OK));
32
+ return result.isErr();
33
33
  }
34
34
  function cleanWindowsCommand(input) {
35
35
  if (/[^A-Za-z0-9_\/:=-]/.test(input)) {
@@ -44,22 +44,22 @@ async function commandExistsUnix(command) {
44
44
  return true;
45
45
  }
46
46
  }
47
- const result = await fromAsync(() => execa('which', [command]));
48
- if (isErr(result)) {
49
- return false;
50
- }
51
- return Boolean(result.value.stdout);
47
+ const result = await Result.fromAsync(() => execa('which', [command]));
48
+ return result.match({
49
+ err: () => false,
50
+ ok: (value) => Boolean(value.stdout)
51
+ });
52
52
  }
53
53
  const invalidWindowsCommandNameRegex = /[\x00-\x1f<>:"|?*]/;
54
54
  async function commandExistsWindows(command) {
55
55
  if (invalidWindowsCommandNameRegex.test(command)) {
56
56
  return false;
57
57
  }
58
- const result = await fromAsync(async () => execa('where', [cleanWindowsCommand(command)]));
59
- if (isErr(result)) {
60
- return fileExists(command);
61
- }
62
- return true;
58
+ const result = await Result.fromAsync(async () => execa('where', [cleanWindowsCommand(command)]));
59
+ return result.match({
60
+ err: () => fileExists(command),
61
+ ok: () => true
62
+ });
63
63
  }
64
64
  export async function CommandExists(command) {
65
65
  return windows ? commandExistsWindows(command) : commandExistsUnix(command);
@@ -1,7 +1,7 @@
1
- import { fromAsync, isOk } from '@sapphire/result';
1
+ import { Result } from '@sapphire/result';
2
2
  import { access } from 'node:fs/promises';
3
3
  export async function fileExists(filePath) {
4
- const result = await fromAsync(() => access(filePath));
5
- return isOk(result);
4
+ const result = await Result.fromAsync(() => access(filePath));
5
+ return result.isOk();
6
6
  }
7
7
  //# sourceMappingURL=FileExists.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/cli",
3
- "version": "1.2.1-next.b7ba03c.0",
3
+ "version": "1.2.1-next.d253e1c.0",
4
4
  "description": "CLI for Sapphire Framework",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@favware/colorette-spinner": "^1.0.0",
42
- "@sapphire/result": "^1.1.1",
42
+ "@sapphire/result": "^2.0.1",
43
43
  "colorette": "^2.0.19",
44
- "commander": "^9.3.0",
44
+ "commander": "^9.4.0",
45
45
  "execa": "^6.1.0",
46
46
  "find-up": "^5.0.0",
47
47
  "js-yaml": "^4.1.0",
@@ -57,12 +57,12 @@
57
57
  "@sapphire/prettier-config": "^1.4.3",
58
58
  "@sapphire/ts-config": "^3.3.4",
59
59
  "@types/js-yaml": "^4.0.5",
60
- "@types/node": "^17.0.33",
61
- "@types/prompts": "^2.0.14",
62
- "@typescript-eslint/eslint-plugin": "^5.30.3",
63
- "@typescript-eslint/parser": "^5.30.3",
60
+ "@types/node": "^18.0.1",
61
+ "@types/prompts": "^2.4.0",
62
+ "@typescript-eslint/eslint-plugin": "^5.30.6",
63
+ "@typescript-eslint/parser": "^5.30.6",
64
64
  "cz-conventional-changelog": "^3.3.0",
65
- "eslint": "^8.19.0",
65
+ "eslint": "^8.20.0",
66
66
  "eslint-config-prettier": "^8.5.0",
67
67
  "eslint-plugin-prettier": "^4.2.1",
68
68
  "globby": "^13.1.2",
@@ -71,7 +71,7 @@
71
71
  "pinst": "^3.0.0",
72
72
  "prettier": "^2.7.1",
73
73
  "pretty-quick": "^3.1.3",
74
- "ts-node": "^10.8.2",
74
+ "ts-node": "^10.9.1",
75
75
  "typescript": "^4.7.4"
76
76
  },
77
77
  "resolutions": {