jiek 0.2.0-alpha.1 → 0.2.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { program } from 'commander';
4
+ import { load } from 'js-yaml';
5
+ import { getWD } from './getWD.esm.js';
6
+
7
+ function packageIsExist(name) {
8
+ try {
9
+ require.resolve(name);
10
+ return true;
11
+ } catch (e) {
12
+ console.log(e);
13
+ return false;
14
+ }
15
+ }
16
+ let tsRegisterName;
17
+ const registers = [
18
+ process.env.JIEK_TS_REGISTER,
19
+ "esbuild-register"
20
+ ].filter(Boolean);
21
+ for (const register of registers) {
22
+ if (packageIsExist(register)) {
23
+ tsRegisterName = register;
24
+ break;
25
+ }
26
+ }
27
+ let configName = "jiek.config";
28
+ function getConfigPath(root) {
29
+ const isSupportTsLoader = !!tsRegisterName;
30
+ function configWithExtIsExist(ext) {
31
+ const filenames = [
32
+ path.resolve(root, `${configName}.${ext}`),
33
+ path.resolve(root, `.${configName}.${ext}`)
34
+ ];
35
+ for (const filename of filenames) {
36
+ if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
37
+ return filename;
38
+ }
39
+ }
40
+ return;
41
+ }
42
+ configName = configWithExtIsExist("js") ?? configName;
43
+ configName = configWithExtIsExist("json") ?? configName;
44
+ configName = configWithExtIsExist("yaml") ?? configName;
45
+ if (isSupportTsLoader) {
46
+ configName = configWithExtIsExist("ts") ?? configName;
47
+ }
48
+ return path.resolve(root, configName);
49
+ }
50
+ function loadConfig() {
51
+ const { wd: root, notWorkspace } = getWD();
52
+ if (notWorkspace)
53
+ throw new Error("not in workspace");
54
+ let configPath = program.getOptionValue("configPath");
55
+ if (!configPath) {
56
+ configPath = getConfigPath(root);
57
+ } else {
58
+ if (!fs.existsSync(configPath))
59
+ throw new Error(`config file not found: ${configPath}`);
60
+ if (!path.isAbsolute(configPath))
61
+ configPath = path.resolve(root, configPath);
62
+ }
63
+ const ext = path.extname(configPath);
64
+ let module;
65
+ switch (ext) {
66
+ case ".js":
67
+ module = require(configPath);
68
+ break;
69
+ case ".json":
70
+ return require(configPath);
71
+ case ".yaml":
72
+ return load(fs.readFileSync(configPath, "utf-8"));
73
+ case ".ts":
74
+ if (tsRegisterName) {
75
+ require(tsRegisterName);
76
+ module = require(configPath);
77
+ break;
78
+ }
79
+ throw new Error(
80
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
81
+ );
82
+ default:
83
+ throw new Error(`unsupported config file type: ${ext}`);
84
+ }
85
+ if (!module)
86
+ throw new Error("config file is empty");
87
+ return module.default ?? module;
88
+ }
89
+
90
+ export { loadConfig };
91
+ //# sourceMappingURL=loadConfig.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadConfig.esm.js","sources":["../../src/utils/loadConfig.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getWD } from './getWD'\n\nfunction packageIsExist(name: string) {\n try {\n require.resolve(name)\n return true\n } catch (e) {\n console.log(e)\n return false\n }\n}\n\nlet tsRegisterName: string | undefined\nconst registers = [\n process.env.JIEK_TS_REGISTER,\n 'esbuild-register'\n].filter(Boolean) as string[]\nfor (const register of registers) {\n if (packageIsExist(register)) {\n tsRegisterName = register\n break\n }\n}\n\nlet configName = 'jiek.config'\n\nfunction getConfigPath(root: string) {\n const isSupportTsLoader = !!tsRegisterName\n function configWithExtIsExist(ext: string) {\n const filenames = [\n path.resolve(root, `${configName}.${ext}`),\n path.resolve(root, `.${configName}.${ext}`)\n ]\n for (const filename of filenames) {\n if (\n fs.existsSync(filename) &&\n fs.lstatSync(filename)\n .isFile()\n ) {\n return filename\n }\n }\n return\n }\n configName = configWithExtIsExist('js') ?? configName\n configName = configWithExtIsExist('json') ?? configName\n configName = configWithExtIsExist('yaml') ?? configName\n if (isSupportTsLoader) {\n configName = configWithExtIsExist('ts') ?? configName\n }\n return path.resolve(root, configName)\n}\n\nexport function loadConfig() {\n const { wd: root, notWorkspace } = getWD()\n if (notWorkspace)\n throw new Error('not in workspace')\n\n let configPath = program.getOptionValue('configPath')\n\n if (!configPath) {\n configPath = getConfigPath(root)\n } else {\n if (!fs.existsSync(configPath))\n throw new Error(`config file not found: ${configPath}`)\n if (!path.isAbsolute(configPath))\n configPath = path.resolve(root, configPath)\n }\n const ext = path.extname(configPath)\n\n let module: any\n switch (ext) {\n case '.js':\n module = require(configPath)\n break\n case '.json':\n return require(configPath)\n case '.yaml':\n return load(fs.readFileSync(configPath, 'utf-8'))\n case '.ts':\n if (tsRegisterName) {\n require(tsRegisterName)\n module = require(configPath)\n break\n }\n throw new Error(\n 'ts config file is not supported without ts register, ' +\n 'please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register'\n )\n default:\n throw new Error(`unsupported config file type: ${ext}`)\n }\n if (!module) throw new Error('config file is empty')\n\n return module.default ?? module\n}\n"],"names":[],"mappings":";;;;;;AAQA,SAAS,eAAe,IAAc,EAAA;AACpC,EAAI,IAAA;AACF,IAAA,OAAA,CAAQ,QAAQ,IAAI,CAAA,CAAA;AACpB,IAAO,OAAA,IAAA,CAAA;AAAA,WACA,CAAG,EAAA;AACV,IAAA,OAAA,CAAQ,IAAI,CAAC,CAAA,CAAA;AACb,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA;AAEA,IAAI,cAAA,CAAA;AACJ,MAAM,SAAY,GAAA;AAAA,EAChB,QAAQ,GAAI,CAAA,gBAAA;AAAA,EACZ,kBAAA;AACF,CAAA,CAAE,OAAO,OAAO,CAAA,CAAA;AAChB,KAAA,MAAW,YAAY,SAAW,EAAA;AAChC,EAAI,IAAA,cAAA,CAAe,QAAQ,CAAG,EAAA;AAC5B,IAAiB,cAAA,GAAA,QAAA,CAAA;AACjB,IAAA,MAAA;AAAA,GACF;AACF,CAAA;AAEA,IAAI,UAAa,GAAA,aAAA,CAAA;AAEjB,SAAS,cAAc,IAAc,EAAA;AACn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,EAAA,OAAO,OAAO,OAAW,IAAA,MAAA,CAAA;AAC3B;;;;"}
@@ -0,0 +1,2 @@
1
+ import e from"node:fs";import r from"node:path";import{program as o}from"commander";import{load as t}from"js-yaml";import{getWD as s}from"./getWD.esm.min.js";function n(e){try{return require.resolve(e),!0}catch(e){return console.log(e),!1}}let i;const f=[process.env.JIEK_TS_REGISTER,"esbuild-register"].filter(Boolean);for(const e of f)if(n(e)){i=e;break}let c="jiek.config";function l(){const{wd:n,notWorkspace:f}=s();if(f)throw new Error("not in workspace");let l=o.getOptionValue("configPath");if(l){if(!e.existsSync(l))throw new Error(`config file not found: ${l}`);r.isAbsolute(l)||(l=r.resolve(n,l))}else l=function(o){const t=!!i;function s(t){const s=[r.resolve(o,`${c}.${t}`),r.resolve(o,`.${c}.${t}`)];for(const r of s)if(e.existsSync(r)&&e.lstatSync(r).isFile())return r}return c=s("js")??c,c=s("json")??c,c=s("yaml")??c,t&&(c=s("ts")??c),r.resolve(o,c)}(n);const u=r.extname(l);let a;switch(u){case".js":a=require(l);break;case".json":return require(l);case".yaml":return t(e.readFileSync(l,"utf-8"));case".ts":if(i){require(i),a=require(l);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");default:throw new Error(`unsupported config file type: ${u}`)}if(!a)throw new Error("config file is empty");return a.default??a}export{l as loadConfig};
2
+ //# sourceMappingURL=loadConfig.esm.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadConfig.esm.min.js","sources":["../../src/utils/loadConfig.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getWD } from './getWD'\n\nfunction packageIsExist(name: string) {\n try {\n require.resolve(name)\n return true\n } catch (e) {\n console.log(e)\n return false\n }\n}\n\nlet tsRegisterName: string | undefined\nconst registers = [\n process.env.JIEK_TS_REGISTER,\n 'esbuild-register'\n].filter(Boolean) as string[]\nfor (const register of registers) {\n if (packageIsExist(register)) {\n tsRegisterName = register\n break\n }\n}\n\nlet configName = 'jiek.config'\n\nfunction getConfigPath(root: string) {\n const isSupportTsLoader = !!tsRegisterName\n function configWithExtIsExist(ext: string) {\n const filenames = [\n path.resolve(root, `${configName}.${ext}`),\n path.resolve(root, `.${configName}.${ext}`)\n ]\n for (const filename of filenames) {\n if (\n fs.existsSync(filename) &&\n fs.lstatSync(filename)\n .isFile()\n ) {\n return filename\n }\n }\n return\n }\n configName = configWithExtIsExist('js') ?? configName\n configName = configWithExtIsExist('json') ?? configName\n configName = configWithExtIsExist('yaml') ?? configName\n if (isSupportTsLoader) {\n configName = configWithExtIsExist('ts') ?? configName\n }\n return path.resolve(root, configName)\n}\n\nexport function loadConfig() {\n const { wd: root, notWorkspace } = getWD()\n if (notWorkspace)\n throw new Error('not in workspace')\n\n let configPath = program.getOptionValue('configPath')\n\n if (!configPath) {\n configPath = getConfigPath(root)\n } else {\n if (!fs.existsSync(configPath))\n throw new Error(`config file not found: ${configPath}`)\n if (!path.isAbsolute(configPath))\n configPath = path.resolve(root, configPath)\n }\n const ext = path.extname(configPath)\n\n let module: any\n switch (ext) {\n case '.js':\n module = require(configPath)\n break\n case '.json':\n return require(configPath)\n case '.yaml':\n return load(fs.readFileSync(configPath, 'utf-8'))\n case '.ts':\n if (tsRegisterName) {\n require(tsRegisterName)\n module = require(configPath)\n break\n }\n throw new Error(\n 'ts config file is not supported without ts register, ' +\n 'please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register'\n )\n default:\n throw new Error(`unsupported config file type: ${ext}`)\n }\n if (!module) throw new Error('config file is empty')\n\n return module.default ?? module\n}\n"],"names":["packageIsExist","name","require","resolve","e","console","log","tsRegisterName","registers","process","env","JIEK_TS_REGISTER","filter","Boolean","register","configName","loadConfig","wd","root","notWorkspace","getWD","Error","configPath","program","getOptionValue","fs","existsSync","path","isAbsolute","isSupportTsLoader","configWithExtIsExist","ext","filenames","filename","lstatSync","isFile","getConfigPath","extname","module","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MACH,GAAIf,EAAgB,CAClBL,QAAQK,GACR+B,EAASpC,QAAQoB,GACjB,KACF,CACA,MAAM,IAAID,MACR,2IAGJ,QACE,MAAM,IAAIA,MAAM,iCAAiCU,KAErD,IAAKO,EAAc,MAAA,IAAIjB,MAAM,wBAE7B,OAAOiB,EAAOG,SAAWH,CAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jiek",
3
- "version": "0.2.0-alpha.1",
3
+ "version": "0.2.1-alpha.1",
4
4
  "description": "YiJie's personal kits.",
5
5
  "bin": {
6
6
  "jiek": "bin/jiek.js",
@@ -30,6 +30,8 @@
30
30
  "autoprefixer": "^10.4.16",
31
31
  "commander": "^12.0.0",
32
32
  "detect-indent": "^6.1.0",
33
+ "inquirer": "^8.2.6",
34
+ "micromatch": "^4.0.5",
33
35
  "js-yaml": "^4.1.0",
34
36
  "jsonc-parser": "^3.2.1",
35
37
  "rollup": "^4.1.5",
@@ -41,13 +43,16 @@
41
43
  "@jiek/utils": "0.1.6"
42
44
  },
43
45
  "optionalDependencies": {
44
- "@pnpm/filter-workspace-packages": "^7.2.13"
46
+ "@pnpm/filter-workspace-packages": "^7.2.13",
47
+ "esbuild-register": "^3.5.0"
45
48
  },
46
49
  "devDependencies": {
47
50
  "@npm/types": "^1.0.2",
48
51
  "@pnpm/filter-workspace-packages": "^7.2.13",
49
52
  "@pnpm/workspace.pkgs-graph": "^2.0.15",
50
53
  "@types/js-yaml": "^4.0.9",
54
+ "@types/inquirer": "^9.0.7",
55
+ "@types/micromatch": "^4.0.6",
51
56
  "esbuild-register": "^3.5.0"
52
57
  },
53
58
  "scripts": {