@cgzair/cgz-core 1.0.0 → 1.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.
package/lib/index.js CHANGED
@@ -1 +1,17 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};exports.__esModule=!0,__exportStar(require("./terminal"),exports),__exportStar(require("./utils"),exports),__exportStar(require("./package-json"),exports),__exportStar(require("./log"),exports),__exportStar(require("./module-to-cjs"),exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ exports.__esModule = true;
13
+ __exportStar(require("./terminal"), exports);
14
+ __exportStar(require("./utils"), exports);
15
+ __exportStar(require("./package-json"), exports);
16
+ __exportStar(require("./log"), exports);
17
+ __exportStar(require("./module-to-cjs"), exports);
package/lib/log.js CHANGED
@@ -1 +1,53 @@
1
- "use strict";var timer,__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},path_1=(exports.__esModule=!0,exports.log=void 0,__importDefault(require("path"))),chalk_1=__importDefault(require("chalk")),utils_1=require("./utils"),green=chalk_1.default.green,blue=chalk_1.default.blue,yellow=chalk_1.default.yellow,red=chalk_1.default.red,log={success:function(e){clearInterval(timer),console.log(green(e))},info:function(e){clearInterval(timer),console.info(blue(e))},loading:function(e){clearInterval(timer);var l=[".","..","..."],r=0;return timer=setInterval(function(){console.clear(),console.info(blue(""+e+l[r])),3===++r&&(r=0)},1e3)},warn:function(e){clearInterval(timer),console.info(yellow(e))},error:function(e){clearInterval(timer),console.info(red(e))},result:function(e,l,r){clearInterval(timer),console.info([blue((0,utils_1.getCurrentPkg)(path_1.default.resolve(l)).name+" "+e)," ",r?green("🎉 🎉 🎉 🎉 🎉"):red("✖")," "].join("\r\n"))}};exports.log=log;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.log = void 0;
7
+ var path_1 = __importDefault(require("path"));
8
+ var chalk_1 = __importDefault(require("chalk"));
9
+ var utils_1 = require("./utils");
10
+ var green = chalk_1["default"].green, blue = chalk_1["default"].blue, yellow = chalk_1["default"].yellow, red = chalk_1["default"].red;
11
+ var timer;
12
+ var log = {
13
+ success: function (text) {
14
+ clearInterval(timer);
15
+ console.log(green(text));
16
+ },
17
+ info: function (text) {
18
+ clearInterval(timer);
19
+ console.info(blue(text));
20
+ },
21
+ loading: function (text) {
22
+ clearInterval(timer);
23
+ var dot = [".", "..", "..."];
24
+ var dotIndex = 0;
25
+ timer = setInterval(function () {
26
+ console.clear();
27
+ console.info(blue("" + text + dot[dotIndex]));
28
+ dotIndex++;
29
+ if (dotIndex === 3) {
30
+ dotIndex = 0;
31
+ }
32
+ }, 1000);
33
+ return timer;
34
+ },
35
+ warn: function (text) {
36
+ clearInterval(timer);
37
+ console.info(yellow(text));
38
+ },
39
+ error: function (text) {
40
+ clearInterval(timer);
41
+ console.info(red(text));
42
+ },
43
+ result: function (text, root, pass) {
44
+ clearInterval(timer);
45
+ console.info([
46
+ blue((0, utils_1.getCurrentPkg)(path_1["default"].resolve(root)).name + " " + text),
47
+ " ",
48
+ pass ? green("\uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89 \uD83C\uDF89" /* success */) : red("\u2716" /* failure */),
49
+ " ",
50
+ ].join("\r\n"));
51
+ }
52
+ };
53
+ exports.log = log;
@@ -1 +1,49 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},path_1=(exports.__esModule=!0,exports.moduleToCjs=void 0,require("path")),assert_1=__importDefault(require("assert")),execa_1=__importDefault(require("execa")),fs_extra_1=require("fs-extra"),utils_1=require("./utils"),moduleToCjs=function(t){(0,assert_1.default)((0,fs_extra_1.existsSync)(t),"无法访问当前文件路径:"+t);var e=(0,path_1.join)(__dirname,".cjs/"),s=((0,fs_extra_1.rmdirSync)(e,{recursive:!0}),(0,fs_extra_1.mkdirSync)(e),execa_1.default.sync("node",[(0,path_1.resolve)(__dirname,"../node_modules/.bin/tsc"),"--esModuleInterop","--allowJs","--types","node","--module","commonjs","--target","es5","--outDir",e,t]),"");return(0,utils_1.getChildFile)(e).some(function(e){var r=e.indexOf(".cjs"),r=e.substring(r+5,e.length-3);return-1!==t.indexOf(r)&&(s=e,!0)}),require(s)};exports.moduleToCjs=moduleToCjs;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.moduleToCjs = void 0;
7
+ var path_1 = require("path");
8
+ var assert_1 = __importDefault(require("assert"));
9
+ var fs_1 = __importDefault(require("fs"));
10
+ var typescript_1 = __importDefault(require("typescript"));
11
+ var fs_extra_1 = require("fs-extra");
12
+ var utils_1 = require("./utils");
13
+ var log_1 = require("./log");
14
+ var moduleToCjs = function (filePath) {
15
+ (0, assert_1["default"])((0, fs_extra_1.existsSync)(filePath), "\u65E0\u6CD5\u8BBF\u95EE\u5F53\u524D\u6587\u4EF6\u8DEF\u5F84\uFF1A" + filePath);
16
+ var dir = (0, path_1.join)(__dirname, ".cjs/");
17
+ if ((0, fs_extra_1.existsSync)(dir)) {
18
+ (0, fs_extra_1.rmSync)(dir, {
19
+ recursive: true
20
+ });
21
+ }
22
+ (0, fs_extra_1.mkdirSync)(dir);
23
+ var result = "";
24
+ try {
25
+ var content = typescript_1["default"].transpile(fs_1["default"].readFileSync(filePath, "utf8"), {
26
+ target: typescript_1["default"].ScriptTarget.ES5,
27
+ module: typescript_1["default"].ModuleKind.CommonJS,
28
+ esModuleInterop: true,
29
+ allowJs: true,
30
+ types: ["node"],
31
+ lib: ["es5", "dom"]
32
+ });
33
+ fs_1["default"].writeFileSync(dir + "/" + (0, path_1.basename)(filePath).replace(/\.[^.]+$/, ".cjs"), content);
34
+ }
35
+ catch (error) {
36
+ log_1.log.error(error);
37
+ }
38
+ (0, utils_1.getChildFile)(dir).some(function (item) {
39
+ var startIdx = item.indexOf(".cjs");
40
+ var fileName = item.substring(startIdx + 5, item.length - 3);
41
+ if (filePath.indexOf(fileName) !== -1) {
42
+ result = item;
43
+ return true;
44
+ }
45
+ return false;
46
+ });
47
+ return require(result);
48
+ };
49
+ exports.moduleToCjs = moduleToCjs;
@@ -1 +1,54 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},fs_1=(exports.__esModule=!0,exports.setConfig=exports.setScripts=void 0,__importDefault(require("fs"))),path_1=__importDefault(require("path")),setFileData=function(e,t){void 0===t&&(t=path_1.default.resolve(__dirname,"../../../"));t=path_1.default.resolve(t,"package.json");fs_1.default.writeFileSync(t,JSON.stringify(e,null,2)),fs_1.default.writeFileSync(t,"\n",{flag:"a"})},setScripts=function(e,t,s){void 0===s&&(s=path_1.default.resolve(__dirname,"../../../"));var a,i=path_1.default.resolve(s,"package.json"),i=JSON.parse(fs_1.default.readFileSync(i,"utf-8"));i.scripts?i.scripts[e]=t:i.scripts=((a={})[e]=t,a),setFileData(i,s)},setConfig=(exports.setScripts=setScripts,function(e,t,s){void 0===s&&(s=path_1.default.resolve(__dirname,"../../../"));var a=path_1.default.resolve(s,"package.json"),a=JSON.parse(fs_1.default.readFileSync(a,"utf-8"));a[e]=t,setFileData(a,s)});exports.setConfig=setConfig;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.setConfig = exports.setScripts = void 0;
7
+ var fs_1 = __importDefault(require("fs"));
8
+ var path_1 = __importDefault(require("path"));
9
+ /**
10
+ * 以 2 个空格缩进将内容写入 package.json
11
+ * @param {string} cont
12
+ * @param {string} root
13
+ */
14
+ var setFileData = function (cont, root) {
15
+ if (root === void 0) { root = path_1["default"].resolve(__dirname, "../../../"); }
16
+ var rootPackageJson = path_1["default"].resolve(root, "package.json");
17
+ fs_1["default"].writeFileSync(rootPackageJson, JSON.stringify(cont, null, 2));
18
+ fs_1["default"].writeFileSync(rootPackageJson, "\n", {
19
+ flag: "a"
20
+ });
21
+ };
22
+ /**
23
+ * 写入 scripts 命令到 package.json
24
+ * @param {string} key
25
+ * @param {string} value
26
+ * @param {string} root
27
+ */
28
+ var setScripts = function (key, value, root) {
29
+ var _a;
30
+ if (root === void 0) { root = path_1["default"].resolve(__dirname, "../../../"); }
31
+ var rootPackageJson = path_1["default"].resolve(root, "package.json");
32
+ var content = JSON.parse(fs_1["default"].readFileSync(rootPackageJson, "utf-8"));
33
+ content.scripts
34
+ ? (content.scripts[key] = value)
35
+ : (content.scripts = (_a = {},
36
+ _a[key] = value,
37
+ _a));
38
+ setFileData(content, root);
39
+ };
40
+ exports.setScripts = setScripts;
41
+ /**
42
+ * 写入自定义配置到 package.json
43
+ * @param {string} key
44
+ * @param {string | Record<string, any>} value
45
+ * @param {string} root
46
+ */
47
+ var setConfig = function (key, value, root) {
48
+ if (root === void 0) { root = path_1["default"].resolve(__dirname, "../../../"); }
49
+ var rootPackageJson = path_1["default"].resolve(root, "package.json");
50
+ var content = JSON.parse(fs_1["default"].readFileSync(rootPackageJson, "utf-8"));
51
+ content[key] = value;
52
+ setFileData(content, root);
53
+ };
54
+ exports.setConfig = setConfig;
package/lib/terminal.js CHANGED
@@ -1 +1,39 @@
1
- "use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(s){for(var n,o=1,e=arguments.length;o<e;o++)for(var r in n=arguments[o])Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r]);return s}).apply(this,arguments)},child_process_1=(exports.__esModule=!0,exports.spawnCommand=void 0,require("child_process")),spawnCommand=function(t,i,p){return void 0===i&&(i=[]),new Promise(function(s){var n=(0,child_process_1.spawn)(t,i,__assign({stdio:"inherit"},p)),o=n.stdin,e=n.stdout,r=n.stderr;process.stdin.setRawMode(!0),o&&e&&r&&(process.stdin.pipe(o),e.pipe(process.stdout),r.pipe(process.stderr)),n.on("close",function(){s("ok")})})};exports.spawnCommand=spawnCommand;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ exports.__esModule = true;
14
+ exports.spawnCommand = void 0;
15
+ var child_process_1 = require("child_process");
16
+ /**
17
+ *
18
+ * @param {string} command
19
+ * @param {string[]} args
20
+ * @param {SpawnOptions} options
21
+ * @returns {Promise<unknown>}
22
+ */
23
+ var spawnCommand = function (command, args, options) {
24
+ if (args === void 0) { args = []; }
25
+ return new Promise(function (resolve) {
26
+ var childProcess = (0, child_process_1.spawn)(command, args, __assign({ stdio: "inherit" }, options));
27
+ var stdin = childProcess.stdin, stdout = childProcess.stdout, stderr = childProcess.stderr;
28
+ process.stdin.setRawMode(true);
29
+ if (stdin && stdout && stderr) {
30
+ process.stdin.pipe(stdin);
31
+ stdout.pipe(process.stdout);
32
+ stderr.pipe(process.stderr);
33
+ }
34
+ childProcess.on("close", function () {
35
+ resolve("ok");
36
+ });
37
+ });
38
+ };
39
+ exports.spawnCommand = spawnCommand;
package/lib/utils.js CHANGED
@@ -1 +1,116 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},fs_1=(exports.__esModule=!0,exports.getChildFile=exports.getUserHomeDir=exports.getCurrentPkg=exports.getRootPath=exports.isAccessSync=exports.getEscapePath=exports.getExecutableSuffix=void 0,__importDefault(require("fs"))),os_1=__importDefault(require("os")),path_1=__importDefault(require("path")),global_dirs_1=__importDefault(require("global-dirs")),getExecutableSuffix=function(e){return"win32"===e?".cmd":""},getEscapePath=(exports.getExecutableSuffix=getExecutableSuffix,function(e,t){return"win32"===e?t.replace(/\\/g,"\\\\"):t}),isAccessSync=(exports.getEscapePath=getEscapePath,function(e,t){try{return fs_1.default.accessSync(e,t),!0}catch(e){return!1}}),getRootPath=(exports.isAccessSync=isAccessSync,function(e,t,r){return"win32"===e?path_1.default.join(t,"..",".."):path_1.default.join(global_dirs_1.default.npm.packages,r)}),getCurrentPkg=(exports.getRootPath=getRootPath,function(e){return void 0===e&&(e=process.cwd()),JSON.parse(fs_1.default.readFileSync(path_1.default.join(e,"./package.json"),"utf8"))}),getUserHomeDir=(exports.getCurrentPkg=getCurrentPkg,function(){var e,t,r;return"function"==typeof os_1.default.homedir?os_1.default.homedir():(e=process.env,t=e.HOME,r=e.LOGNAME||e.USER||e.LNAME||e.USERNAME,"win32"===process.platform?e.USERPROFILE||""+e.HOMEDRIVE+e.HOMEPATH||t||"":"darwin"===process.platform?t||(r?"/Users/"+r:""):"linux"===process.platform?t||(0===process.getuid()?"/root":r?"/home/"+r:""):t||"")}),getChildFile=(exports.getUserHomeDir=getUserHomeDir,function(t){var r=[];return fs_1.default.readdirSync(t).forEach(function(e){fs_1.default.statSync(path_1.default.join(t,e)).isDirectory()?r=r.concat(getChildFile(path_1.default.join(t,e))):r.push(path_1.default.join(t,e))}),r});exports.getChildFile=getChildFile;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.getChildFile = exports.getUserHomeDir = exports.getCurrentPkg = exports.getRootPath = exports.isAccessSync = exports.getEscapePath = exports.getExecutableSuffix = void 0;
7
+ var fs_1 = __importDefault(require("fs"));
8
+ var os_1 = __importDefault(require("os"));
9
+ var path_1 = __importDefault(require("path"));
10
+ var global_dirs_1 = __importDefault(require("global-dirs"));
11
+ /**
12
+ * 根据平台不同返回执行后缀
13
+ * @param {string} platform
14
+ * @returns {string}
15
+ */
16
+ var getExecutableSuffix = function (platform) {
17
+ if (platform === "win32") {
18
+ return ".cmd";
19
+ }
20
+ return "";
21
+ };
22
+ exports.getExecutableSuffix = getExecutableSuffix;
23
+ /**
24
+ * 根据不同平台转义路径
25
+ * @param {string} platform
26
+ * @param {string} url
27
+ * @returns {string}
28
+ */
29
+ var getEscapePath = function (platform, url) {
30
+ if (platform === "win32") {
31
+ return url.replace(/\\/g, "\\\\");
32
+ }
33
+ return url;
34
+ };
35
+ exports.getEscapePath = getEscapePath;
36
+ /**
37
+ * 文件是否存在
38
+ * @param {PathLike} url
39
+ * @param {number} mode
40
+ * @returns {boolean}
41
+ */
42
+ var isAccessSync = function (url, mode) {
43
+ try {
44
+ fs_1["default"].accessSync(url, mode);
45
+ return true;
46
+ }
47
+ catch (error) {
48
+ return false;
49
+ }
50
+ };
51
+ exports.isAccessSync = isAccessSync;
52
+ /**
53
+ * 返回当前项目安装路径
54
+ * @param {string} platform
55
+ * @param {string} url
56
+ * @param {string} name
57
+ * @returns {string}
58
+ */
59
+ var getRootPath = function (platform, url, name) {
60
+ if (platform === "win32") {
61
+ return path_1["default"].join(url, "..", "..");
62
+ }
63
+ return path_1["default"].join(global_dirs_1["default"].npm.packages, name);
64
+ };
65
+ exports.getRootPath = getRootPath;
66
+ /**
67
+ * 返回当前项目 package.json 信息
68
+ * @param {string} [dir="./package.json"]
69
+ * @returns {PKG}
70
+ */
71
+ var getCurrentPkg = function (dir) {
72
+ if (dir === void 0) { dir = process.cwd(); }
73
+ return JSON.parse(fs_1["default"].readFileSync(path_1["default"].join(dir, "./package.json"), "utf8"));
74
+ };
75
+ exports.getCurrentPkg = getCurrentPkg;
76
+ /**
77
+ * 获取用户目录
78
+ * @returns {string}
79
+ */
80
+ var getUserHomeDir = function () {
81
+ var homedir = function () {
82
+ var env = process.env;
83
+ var home = env.HOME;
84
+ var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME;
85
+ if (process.platform === "win32") {
86
+ return env.USERPROFILE || "" + env.HOMEDRIVE + env.HOMEPATH || home || "";
87
+ }
88
+ if (process.platform === "darwin") {
89
+ return home || (user ? "/Users/" + user : "");
90
+ }
91
+ if (process.platform === "linux") {
92
+ return home || (process.getuid() === 0 ? "/root" : user ? "/home/" + user : "");
93
+ }
94
+ return home || "";
95
+ };
96
+ return typeof os_1["default"].homedir === "function" ? os_1["default"].homedir() : homedir();
97
+ };
98
+ exports.getUserHomeDir = getUserHomeDir;
99
+ /**
100
+ * 获取目录下级所有文件
101
+ * @param {string} root
102
+ * @returns {string[]}
103
+ */
104
+ var getChildFile = function (root) {
105
+ var result = [];
106
+ fs_1["default"].readdirSync(root).forEach(function (item) {
107
+ if (fs_1["default"].statSync(path_1["default"].join(root, item)).isDirectory()) {
108
+ result = result.concat(getChildFile(path_1["default"].join(root, item)));
109
+ }
110
+ else {
111
+ result.push(path_1["default"].join(root, item));
112
+ }
113
+ });
114
+ return result;
115
+ };
116
+ exports.getChildFile = getChildFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cgzair/cgz-core",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Core tool library.",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
@@ -10,7 +10,6 @@
10
10
  "build": "tsc"
11
11
  },
12
12
  "files": [
13
- "assets",
14
13
  "lib",
15
14
  "package.json",
16
15
  "README.md",
@@ -34,5 +33,5 @@
34
33
  "access": "public"
35
34
  },
36
35
  "license": "MIT",
37
- "gitHead": "ac4f859f68745c4250c8aab06047ce03b0de733e"
36
+ "gitHead": "ded6ffbaa1fd7da5cca106fcf1addd7c6bf8b930"
38
37
  }
package/tsconfig.json CHANGED
@@ -9,5 +9,5 @@
9
9
  "declaration": false,
10
10
  "strictNullChecks": true
11
11
  },
12
- "include": ["src", "../cgz-deploy/__tests__/__fixtures__/config/typings.d.ts"]
12
+ "include": ["src"]
13
13
  }
Binary file
package/assets/font.ttf DELETED
Binary file