@nemo-cli/shared 0.0.6 → 0.1.1

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.
@@ -1,60 +0,0 @@
1
- import npmlog from 'npmlog';
2
- declare const DEFAULT_OPTIONS: {
3
- heading: string;
4
- level: string;
5
- };
6
- export declare const log: {
7
- init: (customOptions?: typeof DEFAULT_OPTIONS) => void;
8
- level: unknown;
9
- stopDebug(): void;
10
- debug(): void;
11
- timing(prefix: string | undefined, time: string | number): void;
12
- error(prefix?: string, ...messages: unknown[]): void;
13
- verbose(prefix?: string, ...messages: unknown[]): void;
14
- success(prefix?: string, ...messages: unknown[]): void;
15
- clearScreen(): void;
16
- clearTerminal(): void;
17
- beep(): void;
18
- scrollDown(): void;
19
- scrollUp(): void;
20
- eraseEndLine(): void;
21
- record: npmlog.MessageObject[];
22
- maxRecordSize: number;
23
- prefixStyle: npmlog.StyleObject;
24
- headingStyle: npmlog.StyleObject;
25
- heading: string;
26
- stream: any;
27
- log(level: string, prefix: string, message: string, ...args: any[]): void;
28
- silly(prefix: string, message: string, ...args: any[]): void;
29
- info(prefix: string, message: string, ...args: any[]): void;
30
- http(prefix: string, message: string, ...args: any[]): void;
31
- notice(prefix: string, message: string, ...args: any[]): void;
32
- warn(prefix: string, message: string, ...args: any[]): void;
33
- silent(prefix: string, message: string, ...args: any[]): void;
34
- enableColor(): void;
35
- disableColor(): void;
36
- enableProgress(): void;
37
- disableProgress(): void;
38
- progressEnabled(): boolean;
39
- enableUnicode(): void;
40
- disableUnicode(): void;
41
- pause(): void;
42
- resume(): void;
43
- addLevel(level: string, n: number, style?: npmlog.StyleObject | undefined, disp?: string | undefined): void;
44
- addListener(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
45
- on(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
46
- once(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
47
- removeListener(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
48
- off(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
49
- removeAllListeners(event?: string | symbol | undefined): npmlog.Logger;
50
- setMaxListeners(n: number): npmlog.Logger;
51
- getMaxListeners(): number;
52
- listeners(eventName: string | symbol): Function[];
53
- rawListeners(eventName: string | symbol): Function[];
54
- emit(eventName: string | symbol, ...args: any[]): boolean;
55
- listenerCount(eventName: string | symbol): number;
56
- prependListener(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
57
- prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): npmlog.Logger;
58
- eventNames(): (string | symbol)[];
59
- };
60
- export {};
package/dist/utils/log.js DELETED
@@ -1,102 +0,0 @@
1
- import chalk from 'chalk';
2
- import npmlog from 'npmlog';
3
- import ansiEscapes from 'ansi-escapes';
4
- import { isString } from './types.js';
5
- // type LogLevels = "silly" | "verbose" | "info" | "timing" | "http" | "notice" | "warn" | "error" | "silent";
6
- const DEFAULT_OPTIONS = {
7
- heading: '@nemo-cli',
8
- level: 'warn'
9
- };
10
- const init = (customOptions) => {
11
- const options = { ...DEFAULT_OPTIONS, ...customOptions };
12
- npmlog.heading = options.heading;
13
- npmlog.level = options.level;
14
- npmlog.addLevel('success', 8000, {
15
- fg: 'green',
16
- bg: 'black',
17
- bold: true,
18
- bell: true
19
- });
20
- };
21
- init();
22
- const transformMessage = (messages) => {
23
- for (let i = 0; i < messages.length; i++) {
24
- const [current, next] = [messages[i], messages[i + 1]];
25
- if (isString(current) && isString(next)) {
26
- messages.splice(i, 2, `${current}${next}`);
27
- }
28
- }
29
- return messages;
30
- };
31
- export const log = {
32
- ...npmlog,
33
- init,
34
- get level() {
35
- throw new Error("can't visit level");
36
- },
37
- set level(_) {
38
- throw new Error('use setLevel');
39
- },
40
- stopDebug() {
41
- npmlog.level = 'warn';
42
- npmlog.warn('current npmlog level', npmlog.level);
43
- },
44
- debug() {
45
- npmlog.level = 'silly';
46
- npmlog.warn('current npmlog level', npmlog.level);
47
- },
48
- timing(prefix = '', time) {
49
- npmlog.timing(prefix, `${time}`);
50
- },
51
- error(prefix = '', ...messages) {
52
- transformMessage(messages).forEach((message) => {
53
- if (isString(message)) {
54
- npmlog.error(prefix, chalk.red.bgBlack(message));
55
- }
56
- else {
57
- console.log(message);
58
- }
59
- });
60
- },
61
- verbose(prefix = '', ...messages) {
62
- transformMessage(messages).forEach((message) => {
63
- if (isString(message)) {
64
- npmlog.verbose(prefix, message);
65
- }
66
- else {
67
- npmlog.verbose(prefix, JSON.stringify(message, null, 2));
68
- }
69
- });
70
- },
71
- success(prefix = '', ...messages) {
72
- transformMessage(messages).forEach((message) => {
73
- if (isString(message)) {
74
- npmlog.success(prefix, chalk.green.bgBlack(message));
75
- }
76
- else {
77
- console.log(message);
78
- }
79
- });
80
- },
81
- clearScreen() {
82
- process.stdout.write(ansiEscapes.clearScreen);
83
- },
84
- clearTerminal() {
85
- process.stdout.write(ansiEscapes.clearTerminal);
86
- },
87
- beep() {
88
- process.stdout.write(ansiEscapes.beep);
89
- },
90
- scrollDown() {
91
- process.stdout.write(ansiEscapes.scrollDown);
92
- },
93
- scrollUp() {
94
- process.stdout.write(ansiEscapes.scrollUp);
95
- },
96
- eraseEndLine() {
97
- // process.stdout.moveCursor(0, -1)
98
- // process.stdout.clearLine(0)
99
- process.stdout.write(ansiEscapes.cursorPrevLine);
100
- process.stdout.write(ansiEscapes.eraseLine);
101
- }
102
- };
@@ -1,7 +0,0 @@
1
- type NPM_INFO = {
2
- 'dist-tags': {
3
- latest: `${number}.${number}.${number}`;
4
- };
5
- };
6
- export declare const getNpmInfo: (npmName: string, register: string) => Promise<NPM_INFO>;
7
- export {};
@@ -1,10 +0,0 @@
1
- import { log } from './log.js';
2
- export const getNpmInfo = (npmName, register) => {
3
- const url = new URL(npmName, register);
4
- return fetch(url.toString())
5
- .then((data) => data.json())
6
- .catch((err) => {
7
- log.error('network', err.message);
8
- throw new Error(err);
9
- });
10
- };
@@ -1,6 +0,0 @@
1
- export declare const filename: <T extends {
2
- url: string;
3
- }>(importMate: T) => string;
4
- export declare const dirname: <T extends {
5
- url: string;
6
- }>(importMate: T) => string;
@@ -1,4 +0,0 @@
1
- import { fileURLToPath } from 'node:url';
2
- import { dirname as _dirname } from 'node:path';
3
- export const filename = (importMate) => fileURLToPath(importMate.url);
4
- export const dirname = (importMate) => _dirname(filename(importMate));
@@ -1 +0,0 @@
1
- export declare const tryPromise: <T>(promise: Promise<T>) => Promise<[any, T]>;
@@ -1,9 +0,0 @@
1
- export const tryPromise = async (promise) => {
2
- try {
3
- const result = await promise;
4
- return [null, result];
5
- }
6
- catch (err) {
7
- return [err, null];
8
- }
9
- };
@@ -1,2 +0,0 @@
1
- import { type Options } from 'ora';
2
- export declare const ora: (options: string | Options) => import("ora").Ora;
@@ -1,15 +0,0 @@
1
- import instance from 'ora';
2
- import { isString } from './types.js';
3
- const BASE_OPTIONS = {
4
- timeout: 10000
5
- };
6
- export const ora = (options) => {
7
- if (!isString(options))
8
- return instance(options);
9
- // TODO: add logo...
10
- const spinner = instance({
11
- // spinner: {},
12
- text: options
13
- });
14
- return spinner;
15
- };
@@ -1,19 +0,0 @@
1
- declare const hasOwn: (target: unknown, key: PropertyKey) => boolean;
2
- declare const has: <T extends object, K extends PropertyKey>(target: T, key: K) => boolean;
3
- declare const isLocal: (url?: string) => boolean;
4
- declare const isString: <T1 extends string = string>(obj: unknown) => obj is T1;
5
- declare const isNumber: <T1 extends number = number>(obj: unknown) => obj is T1;
6
- declare const isBoolean: <T1 extends boolean = boolean>(obj: unknown) => obj is T1;
7
- declare const isNull: <T1 extends null = null>(obj: unknown) => obj is T1;
8
- declare const isUndefined: <T1 extends undefined = undefined>(obj: unknown) => obj is T1;
9
- declare const isError: <T1 extends Error = Error>(obj: unknown) => obj is T1;
10
- declare const isPromise: <T1 extends Promise<unknown> = Promise<unknown>>(obj: unknown) => obj is T1;
11
- declare const isPlainObject: <T1 extends Record<string, unknown> = Record<string, unknown>>(obj: unknown) => obj is T1;
12
- declare const isArray: <T1 extends unknown[] = unknown[]>(obj: unknown) => obj is T1;
13
- declare const isDate: <T1 extends Date = Date>(obj: unknown) => obj is T1;
14
- declare const isSymbol: <T1 extends symbol = symbol>(obj: unknown) => obj is T1;
15
- declare const isSet: <T1 extends Set<unknown> = Set<unknown>>(obj: unknown) => obj is T1;
16
- declare const isMap: <T1 extends Map<unknown, unknown> = Map<unknown, unknown>>(obj: unknown) => obj is T1;
17
- declare const isFormData: <T1 extends FormData = FormData>(obj: unknown) => obj is T1;
18
- declare const isURLSearchParams: <T1 extends URLSearchParams = URLSearchParams>(obj: unknown) => obj is T1;
19
- export { hasOwn, has, isString, isNumber, isBoolean, isNull, isUndefined, isError, isPromise, isPlainObject, isArray, isDate, isSymbol, isSet, isMap, isFormData, isURLSearchParams, isLocal };
@@ -1,22 +0,0 @@
1
- const { toString, hasOwnProperty } = Object.prototype;
2
- const hasOwn = (target, key) => hasOwnProperty.call(target, key);
3
- const has = (target, key) => Reflect.has(target, key);
4
- const localRegExp = /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/;
5
- const isLocal = (url = window.location.hostname) => url === 'localhost' || url === '[::1]' || url.match(localRegExp) !== null;
6
- const isType = (type) => (obj) => toString.call(obj) === `[object ${type}]`;
7
- const isString = isType('String');
8
- const isNumber = isType('Number');
9
- const isBoolean = isType('Boolean');
10
- const isNull = isType('Null');
11
- const isUndefined = isType('Undefined');
12
- const isError = isType('Error');
13
- const isPromise = isType('Promise');
14
- const isPlainObject = isType('Object');
15
- const isArray = isType('Array');
16
- const isDate = isType('Date');
17
- const isSymbol = isType('Symbol');
18
- const isSet = isType('Set');
19
- const isMap = isType('Map');
20
- const isFormData = isType('FormData');
21
- const isURLSearchParams = isType('URLSearchParams');
22
- export { hasOwn, has, isString, isNumber, isBoolean, isNull, isUndefined, isError, isPromise, isPlainObject, isArray, isDate, isSymbol, isSet, isMap, isFormData, isURLSearchParams, isLocal };