@tikkhun/index-generator 0.0.5 → 0.1.0

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/dist/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';var cliCore=require('@tikkhun/cli-core'),utilsCore=require('@tikkhun/utils-core'),x=require('fs/promises'),glob=require('glob'),c=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var x__default=/*#__PURE__*/_interopDefault(x);var c__default=/*#__PURE__*/_interopDefault(c);/**
2
+ 'use strict';var cliCore=require('@tikkhun/cli-core'),utilsCore=require('@tikkhun/utils-core'),fs=require('fs'),promises=require('fs/promises'),glob=require('glob'),o=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var o__default=/*#__PURE__*/_interopDefault(o);/**
3
3
  @tikkhun/index-generator
4
4
  */
5
- var h=Object.defineProperty;var f=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var g=(n,e,t)=>e in n?h(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t,y=(n,e)=>{for(var t in e||(e={}))v.call(e,t)&&g(n,t,e[t]);if(f)for(var t of f(e))O.call(e,t)&&g(n,t,e[t]);return n};var o=(n,e,t)=>new Promise((u,r)=>{var d=i=>{try{p(t.next(i));}catch(l){r(l);}},s=i=>{try{p(t.throw(i));}catch(l){r(l);}},p=i=>i.done?u(i.value):Promise.resolve(i.value).then(d,s);p((t=t.apply(n,e)).next());});var a={name:"@tikkhun/index-generator",version:"0.0.3",description:""};var m={cwd:".",indexName:"index.ts",include:"*",exclude:[]};function k(n){return o(this,null,function*(){try{let e=utilsCore.mergeOptions(m,n),t=c__default.default.resolve(e.cwd),r=(yield glob.glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${c__default.default.extname(s)?c__default.default.basename(s).split(c__default.default.extname(s))[0]:s}";`).join(`
6
- `);console.log(r);let d=(e==null?void 0:e.indexName)||"index.ts";if(yield C(d)){console.error("index.ts \u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA");return}yield x__default.default.writeFile(d,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function C(n){return o(this,null,function*(){try{return yield x__default.default.access(n,x__default.default.constants.F_OK),!0}catch(e){return false}})}var F=y({},m),N={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664"},T={cwd:"string",indexName:"string",include:"array",exclude:"array"},E={name:a.name,version:a.version,description:a.description,types:[cliCore.CommandTypes.args,cliCore.CommandTypes.prompts],defaultOptions:F,optionTitles:N,optionTypes:T,action:n=>o(null,null,function*(){k(n);})},w=new cliCore.Cli(E);w.start();
5
+ var O=Object.defineProperty,j=Object.defineProperties;var v=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var b=(i,e,t)=>e in i?O(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t,p=(i,e)=>{for(var t in e||(e={}))I.call(e,t)&&b(i,t,e[t]);if(y)for(var t of y(e))G.call(e,t)&&b(i,t,e[t]);return i},x=(i,e)=>j(i,v(e));var d=(i,e,t)=>new Promise((g,r)=>{var c=n=>{try{a(t.next(n));}catch(l){r(l);}},s=n=>{try{a(t.throw(n));}catch(l){r(l);}},a=n=>n.done?g(n.value):Promise.resolve(n.value).then(c,s);a((t=t.apply(i,e)).next());});var u={name:"@tikkhun/index-generator",version:"0.1.0",description:""};var m={cwd:".",indexName:"index.ts",include:["*"],exclude:[],clean:false,child:false,debug:false};function f(i){return d(this,null,function*(){try{let e=utilsCore.mergeOptions(m,i);e.debug&&console.log("opts",e);let t=o__default.default.resolve(e.cwd);if(e.child){let a=(yield glob.glob("**/*",{cwd:t,ignore:e.exclude})).filter(n=>fs.statSync(o__default.default.join(t,n)).isDirectory());for(let n of a)console.log("\u5BF9\u76EE\u5F55\u8FDB\u884Cindex\u751F\u6210",n),yield f(x(p({},e),{cwd:o__default.default.join(t,n),child:!1}));return}let r=(yield glob.glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${o__default.default.extname(s)?o__default.default.basename(s).split(o__default.default.extname(s))[0]:s}";`).join(`
6
+ `);console.log(r);let c=o__default.default.join(t,e.indexName);if(!(e!=null&&e.clean)&&(yield E(c))){console.error(`index\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA,\u6587\u4EF6\u540D\u4E3A${c}`);return}yield promises.writeFile(c,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function E(i){return d(this,null,function*(){try{return yield promises.access(i,promises.constants.F_OK),!0}catch(e){return false}})}var q=x(p({},m),{child:false}),J={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664",clean:"\u6E05\u9664\u65E7\u7684",child:"\u5B50\u76EE\u5F55"},K={cwd:"string",indexName:"string",include:"array",exclude:"array",clean:"boolean",child:"boolean"},P={name:u.name,version:u.version,description:u.description,types:[cliCore.CommandTypes.args,cliCore.CommandTypes.prompts],defaultOptions:q,optionTitles:J,optionTypes:K,action:i=>d(null,null,function*(){f(i);})},k=new cliCore.Cli(P);k.start();
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import {CommandTypes,Cli}from'@tikkhun/cli-core';import {mergeOptions}from'@tikkhun/utils-core';import x from'fs/promises';import {glob}from'glob';import c from'path';/**
2
+ import {CommandTypes,Cli}from'@tikkhun/cli-core';import {mergeOptions}from'@tikkhun/utils-core';import {statSync}from'fs';import {writeFile,access,constants}from'fs/promises';import {glob}from'glob';import o from'path';/**
3
3
  @tikkhun/index-generator
4
4
  */
5
- var h=Object.defineProperty;var f=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var g=(n,e,t)=>e in n?h(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t,y=(n,e)=>{for(var t in e||(e={}))v.call(e,t)&&g(n,t,e[t]);if(f)for(var t of f(e))O.call(e,t)&&g(n,t,e[t]);return n};var o=(n,e,t)=>new Promise((u,r)=>{var d=i=>{try{p(t.next(i));}catch(l){r(l);}},s=i=>{try{p(t.throw(i));}catch(l){r(l);}},p=i=>i.done?u(i.value):Promise.resolve(i.value).then(d,s);p((t=t.apply(n,e)).next());});var a={name:"@tikkhun/index-generator",version:"0.0.3",description:""};var m={cwd:".",indexName:"index.ts",include:"*",exclude:[]};function k(n){return o(this,null,function*(){try{let e=mergeOptions(m,n),t=c.resolve(e.cwd),r=(yield glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${c.extname(s)?c.basename(s).split(c.extname(s))[0]:s}";`).join(`
6
- `);console.log(r);let d=(e==null?void 0:e.indexName)||"index.ts";if(yield C(d)){console.error("index.ts \u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA");return}yield x.writeFile(d,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function C(n){return o(this,null,function*(){try{return yield x.access(n,x.constants.F_OK),!0}catch(e){return false}})}var F=y({},m),N={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664"},T={cwd:"string",indexName:"string",include:"array",exclude:"array"},E={name:a.name,version:a.version,description:a.description,types:[CommandTypes.args,CommandTypes.prompts],defaultOptions:F,optionTitles:N,optionTypes:T,action:n=>o(null,null,function*(){k(n);})},w=new Cli(E);w.start();
5
+ var O=Object.defineProperty,j=Object.defineProperties;var v=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var b=(i,e,t)=>e in i?O(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t,p=(i,e)=>{for(var t in e||(e={}))I.call(e,t)&&b(i,t,e[t]);if(y)for(var t of y(e))G.call(e,t)&&b(i,t,e[t]);return i},x=(i,e)=>j(i,v(e));var d=(i,e,t)=>new Promise((g,r)=>{var c=n=>{try{a(t.next(n));}catch(l){r(l);}},s=n=>{try{a(t.throw(n));}catch(l){r(l);}},a=n=>n.done?g(n.value):Promise.resolve(n.value).then(c,s);a((t=t.apply(i,e)).next());});var u={name:"@tikkhun/index-generator",version:"0.1.0",description:""};var m={cwd:".",indexName:"index.ts",include:["*"],exclude:[],clean:false,child:false,debug:false};function f(i){return d(this,null,function*(){try{let e=mergeOptions(m,i);e.debug&&console.log("opts",e);let t=o.resolve(e.cwd);if(e.child){let a=(yield glob("**/*",{cwd:t,ignore:e.exclude})).filter(n=>statSync(o.join(t,n)).isDirectory());for(let n of a)console.log("\u5BF9\u76EE\u5F55\u8FDB\u884Cindex\u751F\u6210",n),yield f(x(p({},e),{cwd:o.join(t,n),child:!1}));return}let r=(yield glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${o.extname(s)?o.basename(s).split(o.extname(s))[0]:s}";`).join(`
6
+ `);console.log(r);let c=o.join(t,e.indexName);if(!(e!=null&&e.clean)&&(yield E(c))){console.error(`index\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA,\u6587\u4EF6\u540D\u4E3A${c}`);return}yield writeFile(c,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function E(i){return d(this,null,function*(){try{return yield access(i,constants.F_OK),!0}catch(e){return false}})}var q=x(p({},m),{child:false}),J={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664",clean:"\u6E05\u9664\u65E7\u7684",child:"\u5B50\u76EE\u5F55"},K={cwd:"string",indexName:"string",include:"array",exclude:"array",clean:"boolean",child:"boolean"},P={name:u.name,version:u.version,description:u.description,types:[CommandTypes.args,CommandTypes.prompts],defaultOptions:q,optionTitles:J,optionTypes:K,action:i=>d(null,null,function*(){f(i);})},k=new Cli(P);k.start();
@@ -2,22 +2,29 @@ import * as _tikkhun_cli_core from '@tikkhun/cli-core';
2
2
  import { CommandTypes } from '@tikkhun/cli-core';
3
3
 
4
4
  declare const defaultOptions: {
5
+ child: boolean;
5
6
  cwd: string;
6
7
  indexName: string;
7
- include: string;
8
+ include: string[];
8
9
  exclude: never[];
10
+ clean: boolean;
11
+ debug: boolean;
9
12
  };
10
13
  declare const optionTitles: {
11
14
  cwd: string;
12
15
  indexName: string;
13
16
  include: string;
14
17
  exclude: string;
18
+ clean: string;
19
+ child: string;
15
20
  };
16
21
  declare const optionTypes: {
17
22
  cwd: string;
18
23
  indexName: string;
19
24
  include: string;
20
25
  exclude: string;
26
+ clean: string;
27
+ child: string;
21
28
  };
22
29
  declare const cliOptions: {
23
30
  name: string;
@@ -25,22 +32,29 @@ declare const cliOptions: {
25
32
  description: string;
26
33
  types: CommandTypes[];
27
34
  defaultOptions: {
35
+ child: boolean;
28
36
  cwd: string;
29
37
  indexName: string;
30
- include: string;
38
+ include: string[];
31
39
  exclude: never[];
40
+ clean: boolean;
41
+ debug: boolean;
32
42
  };
33
43
  optionTitles: {
34
44
  cwd: string;
35
45
  indexName: string;
36
46
  include: string;
37
47
  exclude: string;
48
+ clean: string;
49
+ child: string;
38
50
  };
39
51
  optionTypes: {
40
52
  cwd: string;
41
53
  indexName: string;
42
54
  include: string;
43
55
  exclude: string;
56
+ clean: string;
57
+ child: string;
44
58
  };
45
59
  action: (options: any) => Promise<void>;
46
60
  };
@@ -2,22 +2,29 @@ import * as _tikkhun_cli_core from '@tikkhun/cli-core';
2
2
  import { CommandTypes } from '@tikkhun/cli-core';
3
3
 
4
4
  declare const defaultOptions: {
5
+ child: boolean;
5
6
  cwd: string;
6
7
  indexName: string;
7
- include: string;
8
+ include: string[];
8
9
  exclude: never[];
10
+ clean: boolean;
11
+ debug: boolean;
9
12
  };
10
13
  declare const optionTitles: {
11
14
  cwd: string;
12
15
  indexName: string;
13
16
  include: string;
14
17
  exclude: string;
18
+ clean: string;
19
+ child: string;
15
20
  };
16
21
  declare const optionTypes: {
17
22
  cwd: string;
18
23
  indexName: string;
19
24
  include: string;
20
25
  exclude: string;
26
+ clean: string;
27
+ child: string;
21
28
  };
22
29
  declare const cliOptions: {
23
30
  name: string;
@@ -25,22 +32,29 @@ declare const cliOptions: {
25
32
  description: string;
26
33
  types: CommandTypes[];
27
34
  defaultOptions: {
35
+ child: boolean;
28
36
  cwd: string;
29
37
  indexName: string;
30
- include: string;
38
+ include: string[];
31
39
  exclude: never[];
40
+ clean: boolean;
41
+ debug: boolean;
32
42
  };
33
43
  optionTitles: {
34
44
  cwd: string;
35
45
  indexName: string;
36
46
  include: string;
37
47
  exclude: string;
48
+ clean: string;
49
+ child: string;
38
50
  };
39
51
  optionTypes: {
40
52
  cwd: string;
41
53
  indexName: string;
42
54
  include: string;
43
55
  exclude: string;
56
+ clean: string;
57
+ child: string;
44
58
  };
45
59
  action: (options: any) => Promise<void>;
46
60
  };
@@ -1,5 +1,5 @@
1
- 'use strict';var cliCore=require('@tikkhun/cli-core'),utilsCore=require('@tikkhun/utils-core'),x=require('fs/promises'),glob=require('glob'),c=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var x__default=/*#__PURE__*/_interopDefault(x);var c__default=/*#__PURE__*/_interopDefault(c);/**
1
+ 'use strict';var cliCore=require('@tikkhun/cli-core'),utilsCore=require('@tikkhun/utils-core'),fs=require('fs'),promises=require('fs/promises'),glob=require('glob'),o=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var o__default=/*#__PURE__*/_interopDefault(o);/**
2
2
  @tikkhun/index-generator
3
3
  */
4
- var w=Object.defineProperty;var f=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var g=(n,e,t)=>e in n?w(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t,y=(n,e)=>{for(var t in e||(e={}))h.call(e,t)&&g(n,t,e[t]);if(f)for(var t of f(e))O.call(e,t)&&g(n,t,e[t]);return n};var o=(n,e,t)=>new Promise((u,r)=>{var d=i=>{try{p(t.next(i));}catch(l){r(l);}},s=i=>{try{p(t.throw(i));}catch(l){r(l);}},p=i=>i.done?u(i.value):Promise.resolve(i.value).then(d,s);p((t=t.apply(n,e)).next());});var a={name:"@tikkhun/index-generator",version:"0.0.3",description:""};var m={cwd:".",indexName:"index.ts",include:"*",exclude:[]};function k(n){return o(this,null,function*(){try{let e=utilsCore.mergeOptions(m,n),t=c__default.default.resolve(e.cwd),r=(yield glob.glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${c__default.default.extname(s)?c__default.default.basename(s).split(c__default.default.extname(s))[0]:s}";`).join(`
5
- `);console.log(r);let d=(e==null?void 0:e.indexName)||"index.ts";if(yield G(d)){console.error("index.ts \u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA");return}yield x__default.default.writeFile(d,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function G(n){return o(this,null,function*(){try{return yield x__default.default.access(n,x__default.default.constants.F_OK),!0}catch(e){return false}})}var D=y({},m),F={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664"},N={cwd:"string",indexName:"string",include:"array",exclude:"array"},T={name:a.name,version:a.version,description:a.description,types:[cliCore.CommandTypes.args,cliCore.CommandTypes.prompts],defaultOptions:D,optionTitles:F,optionTypes:N,action:n=>o(null,null,function*(){k(n);})},B=new cliCore.Cli(T);exports.cli=B;exports.cliOptions=T;exports.defaultOptions=D;exports.optionTitles=F;exports.optionTypes=N;
4
+ var k=Object.defineProperty,O=Object.defineProperties;var j=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var b=(i,e,t)=>e in i?k(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t,p=(i,e)=>{for(var t in e||(e={}))I.call(e,t)&&b(i,t,e[t]);if(y)for(var t of y(e))v.call(e,t)&&b(i,t,e[t]);return i},x=(i,e)=>O(i,j(e));var d=(i,e,t)=>new Promise((g,r)=>{var c=n=>{try{a(t.next(n));}catch(l){r(l);}},s=n=>{try{a(t.throw(n));}catch(l){r(l);}},a=n=>n.done?g(n.value):Promise.resolve(n.value).then(c,s);a((t=t.apply(i,e)).next());});var u={name:"@tikkhun/index-generator",version:"0.1.0",description:""};var m={cwd:".",indexName:"index.ts",include:["*"],exclude:[],clean:false,child:false,debug:false};function f(i){return d(this,null,function*(){try{let e=utilsCore.mergeOptions(m,i);e.debug&&console.log("opts",e);let t=o__default.default.resolve(e.cwd);if(e.child){let a=(yield glob.glob("**/*",{cwd:t,ignore:e.exclude})).filter(n=>fs.statSync(o__default.default.join(t,n)).isDirectory());for(let n of a)console.log("\u5BF9\u76EE\u5F55\u8FDB\u884Cindex\u751F\u6210",n),yield f(x(p({},e),{cwd:o__default.default.join(t,n),child:!1}));return}let r=(yield glob.glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${o__default.default.extname(s)?o__default.default.basename(s).split(o__default.default.extname(s))[0]:s}";`).join(`
5
+ `);console.log(r);let c=o__default.default.join(t,e.indexName);if(!(e!=null&&e.clean)&&(yield T(c))){console.error(`index\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA,\u6587\u4EF6\u540D\u4E3A${c}`);return}yield promises.writeFile(c,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function T(i){return d(this,null,function*(){try{return yield promises.access(i,promises.constants.F_OK),!0}catch(e){return false}})}var $=x(p({},m),{child:false}),q={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664",clean:"\u6E05\u9664\u65E7\u7684",child:"\u5B50\u76EE\u5F55"},J={cwd:"string",indexName:"string",include:"array",exclude:"array",clean:"boolean",child:"boolean"},K={name:u.name,version:u.version,description:u.description,types:[cliCore.CommandTypes.args,cliCore.CommandTypes.prompts],defaultOptions:$,optionTitles:q,optionTypes:J,action:i=>d(null,null,function*(){f(i);})},V=new cliCore.Cli(K);exports.cli=V;exports.cliOptions=K;exports.defaultOptions=$;exports.optionTitles=q;exports.optionTypes=J;
@@ -1,5 +1,5 @@
1
- import {CommandTypes,Cli}from'@tikkhun/cli-core';import {mergeOptions}from'@tikkhun/utils-core';import x from'fs/promises';import {glob}from'glob';import c from'path';/**
1
+ import {CommandTypes,Cli}from'@tikkhun/cli-core';import {mergeOptions}from'@tikkhun/utils-core';import {statSync}from'fs';import {writeFile,access,constants}from'fs/promises';import {glob}from'glob';import o from'path';/**
2
2
  @tikkhun/index-generator
3
3
  */
4
- var w=Object.defineProperty;var f=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var g=(n,e,t)=>e in n?w(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t,y=(n,e)=>{for(var t in e||(e={}))h.call(e,t)&&g(n,t,e[t]);if(f)for(var t of f(e))O.call(e,t)&&g(n,t,e[t]);return n};var o=(n,e,t)=>new Promise((u,r)=>{var d=i=>{try{p(t.next(i));}catch(l){r(l);}},s=i=>{try{p(t.throw(i));}catch(l){r(l);}},p=i=>i.done?u(i.value):Promise.resolve(i.value).then(d,s);p((t=t.apply(n,e)).next());});var a={name:"@tikkhun/index-generator",version:"0.0.3",description:""};var m={cwd:".",indexName:"index.ts",include:"*",exclude:[]};function k(n){return o(this,null,function*(){try{let e=mergeOptions(m,n),t=c.resolve(e.cwd),r=(yield glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${c.extname(s)?c.basename(s).split(c.extname(s))[0]:s}";`).join(`
5
- `);console.log(r);let d=(e==null?void 0:e.indexName)||"index.ts";if(yield G(d)){console.error("index.ts \u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA");return}yield x.writeFile(d,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function G(n){return o(this,null,function*(){try{return yield x.access(n,x.constants.F_OK),!0}catch(e){return false}})}var D=y({},m),F={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664"},N={cwd:"string",indexName:"string",include:"array",exclude:"array"},T={name:a.name,version:a.version,description:a.description,types:[CommandTypes.args,CommandTypes.prompts],defaultOptions:D,optionTitles:F,optionTypes:N,action:n=>o(null,null,function*(){k(n);})},B=new Cli(T);export{B as cli,T as cliOptions,D as defaultOptions,F as optionTitles,N as optionTypes};
4
+ var k=Object.defineProperty,O=Object.defineProperties;var j=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var b=(i,e,t)=>e in i?k(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t,p=(i,e)=>{for(var t in e||(e={}))I.call(e,t)&&b(i,t,e[t]);if(y)for(var t of y(e))v.call(e,t)&&b(i,t,e[t]);return i},x=(i,e)=>O(i,j(e));var d=(i,e,t)=>new Promise((g,r)=>{var c=n=>{try{a(t.next(n));}catch(l){r(l);}},s=n=>{try{a(t.throw(n));}catch(l){r(l);}},a=n=>n.done?g(n.value):Promise.resolve(n.value).then(c,s);a((t=t.apply(i,e)).next());});var u={name:"@tikkhun/index-generator",version:"0.1.0",description:""};var m={cwd:".",indexName:"index.ts",include:["*"],exclude:[],clean:false,child:false,debug:false};function f(i){return d(this,null,function*(){try{let e=mergeOptions(m,i);e.debug&&console.log("opts",e);let t=o.resolve(e.cwd);if(e.child){let a=(yield glob("**/*",{cwd:t,ignore:e.exclude})).filter(n=>statSync(o.join(t,n)).isDirectory());for(let n of a)console.log("\u5BF9\u76EE\u5F55\u8FDB\u884Cindex\u751F\u6210",n),yield f(x(p({},e),{cwd:o.join(t,n),child:!1}));return}let r=(yield glob(e.include,{cwd:t,ignore:e.exclude})).map(s=>`export * from "./${o.extname(s)?o.basename(s).split(o.extname(s))[0]:s}";`).join(`
5
+ `);console.log(r);let c=o.join(t,e.indexName);if(!(e!=null&&e.clean)&&(yield T(c))){console.error(`index\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA,\u6587\u4EF6\u540D\u4E3A${c}`);return}yield writeFile(c,r,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function T(i){return d(this,null,function*(){try{return yield access(i,constants.F_OK),!0}catch(e){return false}})}var $=x(p({},m),{child:false}),q={cwd:"\u8DEF\u5F84",indexName:"\u6587\u4EF6\u540D",include:"\u5305\u542B",exclude:"\u6392\u9664",clean:"\u6E05\u9664\u65E7\u7684",child:"\u5B50\u76EE\u5F55"},J={cwd:"string",indexName:"string",include:"array",exclude:"array",clean:"boolean",child:"boolean"},K={name:u.name,version:u.version,description:u.description,types:[CommandTypes.args,CommandTypes.prompts],defaultOptions:$,optionTitles:q,optionTypes:J,action:i=>d(null,null,function*(){f(i);})},V=new Cli(K);export{V as cli,K as cliOptions,$ as defaultOptions,q as optionTitles,J as optionTypes};
@@ -1,8 +1,11 @@
1
1
  declare const DefaultGenerateIndexOptions: {
2
2
  cwd: string;
3
3
  indexName: string;
4
- include: string;
4
+ include: string[];
5
5
  exclude: never[];
6
+ clean: boolean;
7
+ child: boolean;
8
+ debug: boolean;
6
9
  };
7
10
  type GenerateIndexOptions = typeof DefaultGenerateIndexOptions & {
8
11
  include: string | string[];
@@ -1,8 +1,11 @@
1
1
  declare const DefaultGenerateIndexOptions: {
2
2
  cwd: string;
3
3
  indexName: string;
4
- include: string;
4
+ include: string[];
5
5
  exclude: never[];
6
+ clean: boolean;
7
+ child: boolean;
8
+ debug: boolean;
6
9
  };
7
10
  type GenerateIndexOptions = typeof DefaultGenerateIndexOptions & {
8
11
  include: string | string[];
package/dist/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict';var utilsCore=require('@tikkhun/utils-core'),l=require('fs/promises'),glob=require('glob'),a=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var l__default=/*#__PURE__*/_interopDefault(l);var a__default=/*#__PURE__*/_interopDefault(a);/**
1
+ 'use strict';var utilsCore=require('@tikkhun/utils-core'),fs=require('fs'),promises=require('fs/promises'),glob=require('glob'),i=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var i__default=/*#__PURE__*/_interopDefault(i);/**
2
2
  @tikkhun/index-generator
3
3
  */
4
- var d=(o,e,n)=>new Promise((p,s)=>{var i=t=>{try{c(n.next(t));}catch(x){s(x);}},r=t=>{try{c(n.throw(t));}catch(x){s(x);}},c=t=>t.done?p(t.value):Promise.resolve(t.value).then(i,r);c((n=n.apply(o,e)).next());});var f={cwd:".",indexName:"index.ts",include:"*",exclude:[]};function F(o){return d(this,null,function*(){try{let e=utilsCore.mergeOptions(f,o),n=a__default.default.resolve(e.cwd),s=(yield glob.glob(e.include,{cwd:n,ignore:e.exclude})).map(r=>`export * from "./${a__default.default.extname(r)?a__default.default.basename(r).split(a__default.default.extname(r))[0]:r}";`).join(`
5
- `);console.log(s);let i=(e==null?void 0:e.indexName)||"index.ts";if(yield g(i)){console.error("index.ts \u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA");return}yield l__default.default.writeFile(i,s,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function g(o){return d(this,null,function*(){try{return yield l__default.default.access(o,l__default.default.constants.F_OK),!0}catch(e){return false}})}exports.DefaultGenerateIndexOptions=f;exports.generateIndex=F;exports.isFileExists=g;
4
+ var w=Object.defineProperty,y=Object.defineProperties;var O=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var p=(n,e,t)=>e in n?w(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t,u=(n,e)=>{for(var t in e||(e={}))h.call(e,t)&&p(n,t,e[t]);if(x)for(var t of x(e))I.call(e,t)&&p(n,t,e[t]);return n},m=(n,e)=>y(n,O(e));var d=(n,e,t)=>new Promise((f,s)=>{var a=o=>{try{c(t.next(o));}catch(l){s(l);}},r=o=>{try{c(t.throw(o));}catch(l){s(l);}},c=o=>o.done?f(o.value):Promise.resolve(o.value).then(a,r);c((t=t.apply(n,e)).next());});var D={cwd:".",indexName:"index.ts",include:["*"],exclude:[],clean:false,child:false,debug:false};function E(n){return d(this,null,function*(){try{let e=utilsCore.mergeOptions(D,n);e.debug&&console.log("opts",e);let t=i__default.default.resolve(e.cwd);if(e.child){let c=(yield glob.glob("**/*",{cwd:t,ignore:e.exclude})).filter(o=>fs.statSync(i__default.default.join(t,o)).isDirectory());for(let o of c)console.log("\u5BF9\u76EE\u5F55\u8FDB\u884Cindex\u751F\u6210",o),yield E(m(u({},e),{cwd:i__default.default.join(t,o),child:!1}));return}let s=(yield glob.glob(e.include,{cwd:t,ignore:e.exclude})).map(r=>`export * from "./${i__default.default.extname(r)?i__default.default.basename(r).split(i__default.default.extname(r))[0]:r}";`).join(`
5
+ `);console.log(s);let a=i__default.default.join(t,e.indexName);if(!(e!=null&&e.clean)&&(yield N(a))){console.error(`index\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA,\u6587\u4EF6\u540D\u4E3A${a}`);return}yield promises.writeFile(a,s,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function N(n){return d(this,null,function*(){try{return yield promises.access(n,promises.constants.F_OK),!0}catch(e){return false}})}exports.DefaultGenerateIndexOptions=D;exports.generateIndex=E;exports.isFileExists=N;
@@ -1,5 +1,5 @@
1
- import {mergeOptions}from'@tikkhun/utils-core';import l from'fs/promises';import {glob}from'glob';import a from'path';/**
1
+ import {mergeOptions}from'@tikkhun/utils-core';import {statSync}from'fs';import {writeFile,access,constants}from'fs/promises';import {glob}from'glob';import i from'path';/**
2
2
  @tikkhun/index-generator
3
3
  */
4
- var d=(o,e,n)=>new Promise((p,s)=>{var i=t=>{try{c(n.next(t));}catch(x){s(x);}},r=t=>{try{c(n.throw(t));}catch(x){s(x);}},c=t=>t.done?p(t.value):Promise.resolve(t.value).then(i,r);c((n=n.apply(o,e)).next());});var f={cwd:".",indexName:"index.ts",include:"*",exclude:[]};function F(o){return d(this,null,function*(){try{let e=mergeOptions(f,o),n=a.resolve(e.cwd),s=(yield glob(e.include,{cwd:n,ignore:e.exclude})).map(r=>`export * from "./${a.extname(r)?a.basename(r).split(a.extname(r))[0]:r}";`).join(`
5
- `);console.log(s);let i=(e==null?void 0:e.indexName)||"index.ts";if(yield g(i)){console.error("index.ts \u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA");return}yield l.writeFile(i,s,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function g(o){return d(this,null,function*(){try{return yield l.access(o,l.constants.F_OK),!0}catch(e){return false}})}export{f as DefaultGenerateIndexOptions,F as generateIndex,g as isFileExists};
4
+ var w=Object.defineProperty,y=Object.defineProperties;var O=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var p=(n,e,t)=>e in n?w(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t,u=(n,e)=>{for(var t in e||(e={}))h.call(e,t)&&p(n,t,e[t]);if(x)for(var t of x(e))I.call(e,t)&&p(n,t,e[t]);return n},m=(n,e)=>y(n,O(e));var d=(n,e,t)=>new Promise((f,s)=>{var a=o=>{try{c(t.next(o));}catch(l){s(l);}},r=o=>{try{c(t.throw(o));}catch(l){s(l);}},c=o=>o.done?f(o.value):Promise.resolve(o.value).then(a,r);c((t=t.apply(n,e)).next());});var D={cwd:".",indexName:"index.ts",include:["*"],exclude:[],clean:false,child:false,debug:false};function E(n){return d(this,null,function*(){try{let e=mergeOptions(D,n);e.debug&&console.log("opts",e);let t=i.resolve(e.cwd);if(e.child){let c=(yield glob("**/*",{cwd:t,ignore:e.exclude})).filter(o=>statSync(i.join(t,o)).isDirectory());for(let o of c)console.log("\u5BF9\u76EE\u5F55\u8FDB\u884Cindex\u751F\u6210",o),yield E(m(u({},e),{cwd:i.join(t,o),child:!1}));return}let s=(yield glob(e.include,{cwd:t,ignore:e.exclude})).map(r=>`export * from "./${i.extname(r)?i.basename(r).split(i.extname(r))[0]:r}";`).join(`
5
+ `);console.log(s);let a=i.join(t,e.indexName);if(!(e!=null&&e.clean)&&(yield N(a))){console.error(`index\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8FDB\u884C\u521B\u5EFA,\u6587\u4EF6\u540D\u4E3A${a}`);return}yield writeFile(a,s,"utf-8");}catch(e){console.error("\u751F\u6210 index \u6587\u4EF6\u65F6\u51FA\u9519:",e);}})}function N(n){return d(this,null,function*(){try{return yield access(n,constants.F_OK),!0}catch(e){return false}})}export{D as DefaultGenerateIndexOptions,E as generateIndex,N as isFileExists};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tikkhun/index-generator",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "tikkhun-index-generator": "dist/cli/index.js"
@@ -30,17 +30,16 @@
30
30
  "author": "",
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
- "commander": "^12.1.0",
34
- "glob": "^11.0.2",
33
+ "glob": "^11.0.3",
35
34
  "@tikkhun/cli-core": "^0.0.28",
36
35
  "@tikkhun/logger": "^1.0.8",
37
36
  "@tikkhun/utils-core": "^0.0.22"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@types/node": "^20.3.1",
41
- "tsup": "^8.3.0",
42
- "tsx": "^4.19.1",
43
- "vitest": "^2.1.3"
40
+ "tsup": "^8.5.0",
41
+ "tsx": "^4.20.3",
42
+ "vitest": "^3.2.4"
44
43
  },
45
44
  "scripts": {
46
45
  "build": "tsup",