@aztt-cli/utils 0.0.2 → 0.0.3

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 (2) hide show
  1. package/build/index.js +60 -3
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -1,4 +1,61 @@
1
- function isObject(obj) {
2
- return Object.prototype.toString.call(obj) === "[object Object]";
1
+ 'use strict';
2
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
3
+ import { Spinner } from 'cli-spinner';
4
+ import { spawn } from 'child_process';
5
+ function isObject(o) {
6
+ return Object.prototype.toString.call(o) === '[object Object]';
3
7
  }
4
- export { isObject };
8
+ function spinnerStart(msg, spinnerString = '|/-\\') {
9
+ const spinner = new Spinner(`${msg} %s`);
10
+ spinner.setSpinnerString(spinnerString);
11
+ spinner.start();
12
+ return spinner;
13
+ }
14
+ function sleep(timeout = 1000) {
15
+ return new Promise(resolve => setTimeout(resolve, timeout));
16
+ }
17
+ function exec(command, args, options = {}) {
18
+ const win32 = process.platform === 'win32';
19
+ const cmd = win32 ? 'cmd' : command;
20
+ const cmdArgs = win32 ? ['/c'].concat(command, args) : args;
21
+ return spawn(cmd, cmdArgs, options);
22
+ }
23
+ function execAsync(command, args, options = {}) {
24
+ return new Promise((resolve, reject) => {
25
+ const p = exec(command, args, options);
26
+ p.on('error', e => {
27
+ reject(e);
28
+ });
29
+ p.on('exit', c => {
30
+ resolve(c);
31
+ });
32
+ });
33
+ }
34
+ function readFile(path, options = {}) {
35
+ if (existsSync(path)) {
36
+ const buffer = readFileSync(path);
37
+ if (buffer) {
38
+ if (options.toJson) {
39
+ return buffer.toJSON();
40
+ }
41
+ else {
42
+ return buffer.toString();
43
+ }
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+ function writeFile(path, data, { rewrite = true } = {}) {
49
+ if (existsSync(path)) {
50
+ if (rewrite) {
51
+ writeFileSync(path, data);
52
+ return true;
53
+ }
54
+ return false;
55
+ }
56
+ else {
57
+ writeFileSync(path, data);
58
+ return true;
59
+ }
60
+ }
61
+ export { isObject, spinnerStart, sleep, exec, execAsync, readFile, writeFile, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztt-cli/utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "> TODO: description",
6
6
  "author": "za990326 <956267437@qq.com>",