@youcan/cli-kit 2.1.4 → 2.2.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.
Files changed (51) hide show
  1. package/dist/common/string.d.ts +2 -2
  2. package/dist/common/string.js +11 -11
  3. package/dist/index.d.ts +18 -17
  4. package/dist/index.js +2 -0
  5. package/dist/internal/node/constants.d.ts +5 -5
  6. package/dist/internal/node/constants.js +10 -10
  7. package/dist/internal/node/ui.d.ts +11 -11
  8. package/dist/internal/node/ui.js +40 -40
  9. package/dist/node/callback.d.ts +5 -5
  10. package/dist/node/callback.js +53 -53
  11. package/dist/node/cli.d.ts +21 -21
  12. package/dist/node/cli.js +61 -61
  13. package/dist/node/config.d.ts +20 -20
  14. package/dist/node/config.js +20 -22
  15. package/dist/node/context/helpers.d.ts +1 -1
  16. package/dist/node/context/helpers.js +5 -5
  17. package/dist/node/context/local.d.ts +2 -2
  18. package/dist/node/context/local.js +2 -2
  19. package/dist/node/crypto.d.ts +12 -9
  20. package/dist/node/crypto.js +23 -23
  21. package/dist/node/env.d.ts +5 -6
  22. package/dist/node/env.js +36 -47
  23. package/dist/node/filesystem.d.ts +30 -29
  24. package/dist/node/filesystem.js +81 -78
  25. package/dist/node/form.d.ts +9 -9
  26. package/dist/node/form.js +39 -39
  27. package/dist/node/git.d.ts +10 -10
  28. package/dist/node/git.js +46 -46
  29. package/dist/node/github.d.ts +6 -6
  30. package/dist/node/github.js +8 -8
  31. package/dist/node/http.d.ts +4 -4
  32. package/dist/node/http.js +35 -32
  33. package/dist/node/path.d.ts +5 -5
  34. package/dist/node/path.js +14 -14
  35. package/dist/node/session.d.ts +8 -8
  36. package/dist/node/session.js +92 -78
  37. package/dist/node/system.d.ts +23 -21
  38. package/dist/node/system.js +74 -58
  39. package/dist/node/tasks.d.ts +8 -7
  40. package/dist/node/tasks.js +33 -25
  41. package/dist/node/worker.d.ts +16 -19
  42. package/dist/node/worker.js +43 -30
  43. package/dist/ui/components/DevOutput.d.ts +27 -0
  44. package/dist/ui/components/DevOutput.js +60 -0
  45. package/dist/ui/components/HotKeys.d.ts +12 -0
  46. package/dist/ui/components/HotKeys.js +25 -0
  47. package/dist/ui/components/utils/symbols.d.ts +3 -0
  48. package/dist/ui/components/utils/symbols.js +7 -0
  49. package/dist/ui/index.d.ts +2 -0
  50. package/dist/ui/index.js +2 -0
  51. package/package.json +6 -2
@@ -1,9 +1,12 @@
1
- /// <reference types="node" />
2
- export declare function randomHex(size: number): string;
3
- export declare function base64URLEncode(str: Buffer): string;
4
- export declare function sha256(str: string): Buffer;
5
- export declare function sha1(str: Buffer | string): string;
6
- export declare function hashString(str: string): string;
7
- export declare function fileHash(buff: Buffer): string;
8
- export declare function randomBytes(size: number): Buffer;
9
- export declare function randomUUID(): string;
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import type { BinaryLike } from 'crypto';
5
+ export declare function randomHex(size: number): string;
6
+ export declare function base64URLEncode(str: Buffer): string;
7
+ export declare function sha256(str: BinaryLike): Buffer;
8
+ export declare function sha1(str: BinaryLike): string;
9
+ export declare function hashString(str: string): string;
10
+ export declare function fileHash(buff: BinaryLike): string;
11
+ export declare function randomBytes(size: number): Buffer;
12
+ export declare function randomUUID(): string;
@@ -1,28 +1,28 @@
1
1
  import crypto from 'node:crypto';
