nsgm-cli 2.1.7 → 2.1.9

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/lib/utils.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare const firstUpperCase: (word: string) => string;
2
+ export declare const mkdirSync: (dirPath: string) => void;
3
+ export declare const rmFileSync: (filePath: string) => void;
4
+ export declare const rmdirSync: (dirPath: string) => void;
5
+ export declare const copyFileSync: (source: string, dest: string, upgradeFlag?: boolean) => void;
6
+ export declare const handleReplace: ({ regex, replacement, paths }: any) => void;
7
+ export declare const replaceInFileAll: (array: any, index: number | undefined, callback: any) => Promise<any>;
package/lib/utils.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.replaceInFileAll = exports.handleReplace = exports.copyFileSync = exports.rmdirSync = exports.rmFileSync = exports.mkdirSync = exports.firstUpperCase = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = require("path");
9
+ const replace_1 = __importDefault(require("replace"));
10
+ const replace_in_file_1 = require("replace-in-file");
11
+ const mkdirFlag = true;
12
+ const copyFileFlag = true;
13
+ const replaceFlag = true;
14
+ const replaceInFileFlag = true;
15
+ const rmdirFlag = true;
16
+ const rmfileFlag = true;
17
+ const firstUpperCase = (word) => {
18
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
19
+ };
20
+ exports.firstUpperCase = firstUpperCase;
21
+ const mkdirSync = (dirPath) => {
22
+ if (mkdirFlag) {
23
+ if (!fs_1.default.existsSync(dirPath)) {
24
+ fs_1.default.mkdirSync(dirPath);
25
+ }
26
+ }
27
+ };
28
+ exports.mkdirSync = mkdirSync;
29
+ const rmFileSync = (filePath) => {
30
+ if (rmfileFlag) {
31
+ if (fs_1.default.existsSync(filePath)) {
32
+ fs_1.default.unlinkSync(filePath);
33
+ }
34
+ }
35
+ };
36
+ exports.rmFileSync = rmFileSync;
37
+ const rmdirSync = (dirPath) => {
38
+ if (rmdirFlag) {
39
+ if (fs_1.default.existsSync(dirPath)) {
40
+ const list = fs_1.default.readdirSync(dirPath);
41
+ list.forEach((item) => {
42
+ const resolverPath = (0, path_1.resolve)(`${dirPath}/${item}`);
43
+ const stat = fs_1.default.statSync(resolverPath);
44
+ const isDir = stat.isDirectory();
45
+ const isFile = stat.isFile();
46
+ if (isDir) {
47
+ (0, exports.rmdirSync)(resolverPath);
48
+ }
49
+ else if (isFile) {
50
+ (0, exports.rmFileSync)(resolverPath);
51
+ }
52
+ });
53
+ fs_1.default.rmdirSync(dirPath);
54
+ }
55
+ }
56
+ };
57
+ exports.rmdirSync = rmdirSync;
58
+ const copyFileSync = (source, dest, upgradeFlag = false) => {
59
+ if (copyFileFlag) {
60
+ if (!upgradeFlag) {
61
+ if (!fs_1.default.existsSync(dest) && fs_1.default.existsSync(source)) {
62
+ fs_1.default.copyFileSync(source, dest);
63
+ }
64
+ }
65
+ else {
66
+ if (fs_1.default.existsSync(source)) {
67
+ fs_1.default.copyFileSync(source, dest);
68
+ }
69
+ }
70
+ }
71
+ };
72
+ exports.copyFileSync = copyFileSync;
73
+ const handleReplace = ({ regex, replacement, paths }) => {
74
+ if (replaceFlag) {
75
+ (0, replace_1.default)({
76
+ regex,
77
+ replacement,
78
+ paths,
79
+ recursive: true,
80
+ silent: true
81
+ });
82
+ }
83
+ };
84
+ exports.handleReplace = handleReplace;
85
+ const replaceInFileAll = async (array, index = 0, callback) => {
86
+ if (replaceInFileFlag) {
87
+ console.log('replaceInFileAll', index);
88
+ const arrayLen = array.length;
89
+ if (index < arrayLen) {
90
+ const item = array[index];
91
+ (0, replace_in_file_1.replaceInFile)(item)
92
+ .then((changedFiles) => {
93
+ console.log('Modified files:', changedFiles);
94
+ (0, exports.replaceInFileAll)(array, ++index, callback);
95
+ })
96
+ .catch((error) => {
97
+ if (error) {
98
+ console.error('Error occurred:', error);
99
+ }
100
+ });
101
+ }
102
+ else {
103
+ return callback?.();
104
+ }
105
+ }
106
+ else {
107
+ return callback?.();
108
+ }
109
+ };
110
+ exports.replaceInFileAll = replaceInFileAll;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsgm-cli",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "description": "A CLI tool to run Next/Style-components and Graphql/Mysql fullstack project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,7 +32,6 @@
32
32
  "test": "jest",
33
33
  "test:coverage": "jest --coverage",
34
34
  "test:watch": "jest --watch",
35
- "test:cli": "./test-cli.sh",
36
35
  "performance": "./scripts/performance-check.sh",
37
36
  "size-limit": "npx size-limit"
38
37
  },