2
2
 
3
- function randomHex(size) {
4
- return crypto.randomBytes(size).toString('hex');
5
- }
6
- function base64URLEncode(str) {
7
- return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/[=]/g, '');
8
- }
9
- function sha256(str) {
10
- return crypto.createHash('sha256').update(str).digest();
11
- }
12
- function sha1(str) {
13
- return crypto.createHash('sha1').update(str).digest('hex');
14
- }
15
- function hashString(str) {
16
- return crypto.createHash('sha1').update(str).digest('hex');
17
- }
18
- function fileHash(buff) {
19
- return crypto.createHash('md5').update(buff).digest('hex');
20
- }
21
- function randomBytes(size) {
22
- return crypto.randomBytes(size);
23
- }
24
- function randomUUID() {
25
- return crypto.randomUUID();
3
+ function randomHex(size) {
4
+ return crypto.randomBytes(size).toString('hex');
5
+ }
6
+ function base64URLEncode(str) {
7
+ return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/[=]/g, '');
8
+ }
9
+ function sha256(str) {
10
+ return crypto.createHash('sha256').update(str).digest();
11
+ }
12
+ function sha1(str) {
13
+ return crypto.createHash('sha1').update(str).digest('hex');
14
+ }
15
+ function hashString(str) {
16
+ return crypto.createHash('sha1').update(str).digest('hex');
17
+ }
18
+ function fileHash(buff) {
19
+ return crypto.createHash('md5').update(buff).digest('hex');
20
+ }
21
+ function randomBytes(size) {
22
+ return crypto.randomBytes(size);
23
+ }
24
+ function randomUUID() {
25
+ return crypto.randomUUID();
26
26
  }
27
27
 
28
28
  export { base64URLEncode, fileHash, hashString, randomBytes, randomHex, randomUUID, sha1, sha256 };
@@ -1,6 +1,5 @@
1
- import { ENV_VARS } from '@/internal/node/constants';
2
- export declare function get(key: keyof typeof ENV_VARS): string;
3
- export declare function oauthClientId(): string;
4
- export declare function oauthClientSecret(): string;
5
- export declare function sellerAreaHostname(): string;
6
- export declare function apiHostname(): string;
1
+ import { ENV_VARS } from '@/internal/node/constants';
2
+ export declare function get(key: keyof typeof ENV_VARS): string;
3
+ export declare function oauthClientId(): string;
4
+ export declare function sellerAreaHostname(): string;
5
+ export declare function apiHostname(): string;
package/dist/node/env.js CHANGED
@@ -1,51 +1,40 @@
1
1
  import { ENV_VARS } from '../internal/node/constants.js';
2
2
 
3
- function get(key) {
4
- return process.env[ENV_VARS[key]];
5
- }
6
- function oauthClientId() {
7
- switch (get('HOST_ENV')) {
8
- case 'dev':
9
- return '3';
10
- case 'test':
11
- return '11';
12
- case 'prod':
13
- default:
14
- return '8';
15
- }
16
- }
17
- function oauthClientSecret() {
18
- switch (get('HOST_ENV')) {
19
- case 'dev':
20
- return 'kvvtjXFCeuvvNX2nwD30SAfh7DMbVXm16E0MPCTu';
21
- case 'test':
22
- return 'UkNttuRvqjPtX08nSzwGssnKPb21Kg0s0NJNKMAo';
23
- case 'prod':
24
- default:
25
- return 'lvUw2mQ7nXp4WqZ9CZlURMgRGAra3KuOrYhFlU7X';
26
- }
27
- }
28
- function sellerAreaHostname() {
29
- switch (get('HOST_ENV')) {
30
- case 'dev':
31
- return 'seller-area.dotshop.com';
32
- case 'test':
33
- return 'seller-area.testyoucan.shop';
34
- case 'prod':
35
- default:
36
- return 'seller-area.youcan.shop';
37
- }
38
- }
39
- function apiHostname() {
40
- switch (get('HOST_ENV')) {
41
- case 'dev':
42
- return 'api.dotshop.com';
43
- case 'test':
44
- return 'api.testyoucan.shop';
45
- case 'prod':
46
- default:
47
- return 'api.youcan.shop';
48
- }
3
+ function get(key) {
4
+ return process.env[ENV_VARS[key]];
5
+ }
6
+ function oauthClientId() {
7
+ switch (get('HOST_ENV')) {
8
+ case 'dev':
9
+ return '1';
10
+ case 'test':
11
+ return '11';
12
+ case 'prod':
13
+ default:
14
+ return '398';
15
+ }
16
+ }
17
+ function sellerAreaHostname() {
18
+ switch (get('HOST_ENV')) {
19
+ case 'dev':
20
+ return 'seller-area.dotshop.com';
21
+ case 'test':
22
+ return 'seller-area.testyoucan.shop';
23
+ case 'prod':
24
+ default:
25
+ return 'seller-area.youcan.shop';
26
+ }
27
+ }
28
+ function apiHostname() {
29
+ switch (get('HOST_ENV')) {
30
+ case 'dev':
31
+ return 'api.dotshop.com';
32
+ case 'test':
33
+ return 'api.testyoucan.shop';
34
+ case 'prod':
35
+ default:
36
+ return 'api.youcan.shop';
37
+ }
49
38
  }
50
39
 
51
- export { apiHostname, get, oauthClientId, oauthClientSecret, sellerAreaHostname };
40
+ export { apiHostname, get, oauthClientId, sellerAreaHostname };
@@ -1,29 +1,30 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import type { Mode, OpenMode, PathLike, Stats } from 'fs';
4
- import type { GlobOptions } from 'glob';
5
- export declare function exists(path: string): Promise<boolean>;
6
- export declare function isDirectory(path: string): Promise<boolean>;
7
- export declare function tapIntoTmp<T>(callback: (tmp: string) => T | Promise<T>): Promise<T>;
8
- export declare function mkdir(path: string): Promise<void>;
9
- interface MoveFileOptions {
10
- overwrite?: boolean;
11
- }
12
- export declare function move(src: string, dest: string, options?: MoveFileOptions): Promise<void>;
13
- export declare function readFile(path: PathLike, options?: {
14
- encoding?: BufferEncoding;
15
- flag?: OpenMode;
16
- }): Promise<Buffer | string>;
17
- export declare function writeFile(path: PathLike, data: string, options?: {
18
- encoding: BufferEncoding;
19
- flag: Mode;
20
- }): Promise<void>;
21
- export declare function readJsonFile<T = Record<string, unknown>>(path: PathLike): Promise<T>;
22
- export declare function writeJsonFile(path: PathLike, data: Record<string, unknown>): Promise<void>;
23
- export declare function glob(pattern: string | string[], options?: GlobOptions): Promise<string[]>;
24
- export declare function archived(path: string, name: string, glob?: string): Promise<string>;
25
- export declare function unlink(path: string): Promise<void>;
26
- export declare function readdir(path: string): Promise<string[]>;
27
- export declare function stat(path: string): Promise<Stats>;
28
- export declare const watch: typeof import("chokidar").watch;
29
- export {};
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import type { Mode, OpenMode, PathLike, Stats } from 'fs';
5
+ import type { GlobOptions } from 'glob';
6
+ export declare function exists(path: string): Promise<boolean>;
7
+ export declare function isDirectory(path: string): Promise<boolean>;
8
+ export declare function tapIntoTmp<T>(callback: (tmp: string) => T | Promise<T>): Promise<T>;
9
+ export declare function mkdir(path: string): Promise<void>;
10
+ interface MoveFileOptions {
11
+ overwrite?: boolean;
12
+ }
13
+ export declare function move(src: string, dest: string, options?: MoveFileOptions): Promise<void>;
14
+ export declare function readFile(path: PathLike, options?: {
15
+ encoding?: BufferEncoding;
16
+ flag?: OpenMode;
17
+ }): Promise<Buffer | string>;
18
+ export declare function writeFile(path: PathLike, data: string, options?: {
19
+ encoding: BufferEncoding;
20
+ flag: Mode;
21
+ }): Promise<void>;
22
+ export declare function readJsonFile<T = Record<string, unknown>>(path: PathLike): Promise<T>;
23
+ export declare function writeJsonFile(path: PathLike, data: Record<string, unknown>): Promise<void>;
24
+ export declare function glob(pattern: string | string[], options?: GlobOptions): Promise<string[]>;
25
+ export declare function archived(path: string, name: string, glob?: string): Promise<string>;
26
+ export declare function unlink(path: string): Promise<void>;
27
+ export declare function readdir(path: string): Promise<string[]>;
28
+ export declare function stat(path: string): Promise<Stats>;
29
+ export declare const watch: typeof import("chokidar").watch;
30
+ export {};
@@ -20,85 +20,88 @@ import 'formdata-node/file-from-path';
20
20
  import 'kleur';
21
21
  import 'conf';
22
22
  import 'dayjs';
23
+ import '../ui/components/DevOutput.js';
24
+ import 'react';
25
+ import 'ink';
23
26
 
24
- async function exists(path) {
25
- try {
26
- await FilesystemPromises.access(path);
27
- return true;
28
- }
29
- catch {
30
- return false;
31
- }
32
- }
33
- async function isDirectory(path) {
34
- try {
35
- const stats = await FilesystemPromises.stat(path);
36
- return stats.isDirectory();
37
- }
38
- catch {
39
- return false;
40
- }
41
- }
42
- async function tapIntoTmp(callback) {
43
- return temporaryDirectoryTask(callback);
44
- }
45
- async function mkdir(path) {
46
- await FilesystemPromises.mkdir(path, { recursive: true });
47
- }
48
- async function move(src, dest, options = {}) {
49
- await FsExtra.move(src, dest, options);
50
- }
51
- async function readFile(path, options = { encoding: 'utf-8', flag: 'r' }) {
52
- return await FilesystemPromises.readFile(path, options);
53
- }
54
- async function writeFile(path, data, options = { encoding: 'utf-8', flag: 'w' }) {
55
- return await FilesystemPromises.writeFile(path, data, options);
56
- }
57
- async function readJsonFile(path) {
58
- const file = await readFile(path);
59
- return JSON.parse(file instanceof Buffer ? file.toString() : file);
60
- }
61
- async function writeJsonFile(path, data) {
62
- return writeFile(path, JSON.stringify(data, null, 4));
63
- }
64
- async function glob(pattern, options) {
65
- let _options = options;
66
- if (options?.dot == null) {
67
- _options = { ...options, dot: true };
68
- }
69
- return glob$1.glob(pattern, _options || {});
70
- }
71
- async function archived(path$1, name, glob = '**/*') {
72
- return new Promise((resolve$1, reject) => {
73
- try {
74
- const archivePath = resolve(path$1, `${name}.zip`);
75
- const output = createWriteStream(archivePath);
76
- const _archiver = archiver('zip', { zlib: { level: 9 } });
77
- output.on('close', () => resolve$1(archivePath));
78
- _archiver.on('error', () => (err) => reject(err));
79
- _archiver.pipe(output);
80
- _archiver.glob(glob, {
81
- ignore: [`${name}.zip`],
82
- cwd: path$1,
83
- });
84
- _archiver.finalize();
85
- }
86
- catch (err) {
87
- reject(err);
88
- }
89
- });
90
- }
91
- async function unlink(path) {
92
- if (await exists(path)) {
93
- await FilesystemPromises.unlink(path);
94
- }
95
- }
96
- async function readdir(path) {
97
- return await FilesystemPromises.readdir(path);
98
- }
99
- async function stat(path) {
100
- return await FilesystemPromises.stat(path);
101
- }
27
+ async function exists(path) {
28
+ try {
29
+ await FilesystemPromises.access(path);
30
+ return true;
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ }
36
+ async function isDirectory(path) {
37
+ try {
38
+ const stats = await FilesystemPromises.stat(path);
39
+ return stats.isDirectory();
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ async function tapIntoTmp(callback) {
46
+ return temporaryDirectoryTask(callback);
47
+ }
48
+ async function mkdir(path) {
49
+ await FilesystemPromises.mkdir(path, { recursive: true });
50
+ }
51
+ async function move(src, dest, options = {}) {
52
+ await FsExtra.move(src, dest, options);
53
+ }
54
+ async function readFile(path, options = { encoding: 'utf-8', flag: 'r' }) {
55
+ return await FilesystemPromises.readFile(path, options);
56
+ }
57
+ async function writeFile(path, data, options = { encoding: 'utf-8', flag: 'w' }) {
58
+ return await FilesystemPromises.writeFile(path, data, options);
59
+ }
60
+ async function readJsonFile(path) {
61
+ const content = await readFile(path, { encoding: 'utf8' });
62
+ return JSON.parse(content);
63
+ }
64
+ async function writeJsonFile(path, data) {
65
+ return writeFile(path, JSON.stringify(data, null, 4));
66
+ }
67
+ async function glob(pattern, options) {
68
+ let _options = options;
69
+ if (options?.dot == null) {
70
+ _options = { ...options, dot: true };
71
+ }
72
+ return glob$1.glob(pattern, _options || {});
73
+ }
74
+ async function archived(path$1, name, glob = '**/*') {
75
+ return new Promise((resolve$1, reject) => {
76
+ try {
77
+ const archivePath = resolve(path$1, `${name}.zip`);
78
+ const output = createWriteStream(archivePath);
79
+ const _archiver = archiver('zip', { zlib: { level: 9 } });
80
+ output.on('close', () => resolve$1(archivePath));
81
+ _archiver.on('error', () => (err) => reject(err));
82
+ _archiver.pipe(output);
83
+ _archiver.glob(glob, {
84
+ ignore: [`${name}.zip`],
85
+ cwd: path$1,
86
+ });
87
+ _archiver.finalize();
88
+ }
89
+ catch (err) {
90
+ reject(err);
91
+ }
92
+ });
93
+ }
94
+ async function unlink(path) {
95
+ if (await exists(path)) {
96
+ await FilesystemPromises.unlink(path);
97
+ }
98
+ }
99
+ async function readdir(path) {
100
+ return await FilesystemPromises.readdir(path);
101
+ }
102
+ async function stat(path) {
103
+ return await FilesystemPromises.stat(path);
104
+ }
102
105
  const watch = chokidar.watch;
103
106
 
104
107
  export { archived, exists, glob, isDirectory, mkdir, move, readFile, readJsonFile, readdir, stat, tapIntoTmp, unlink, watch, writeFile, writeJsonFile };
@@ -1,9 +1,9 @@
1
- /// <reference types="node" />
2
- import { FormData } from 'formdata-node';
3
- import type { FormDataEntryValue } from 'formdata-node';
4
- import { fileFromPath } from 'formdata-node/file-from-path';
5
- export type FormDataResolvable = Array<FormDataResolvable> | {
6
- [key: string]: FormDataResolvable;
7
- } | FormDataEntryValue | undefined | boolean | number | Blob | Date | null;
8
- export declare const file: typeof fileFromPath;
9
- export declare function convert(source: Record<string, FormDataResolvable>, form?: FormData, parentKey?: string | null): FormData;
1
+ /// <reference types="node" />
2
+ import { FormData } from 'formdata-node';
3
+ import type { FormDataEntryValue } from 'formdata-node';
4
+ import { fileFromPath } from 'formdata-node/file-from-path';
5
+ export type FormDataResolvable = Array<FormDataResolvable> | {
6
+ [key: string]: FormDataResolvable;
7
+ } | FormDataEntryValue | undefined | boolean | number | Blob | Date | null;
8
+ export declare const file: typeof fileFromPath;
9
+ export declare function convert(source: Record<string, FormDataResolvable>, form?: FormData, parentKey?: string | null): FormData;
package/dist/node/form.js CHANGED
@@ -1,45 +1,45 @@
1
1
  import { FormData, File } from 'formdata-node';
2
2
  import { fileFromPath } from 'formdata-node/file-from-path';
3
3
 
4
- const file = fileFromPath;
5
- function convert(source, form = new FormData(), parentKey = null) {
6
- source = source || {};
7
- for (const key in source) {
8
- if (Object.prototype.hasOwnProperty.call(source, key)) {
9
- append(form, toKey(parentKey, key), source[key]);
10
- }
11
- }
12
- return form;
13
- }
14
- function append(form, key, value) {
15
- if (Array.isArray(value)) {
16
- return Array.from(value.keys()).forEach(index => append(form, toKey(key, index.toString()), value[index]));
17
- }
18
- else if (value instanceof Date) {
19
- return form.append(key, value.toISOString());
20
- }
21
- else if (value instanceof File) {
22
- return form.append(key, value, value.name);
23
- }
24
- else if (value instanceof Blob) {
25
- return form.append(key, value);
26
- }
27
- else if (typeof value === 'boolean') {
28
- return form.append(key, value ? '1' : '0');
29
- }
30
- else if (typeof value === 'string') {
31
- return form.append(key, value);
32
- }
33
- else if (typeof value === 'number') {
34
- return form.append(key, `${value}`);
35
- }
36
- else if (value === null || value === undefined) {
37
- return form.append(key, '');
38
- }
39
- convert(value, form, key);
40
- }
41
- function toKey(parent, key) {
42
- return parent ? `${parent}[${key}]` : key;
4
+ const file = fileFromPath;
5
+ function convert(source, form = new FormData(), parentKey = null) {
6
+ source = source || {};
7
+ for (const key in source) {
8
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
9
+ append(form, toKey(parentKey, key), source[key]);
10
+ }
11
+ }
12
+ return form;
13
+ }
14
+ function append(form, key, value) {
15
+ if (Array.isArray(value)) {
16
+ return Array.from(value.keys()).forEach(index => append(form, toKey(key, index.toString()), value[index]));
17
+ }
18
+ else if (value instanceof Date) {
19
+ return form.append(key, value.toISOString());
20
+ }
21
+ else if (value instanceof File) {
22
+ return form.append(key, value, value.name);
23
+ }
24
+ else if (value instanceof Blob) {
25
+ return form.append(key, value);
26
+ }
27
+ else if (typeof value === 'boolean') {
28
+ return form.append(key, value ? '1' : '0');
29
+ }
30
+ else if (typeof value === 'string') {
31
+ return form.append(key, value);
32
+ }
33
+ else if (typeof value === 'number') {
34
+ return form.append(key, `${value}`);
35
+ }
36
+ else if (value === null || value === undefined) {
37
+ return form.append(key, '');
38
+ }
39
+ convert(value, form, key);
40
+ }
41
+ function toKey(parent, key) {
42
+ return parent ? `${parent}[${key}]` : key;
43
43
  }
44
44
 
45
45
  export { convert, file };
@@ -1,10 +1,10 @@
1
- export declare function binaryExists(): Promise<boolean>;
2
- export interface CloneOptions {
3
- url: string;
4
- destination: string;
5
- progressUpdater?: (statusString: string) => void;
6
- shallow?: boolean;
7
- latestTag?: boolean;
8
- }
9
- export declare function assertGitExists(): Promise<void>;
10
- export declare function clone(cloneOptions: CloneOptions): Promise<void>;
1
+ export declare function binaryExists(): Promise<boolean>;
2
+ export interface CloneOptions {
3
+ url: string;
4
+ destination: string;
5
+ progressUpdater?: (statusString: string) => void;
6
+ shallow?: boolean;
7
+ latestTag?: boolean;
8
+ }
9
+ export declare function assertGitExists(): Promise<void>;
10
+ export declare function clone(cloneOptions: CloneOptions): Promise<void>;
package/dist/node/git.js CHANGED
@@ -1,52 +1,52 @@
1
1
  import git from 'simple-git';
2
2
  import { exec } from './system.js';
3
3
 
4
- async function binaryExists() {
5
- try {
6
- await exec('git', ['--version']);
7
- return true;
8
- }
9
- catch {
10
- return false;
11
- }
12
- }
13
- async function assertGitExists() {
14
- if (!(await binaryExists())) {
15
- throw new Error('Git is required for the setup to continue.');
16
- }
17
- }
18
- async function clone(cloneOptions) {
19
- await assertGitExists();
20
- const { url, destination, shallow, latestTag } = cloneOptions;
21
- const [repository, branch] = url.split('#');
22
- const options = { '--recurse-submodules': null };
23
- // ignore latest tag if branch is provided
24
- if (branch) {
25
- options['--branch'] = branch;
26
- }
27
- if (shallow && latestTag) {
28
- throw new Error('Cannot get a shallow clone of the latest branch.');
29
- }
30
- if (shallow) {
31
- options['--depth'] = 1;
32
- }
33
- const simpleGitOptions = {
34
- config: ['core.askpass=true'],
35
- };
36
- await git(simpleGitOptions)
37
- .clone(repository, destination, options);
38
- if (latestTag) {
39
- const localRepo = git(destination);
40
- const latestTag = await getLocalLatestTag(localRepo, url);
41
- await localRepo.checkout(latestTag);
42
- }
43
- }
44
- async function getLocalLatestTag(repository, url) {
45
- const latest = (await repository.tags()).latest;
46
- if (!latest) {
47
- throw new Error(`Couldn't infer the latest tag from ${url}`);
48
- }
49
- return latest;
4
+ async function binaryExists() {
5
+ try {
6
+ await exec('git', ['--version']);
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }
13
+ async function assertGitExists() {
14
+ if (!(await binaryExists())) {
15
+ throw new Error('Git is required for the setup to continue.');
16
+ }
17
+ }
18
+ async function clone(cloneOptions) {
19
+ await assertGitExists();
20
+ const { url, destination, shallow, latestTag } = cloneOptions;
21
+ const [repository, branch] = url.split('#');
22
+ const options = { '--recurse-submodules': null };
23
+ // ignore latest tag if branch is provided
24
+ if (branch) {
25
+ options['--branch'] = branch;
26
+ }
27
+ if (shallow && latestTag) {
28
+ throw new Error('Cannot get a shallow clone of the latest branch.');
29
+ }
30
+ if (shallow) {
31
+ options['--depth'] = 1;
32
+ }
33
+ const simpleGitOptions = {
34
+ config: ['core.askpass=true'],
35
+ };
36
+ await git(simpleGitOptions)
37
+ .clone(repository, destination, options);
38
+ if (latestTag) {
39
+ const localRepo = git(destination);
40
+ const latestTag = await getLocalLatestTag(localRepo, url);
41
+ await localRepo.checkout(latestTag);
42
+ }
43
+ }
44
+ async function getLocalLatestTag(repository, url) {
45
+ const latest = (await repository.tags()).latest;
46
+ if (!latest) {
47
+ throw new Error(`Couldn't infer the latest tag from ${url}`);
48
+ }
49
+ return latest;
50
50
  }
51
51
 
52
52
  export { assertGitExists, binaryExists, clone };
@@ -1,6 +1,6 @@
1
- export interface RepositoryReference {
2
- baseUrl: string;
3
- branch?: string;
4
- path?: string;
5
- }
6
- export declare function parseRepositoryReference(reference: string): RepositoryReference;
1
+ export interface RepositoryReference {
2
+ baseUrl: string;
3
+ branch?: string;
4
+ path?: string;
5
+ }
6
+ export declare function parseRepositoryReference(reference: string): RepositoryReference;