@qlover/create-app 0.1.5 → 0.1.6
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/CHANGELOG.md +7 -0
- package/configs/_common/.github/workflows/release.yml.template +8 -8
- package/configs/_common/.release-it.json.template +5 -5
- package/configs/_common/{package.json → package.json.template} +5 -5
- package/dist/cjs/index.d.ts +15 -10
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.d.ts +15 -10
- package/dist/es/index.js +1 -1
- package/package.json +2 -1
- package/templates/node-lib/.release-it.json +0 -42
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [0.1.6](https://github.com/qlover/fe-base/compare/create-app-v0.1.5...create-app-v0.1.6) (2025-02-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* template context ([#241](https://github.com/qlover/fe-base/issues/241)) ([9fb3046](https://github.com/qlover/fe-base/commit/9fb3046e3e67c02e5fe4fea81a9a3ef8422e3013))
|
|
9
|
+
|
|
3
10
|
## [0.1.5](https://github.com/qlover/fe-base/compare/create-app-v0.1.4...create-app-v0.1.5) (2025-02-13)
|
|
4
11
|
|
|
5
12
|
## [0.1.4](https://github.com/qlover/fe-base/compare/create-app-v0.1.3...create-app-v0.1.4) (2025-01-20)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name: Release [
|
|
1
|
+
name: Release [TPL:projectName]
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
@@ -8,14 +8,14 @@ on:
|
|
|
8
8
|
types:
|
|
9
9
|
- closed
|
|
10
10
|
paths:
|
|
11
|
-
- [
|
|
11
|
+
- [TPL:releasePath]/**
|
|
12
12
|
|
|
13
13
|
jobs:
|
|
14
14
|
release-PR:
|
|
15
|
-
# only run when PR merged and has changes:[
|
|
15
|
+
# only run when PR merged and has changes:[TPL:projectName] and CI-Release labels
|
|
16
16
|
if: |
|
|
17
17
|
github.event.pull_request.merged == true &&
|
|
18
|
-
contains(github.event.pull_request.labels.*.name, 'changes:[
|
|
18
|
+
contains(github.event.pull_request.labels.*.name, 'changes:[TPL:projectName]') &&
|
|
19
19
|
!contains(github.event.pull_request.labels.*.name, 'CI-Release')
|
|
20
20
|
runs-on: ubuntu-latest
|
|
21
21
|
|
|
@@ -50,17 +50,17 @@ jobs:
|
|
|
50
50
|
run: pnpm build
|
|
51
51
|
|
|
52
52
|
- name: Create release PR
|
|
53
|
-
run: npm run release-pr:[
|
|
53
|
+
run: npm run release-pr:[TPL:projectName]
|
|
54
54
|
env:
|
|
55
55
|
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN}}
|
|
56
56
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
|
|
57
57
|
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
|
58
58
|
|
|
59
59
|
release:
|
|
60
|
-
# only run when PR merged and has changes:[
|
|
60
|
+
# only run when PR merged and has changes:[TPL:projectName] and CI-Release labels
|
|
61
61
|
if: |
|
|
62
62
|
github.event.pull_request.merged == true &&
|
|
63
|
-
contains(github.event.pull_request.labels.*.name, 'changes:[
|
|
63
|
+
contains(github.event.pull_request.labels.*.name, 'changes:[TPL:projectName]') &&
|
|
64
64
|
contains(github.event.pull_request.labels.*.name, 'CI-Release')
|
|
65
65
|
|
|
66
66
|
runs-on: ubuntu-latest
|
|
@@ -97,7 +97,7 @@ jobs:
|
|
|
97
97
|
run: pnpm build
|
|
98
98
|
|
|
99
99
|
- name: Create tag and publish
|
|
100
|
-
run: npm run release:[
|
|
100
|
+
run: npm run release:[TPL:projectName]
|
|
101
101
|
env:
|
|
102
102
|
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN}}
|
|
103
103
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"git": {
|
|
3
|
-
"commitMessage": "chore(tag): [
|
|
4
|
-
"tagName": "[
|
|
5
|
-
"tagMatch": "[
|
|
6
|
-
"tagAnnotation": "chore(tag): [
|
|
3
|
+
"commitMessage": "chore(tag): [TPL:projectName] v${version}",
|
|
4
|
+
"tagName": "[TPL:projectName]-v${version}",
|
|
5
|
+
"tagMatch": "[TPL:projectName]-v*",
|
|
6
|
+
"tagAnnotation": "chore(tag): [TPL:projectName] v${version}",
|
|
7
7
|
"push": true,
|
|
8
8
|
"pushArgs": ["--follow-tags"]
|
|
9
9
|
},
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"github": {
|
|
15
15
|
"release": true,
|
|
16
|
-
"releaseName": "chore(tag): [
|
|
16
|
+
"releaseName": "chore(tag): [TPL:projectName] v${version}"
|
|
17
17
|
},
|
|
18
18
|
|
|
19
19
|
"plugins": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
3
|
-
"description": "
|
|
2
|
+
"name": "[TPL:projectName]",
|
|
3
|
+
"description": "[TPL:projectName] description",
|
|
4
4
|
"version": "0.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": true,
|
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
"README.md"
|
|
33
33
|
],
|
|
34
34
|
"keywords": [
|
|
35
|
-
"
|
|
36
|
-
"node lib"
|
|
35
|
+
"[TPL:projectName]"
|
|
37
36
|
],
|
|
38
37
|
"publishConfig": {
|
|
39
38
|
"access": "public"
|
|
@@ -47,7 +46,8 @@
|
|
|
47
46
|
"clean": "fe-clean",
|
|
48
47
|
"check-packages": "fe-check-packages",
|
|
49
48
|
"commit": "fe-commit",
|
|
50
|
-
"clean-branch": "fe-clean-branch"
|
|
49
|
+
"clean-branch": "fe-clean-branch",
|
|
50
|
+
"release:[TPL:projectName]": "release-it"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@qlover/env-loader": "latest",
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -19,11 +19,11 @@ type GeneratorOptions = {
|
|
|
19
19
|
*/
|
|
20
20
|
config?: boolean;
|
|
21
21
|
};
|
|
22
|
-
interface
|
|
22
|
+
interface GeneratorContext extends GeneratorOptions {
|
|
23
23
|
/**
|
|
24
24
|
* project name
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
projectName: string;
|
|
27
27
|
/**
|
|
28
28
|
* choose template name
|
|
29
29
|
*
|
|
@@ -45,10 +45,15 @@ interface GeneratorRuntimes extends GeneratorOptions {
|
|
|
45
45
|
* @default `./`
|
|
46
46
|
*/
|
|
47
47
|
targetPath?: string;
|
|
48
|
+
/**
|
|
49
|
+
* release path
|
|
50
|
+
* @default `src`
|
|
51
|
+
*/
|
|
52
|
+
releasePath?: string;
|
|
48
53
|
}
|
|
49
54
|
type TaskOptions = {
|
|
50
55
|
templateFiles: TemplateFile[];
|
|
51
|
-
result:
|
|
56
|
+
result: GeneratorContext;
|
|
52
57
|
};
|
|
53
58
|
type TemplateFile = {
|
|
54
59
|
path: string;
|
|
@@ -60,19 +65,20 @@ declare class Generator {
|
|
|
60
65
|
protected context: FeScriptContext<GeneratorOptions>;
|
|
61
66
|
private subPackages;
|
|
62
67
|
private copyer;
|
|
68
|
+
private compose;
|
|
63
69
|
constructor(context: Partial<FeScriptContext<GeneratorOptions>>);
|
|
64
70
|
get logger(): Logger;
|
|
65
|
-
steps(prompts: GeneratorPrompt[]): Promise<
|
|
71
|
+
steps(prompts: GeneratorPrompt[]): Promise<GeneratorContext>;
|
|
66
72
|
action({ label, task }: {
|
|
67
73
|
label: string;
|
|
68
74
|
task: (() => Promise<unknown>) | (() => unknown);
|
|
69
75
|
}): Promise<unknown>;
|
|
70
76
|
private isPackageTemplate;
|
|
71
|
-
private
|
|
72
|
-
private copyConfigs;
|
|
77
|
+
private getGeneratorContext;
|
|
73
78
|
generate(): Promise<void>;
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
generateConfigs(context: GeneratorContext, targetPath: string, configName: string): Promise<void>;
|
|
80
|
+
generateTemplateDir(context: GeneratorContext): Promise<void>;
|
|
81
|
+
generateSubPackages(context: GeneratorContext): Promise<void>;
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
declare const validRequiredString: (value: string, key: string) => string | true;
|
|
@@ -86,7 +92,6 @@ declare class Copyer {
|
|
|
86
92
|
static IGNORE_FILE: string;
|
|
87
93
|
constructor(ignoreTargetPath: string, ignoreFile?: string);
|
|
88
94
|
getIg(targetDir?: string): ignore.Ignore | undefined;
|
|
89
|
-
ensureDir(dir: string): void;
|
|
90
95
|
/**
|
|
91
96
|
* Asynchronously copy files from source to target directory.
|
|
92
97
|
* @param {string} sourcePath - Source directory.
|
|
@@ -104,4 +109,4 @@ declare class Copyer {
|
|
|
104
109
|
}): Promise<void>;
|
|
105
110
|
}
|
|
106
111
|
|
|
107
|
-
export { type CopyCallback, Copyer, Generator, type
|
|
112
|
+
export { type CopyCallback, Copyer, Generator, type GeneratorContext, type GeneratorOptions, type GeneratorPrompt, type TaskOptions, type TemplateFile, createDefaultPrompts, createPackagePrompts, validRequiredString };
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@qlover/scripts-context"),e=require("inquirer"),a=require("path"),s=require("ora"),i=require("fs"),r=require("ignore");const o=(t,e)=>"string"==typeof t&&""!==t.trim()||`${e} is required`;function n(t,e){return[{type:"input",name:"name",message:"Project name",validate:t=>o(t,"Project name")},{type:"list",name:"template",message:"Template name",choices:[...t,...e]}]}function c(t){return[{type:"checkbox",name:"subPackages",message:"Sub package names",choices:t}]}const{copyFile:g,stat:p}=i.promises;class h{ignoreTargetPath;ignoreFile;static IGNORE_FILE=".gitignore.template";constructor(t,e=h.IGNORE_FILE){this.ignoreTargetPath=t,this.ignoreFile=e}getIg(t=this.ignoreTargetPath){const e=a.join(t,this.ignoreFile);if(!i.existsSync(e))return;const s=i.readFileSync(e,"utf8").split("\n").map((t=>t.trim())).filter((t=>t&&!t.startsWith("#")));return r().add(s)}ensureDir(t){i.existsSync(t)||i.mkdirSync(t,{recursive:!0})}async copyFiles(t,e,s,r){const o=await i.promises.readdir(t);await Promise.all(o.map((async i=>{const o=a.join(t,i),n=a.join(e,i);if(s&&s.ignores(i))return;this.ensureDir(a.dirname(n));if((await p(o)).isDirectory())await this.copyFiles(o,n,s);else{if(r&&await r(o,n))return;await g(o,n)}})))}copyPaths({sourcePath:t,targetPath:e,copyCallback:a}){this.ensureDir(e);const s=this.getIg();return this.copyFiles(t,e,s,a)}}const l=["pack-app"];exports.Copyer=h,exports.Generator=class{ora;context;subPackages;copyer;constructor(e){const r=e.options?.templateRootPath;if(!r)throw new Error("template path not exit");if(!i.existsSync(r))throw new Error("template path not exit");this.ora=s.oraPromise,this.context=new t.FeScriptContext(e),this.subPackages=["node-lib","react-app"],this.copyer=new h(a.join(this.context.options.configsRootPath,"_common"))}get logger(){return this.context.logger}async steps(t){try{return await e.prompt(t)}catch(t){throw this.logger.error(t),t}}async action({label:t,task:e}){let a=e();a instanceof Promise||(a=Promise.resolve(a));const s=t;return this.ora(a,s),a}isPackageTemplate(t){return l.includes(t)}async getGeneratorResult(){const t=n(this.subPackages,l),e=await this.steps(t);if(this.isPackageTemplate(e.template)){const t=c(this.subPackages),a=await this.steps(t);Object.assign(e,a)}return e}async copyConfigs(t,e){const{configsRootPath:s,config:i}=this.context.options;i?await this.copyer.copyPaths({sourcePath:a.join(s,e),targetPath:t,copyCallback:(t,e)=>(this.logger.debug("copyCallback",t,e),!1)}):this.logger.debug("no copy config files")}async generate(){const t=await this.getGeneratorResult();t.targetPath=a.join(process.cwd(),t.name),this.logger.debug("result is:",t,this.context.options.templateRootPath),t.subPackages?await this.action({label:"Generate Directories(subPackages)",task:async()=>{await this.generateTemplateDir(t),await this.generateSubPackages(t),await this.copyConfigs(t.targetPath,"_common")}}):await this.action({label:"Generate Directory",task:async()=>{await this.generateTemplateDir(t),await this.copyConfigs(t.targetPath,"_common"),await this.copyConfigs(t.targetPath,t.template)}})}generateTemplateDir(t){return this.copyer.copyPaths({sourcePath:a.join(this.context.options.templateRootPath,t.template),targetPath:t.targetPath})}async generateSubPackages(t){const{packagesNames:e="packages",subPackages:s=[],targetPath:i=""}=t,{templateRootPath:r}=this.context.options;for(const t of s){const s=a.join(r,t),o=a.join(i,e,t);this.logger.debug("copy sub package",s,o),await this.copyer.copyPaths({sourcePath:s,targetPath:o})}}},exports.createDefaultPrompts=n,exports.createPackagePrompts=c,exports.validRequiredString=o;
|
|
1
|
+
"use strict";var t=require("@qlover/scripts-context"),r=require("inquirer"),e=require("path"),n=require("ora"),i=require("fs"),o=require("ignore");const u=(t,r)=>"string"==typeof t&&""!==t.trim()||`${r} is required`;function a(t,r){return[{type:"input",name:"projectName",message:"Project name",validate:t=>u(t,"Project name")},{type:"list",name:"template",message:"Template name",choices:[...t,...r]}]}function c(t){return[{type:"checkbox",name:"subPackages",message:"Sub package names",choices:t}]}class f{static ensureDir(t){i.existsSync(t)||i.mkdirSync(t,{recursive:!0})}}const{copyFile:s,stat:l}=i.promises;class p{ignoreTargetPath;ignoreFile;static IGNORE_FILE=".gitignore.template";constructor(t,r=p.IGNORE_FILE){this.ignoreTargetPath=t,this.ignoreFile=r}getIg(t=this.ignoreTargetPath){const r=e.join(t,this.ignoreFile);if(!i.existsSync(r))return;const n=i.readFileSync(r,"utf8").split("\n").map((t=>t.trim())).filter((t=>t&&!t.startsWith("#")));return o().add(n)}async copyFiles(t,r,n,o){const u=await i.promises.readdir(t);await Promise.all(u.map((async i=>{const u=e.join(t,i),a=e.join(r,i);if(n&&n.ignores(i))return;f.ensureDir(e.dirname(a));if((await l(u)).isDirectory())await this.copyFiles(u,a,n,o);else{if(o&&await o(u,a))return;await s(u,a)}})))}copyPaths({sourcePath:t,targetPath:r,copyCallback:e}){f.ensureDir(r);const n=this.getIg();return this.copyFiles(t,r,n,e)}}var h,v,y,g,b,d,_,m,j,P,w,O,x,F,S,k,T,A,z,N,R,C,D,E,q,I,J,$,G,U,B,L,M,W,V,H,K,Q,X,Y,Z,tt,rt,et,nt,it,ot,ut,at,ct,ft,st,lt,pt,ht,vt,yt,gt,bt,dt,_t,mt,jt,Pt,wt,Ot,xt,Ft,St,kt,Tt,At,zt,Nt,Rt,Ct,Dt,Et,qt,It,Jt,$t,Gt,Ut,Bt,Lt,Mt,Wt,Vt,Ht,Kt,Qt,Xt,Yt,Zt,tr,rr,er,nr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ir(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function or(){if(v)return h;return v=1,h=function(){this.__data__=[],this.size=0}}function ur(){if(g)return y;return g=1,y=function(t,r){return t===r||t!=t&&r!=r}}function ar(){if(d)return b;d=1;var t=ur();return b=function(r,e){for(var n=r.length;n--;)if(t(r[n][0],e))return n;return-1}}function cr(){if(m)return _;m=1;var t=ar(),r=Array.prototype.splice;return _=function(e){var n=this.__data__,i=t(n,e);return!(i<0)&&(i==n.length-1?n.pop():r.call(n,i,1),--this.size,!0)}}function fr(){if(P)return j;P=1;var t=ar();return j=function(r){var e=this.__data__,n=t(e,r);return n<0?void 0:e[n][1]}}function sr(){if(O)return w;O=1;var t=ar();return w=function(r){return t(this.__data__,r)>-1}}function lr(){if(F)return x;F=1;var t=ar();return x=function(r,e){var n=this.__data__,i=t(n,r);return i<0?(++this.size,n.push([r,e])):n[i][1]=e,this}}function pr(){if(k)return S;k=1;var t=or(),r=cr(),e=fr(),n=sr(),i=lr();function o(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}return o.prototype.clear=t,o.prototype.delete=r,o.prototype.get=e,o.prototype.has=n,o.prototype.set=i,S=o}function hr(){if(A)return T;A=1;var t=pr();return T=function(){this.__data__=new t,this.size=0}}function vr(){if(N)return z;return N=1,z=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e}}function yr(){if(C)return R;return C=1,R=function(t){return this.__data__.get(t)}}function gr(){if(E)return D;return E=1,D=function(t){return this.__data__.has(t)}}function br(){if(I)return q;I=1;var t="object"==typeof nr&&nr&&nr.Object===Object&&nr;return q=t}function dr(){if($)return J;$=1;var t=br(),r="object"==typeof self&&self&&self.Object===Object&&self,e=t||r||Function("return this")();return J=e}function _r(){if(U)return G;U=1;var t=dr().Symbol;return G=t}function mr(){if(L)return B;L=1;var t=_r(),r=Object.prototype,e=r.hasOwnProperty,n=r.toString,i=t?t.toStringTag:void 0;return B=function(t){var r=e.call(t,i),o=t[i];try{t[i]=void 0;var u=!0}catch(t){}var a=n.call(t);return u&&(r?t[i]=o:delete t[i]),a}}function jr(){if(W)return M;W=1;var t=Object.prototype.toString;return M=function(r){return t.call(r)}}function Pr(){if(H)return V;H=1;var t=_r(),r=mr(),e=jr(),n=t?t.toStringTag:void 0;return V=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":n&&n in Object(t)?r(t):e(t)}}function wr(){if(Q)return K;return Q=1,K=function(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}}function Or(){if(Y)return X;Y=1;var t=Pr(),r=wr();return X=function(e){if(!r(e))return!1;var n=t(e);return"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n}}function xr(){if(tt)return Z;tt=1;var t=dr()["__core-js_shared__"];return Z=t}function Fr(){if(et)return rt;et=1;var t,r=xr(),e=(t=/[^.]+$/.exec(r&&r.keys&&r.keys.IE_PROTO||""))?"Symbol(src)_1."+t:"";return rt=function(t){return!!e&&e in t}}function Sr(){if(it)return nt;it=1;var t=Function.prototype.toString;return nt=function(r){if(null!=r){try{return t.call(r)}catch(t){}try{return r+""}catch(t){}}return""}}function kr(){if(ut)return ot;ut=1;var t=Or(),r=Fr(),e=wr(),n=Sr(),i=/^\[object .+?Constructor\]$/,o=Function.prototype,u=Object.prototype,a=o.toString,c=u.hasOwnProperty,f=RegExp("^"+a.call(c).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");return ot=function(o){return!(!e(o)||r(o))&&(t(o)?f:i).test(n(o))}}function Tr(){if(ct)return at;return ct=1,at=function(t,r){return null==t?void 0:t[r]}}function Ar(){if(st)return ft;st=1;var t=kr(),r=Tr();return ft=function(e,n){var i=r(e,n);return t(i)?i:void 0}}function zr(){if(pt)return lt;pt=1;var t=Ar()(dr(),"Map");return lt=t}function Nr(){if(vt)return ht;vt=1;var t=Ar()(Object,"create");return ht=t}function Rr(){if(gt)return yt;gt=1;var t=Nr();return yt=function(){this.__data__=t?t(null):{},this.size=0}}function Cr(){if(dt)return bt;return dt=1,bt=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}}function Dr(){if(mt)return _t;mt=1;var t=Nr(),r=Object.prototype.hasOwnProperty;return _t=function(e){var n=this.__data__;if(t){var i=n[e];return"__lodash_hash_undefined__"===i?void 0:i}return r.call(n,e)?n[e]:void 0}}function Er(){if(Pt)return jt;Pt=1;var t=Nr(),r=Object.prototype.hasOwnProperty;return jt=function(e){var n=this.__data__;return t?void 0!==n[e]:r.call(n,e)}}function qr(){if(Ot)return wt;Ot=1;var t=Nr();return wt=function(r,e){var n=this.__data__;return this.size+=this.has(r)?0:1,n[r]=t&&void 0===e?"__lodash_hash_undefined__":e,this}}function Ir(){if(Ft)return xt;Ft=1;var t=Rr(),r=Cr(),e=Dr(),n=Er(),i=qr();function o(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}return o.prototype.clear=t,o.prototype.delete=r,o.prototype.get=e,o.prototype.has=n,o.prototype.set=i,xt=o}function Jr(){if(kt)return St;kt=1;var t=Ir(),r=pr(),e=zr();return St=function(){this.size=0,this.__data__={hash:new t,map:new(e||r),string:new t}}}function $r(){if(At)return Tt;return At=1,Tt=function(t){var r=typeof t;return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t}}function Gr(){if(Nt)return zt;Nt=1;var t=$r();return zt=function(r,e){var n=r.__data__;return t(e)?n["string"==typeof e?"string":"hash"]:n.map}}function Ur(){if(Ct)return Rt;Ct=1;var t=Gr();return Rt=function(r){var e=t(this,r).delete(r);return this.size-=e?1:0,e}}function Br(){if(Et)return Dt;Et=1;var t=Gr();return Dt=function(r){return t(this,r).get(r)}}function Lr(){if(It)return qt;It=1;var t=Gr();return qt=function(r){return t(this,r).has(r)}}function Mr(){if($t)return Jt;$t=1;var t=Gr();return Jt=function(r,e){var n=t(this,r),i=n.size;return n.set(r,e),this.size+=n.size==i?0:1,this}}function Wr(){if(Ut)return Gt;Ut=1;var t=Jr(),r=Ur(),e=Br(),n=Lr(),i=Mr();function o(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}return o.prototype.clear=t,o.prototype.delete=r,o.prototype.get=e,o.prototype.has=n,o.prototype.set=i,Gt=o}function Vr(){if(Lt)return Bt;Lt=1;var t=pr(),r=zr(),e=Wr();return Bt=function(n,i){var o=this.__data__;if(o instanceof t){var u=o.__data__;if(!r||u.length<199)return u.push([n,i]),this.size=++o.size,this;o=this.__data__=new e(u)}return o.set(n,i),this.size=o.size,this}}function Hr(){if(Wt)return Mt;Wt=1;var t=pr(),r=hr(),e=vr(),n=yr(),i=gr(),o=Vr();function u(r){var e=this.__data__=new t(r);this.size=e.size}return u.prototype.clear=r,u.prototype.delete=e,u.prototype.get=n,u.prototype.has=i,u.prototype.set=o,Mt=u}function Kr(){if(Ht)return Vt;Ht=1;var t=Ar(),r=function(){try{var r=t(Object,"defineProperty");return r({},"",{}),r}catch(t){}}();return Vt=r}function Qr(){if(Qt)return Kt;Qt=1;var t=Kr();return Kt=function(r,e,n){"__proto__"==e&&t?t(r,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):r[e]=n}}function Xr(){if(Yt)return Xt;Yt=1;var t=Qr(),r=ur();return Xt=function(e,n,i){(void 0!==i&&!r(e[n],i)||void 0===i&&!(n in e))&&t(e,n,i)}}function Yr(){if(tr)return Zt;return tr=1,Zt=function(t){return function(r,e,n){for(var i=-1,o=Object(r),u=n(r),a=u.length;a--;){var c=u[t?a:++i];if(!1===e(o[c],c,o))break}return r}}}function Zr(){if(er)return rr;er=1;var t=Yr()();return rr=t}var te,re,ee,ne,ie,oe,ue,ae,ce,fe,se,le,pe,he,ve,ye,ge,be,de,_e,me,je,Pe,we,Oe,xe,Fe,Se,ke,Te,Ae,ze,Ne,Re={exports:{}};function Ce(){return te||(te=1,function(t,r){var e=dr(),n=r&&!r.nodeType&&r,i=n&&t&&!t.nodeType&&t,o=i&&i.exports===n?e.Buffer:void 0,u=o?o.allocUnsafe:void 0;t.exports=function(t,r){if(r)return t.slice();var e=t.length,n=u?u(e):new t.constructor(e);return t.copy(n),n}}(Re,Re.exports)),Re.exports}function De(){if(ee)return re;ee=1;var t=dr().Uint8Array;return re=t}function Ee(){if(ie)return ne;ie=1;var t=De();return ne=function(r){var e=new r.constructor(r.byteLength);return new t(e).set(new t(r)),e}}function qe(){if(ue)return oe;ue=1;var t=Ee();return oe=function(r,e){var n=e?t(r.buffer):r.buffer;return new r.constructor(n,r.byteOffset,r.length)}}function Ie(){if(ce)return ae;return ce=1,ae=function(t,r){var e=-1,n=t.length;for(r||(r=Array(n));++e<n;)r[e]=t[e];return r}}function Je(){if(se)return fe;se=1;var t=wr(),r=Object.create,e=function(){function e(){}return function(n){if(!t(n))return{};if(r)return r(n);e.prototype=n;var i=new e;return e.prototype=void 0,i}}();return fe=e}function $e(){if(pe)return le;return pe=1,le=function(t,r){return function(e){return t(r(e))}}}function Ge(){if(ve)return he;ve=1;var t=$e()(Object.getPrototypeOf,Object);return he=t}function Ue(){if(ge)return ye;ge=1;var t=Object.prototype;return ye=function(r){var e=r&&r.constructor;return r===("function"==typeof e&&e.prototype||t)}}function Be(){if(de)return be;de=1;var t=Je(),r=Ge(),e=Ue();return be=function(n){return"function"!=typeof n.constructor||e(n)?{}:t(r(n))}}function Le(){if(me)return _e;return me=1,_e=function(t){return null!=t&&"object"==typeof t}}function Me(){if(Pe)return je;Pe=1;var t=Pr(),r=Le();return je=function(e){return r(e)&&"[object Arguments]"==t(e)}}function We(){if(Oe)return we;Oe=1;var t=Me(),r=Le(),e=Object.prototype,n=e.hasOwnProperty,i=e.propertyIsEnumerable,o=t(function(){return arguments}())?t:function(t){return r(t)&&n.call(t,"callee")&&!i.call(t,"callee")};return we=o}function Ve(){if(Fe)return xe;Fe=1;var t=Array.isArray;return xe=t}function He(){if(ke)return Se;ke=1;return Se=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}}function Ke(){if(Ae)return Te;Ae=1;var t=Or(),r=He();return Te=function(e){return null!=e&&r(e.length)&&!t(e)}}function Qe(){if(Ne)return ze;Ne=1;var t=Ke(),r=Le();return ze=function(e){return r(e)&&t(e)}}var Xe,Ye,Ze,tn,rn,en,nn,on,un,an={exports:{}};function cn(){if(Ye)return Xe;return Ye=1,Xe=function(){return!1}}function fn(){return Ze||(Ze=1,function(t,r){var e=dr(),n=cn(),i=r&&!r.nodeType&&r,o=i&&t&&!t.nodeType&&t,u=o&&o.exports===i?e.Buffer:void 0,a=(u?u.isBuffer:void 0)||n;t.exports=a}(an,an.exports)),an.exports}function sn(){if(rn)return tn;rn=1;var t=Pr(),r=Ge(),e=Le(),n=Function.prototype,i=Object.prototype,o=n.toString,u=i.hasOwnProperty,a=o.call(Object);return tn=function(n){if(!e(n)||"[object Object]"!=t(n))return!1;var i=r(n);if(null===i)return!0;var c=u.call(i,"constructor")&&i.constructor;return"function"==typeof c&&c instanceof c&&o.call(c)==a}}function ln(){if(nn)return en;nn=1;var t=Pr(),r=He(),e=Le(),n={};return n["[object Float32Array]"]=n["[object Float64Array]"]=n["[object Int8Array]"]=n["[object Int16Array]"]=n["[object Int32Array]"]=n["[object Uint8Array]"]=n["[object Uint8ClampedArray]"]=n["[object Uint16Array]"]=n["[object Uint32Array]"]=!0,n["[object Arguments]"]=n["[object Array]"]=n["[object ArrayBuffer]"]=n["[object Boolean]"]=n["[object DataView]"]=n["[object Date]"]=n["[object Error]"]=n["[object Function]"]=n["[object Map]"]=n["[object Number]"]=n["[object Object]"]=n["[object RegExp]"]=n["[object Set]"]=n["[object String]"]=n["[object WeakMap]"]=!1,en=function(i){return e(i)&&r(i.length)&&!!n[t(i)]}}function pn(){if(un)return on;return un=1,on=function(t){return function(r){return t(r)}}}var hn,vn,yn,gn,bn,dn,_n,mn,jn,Pn,wn,On,xn,Fn,Sn,kn,Tn,An,zn,Nn,Rn,Cn,Dn,En,qn,In,Jn,$n,Gn,Un,Bn,Ln,Mn,Wn,Vn,Hn,Kn,Qn,Xn,Yn,Zn,ti,ri,ei,ni,ii,oi,ui,ai,ci={exports:{}};function fi(){return hn||(hn=1,function(t,r){var e=br(),n=r&&!r.nodeType&&r,i=n&&t&&!t.nodeType&&t,o=i&&i.exports===n&&e.process,u=function(){try{var t=i&&i.require&&i.require("util").types;return t||o&&o.binding&&o.binding("util")}catch(t){}}();t.exports=u}(ci,ci.exports)),ci.exports}function si(){if(yn)return vn;yn=1;var t=ln(),r=pn(),e=fi(),n=e&&e.isTypedArray,i=n?r(n):t;return vn=i}function li(){if(bn)return gn;return bn=1,gn=function(t,r){if(("constructor"!==r||"function"!=typeof t[r])&&"__proto__"!=r)return t[r]}}function pi(){if(_n)return dn;_n=1;var t=Qr(),r=ur(),e=Object.prototype.hasOwnProperty;return dn=function(n,i,o){var u=n[i];e.call(n,i)&&r(u,o)&&(void 0!==o||i in n)||t(n,i,o)}}function hi(){if(jn)return mn;jn=1;var t=pi(),r=Qr();return mn=function(e,n,i,o){var u=!i;i||(i={});for(var a=-1,c=n.length;++a<c;){var f=n[a],s=o?o(i[f],e[f],f,i,e):void 0;void 0===s&&(s=e[f]),u?r(i,f,s):t(i,f,s)}return i}}function vi(){if(wn)return Pn;return wn=1,Pn=function(t,r){for(var e=-1,n=Array(t);++e<t;)n[e]=r(e);return n}}function yi(){if(xn)return On;xn=1;var t=/^(?:0|[1-9]\d*)$/;return On=function(r,e){var n=typeof r;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&t.test(r))&&r>-1&&r%1==0&&r<e}}function gi(){if(Sn)return Fn;Sn=1;var t=vi(),r=We(),e=Ve(),n=fn(),i=yi(),o=si(),u=Object.prototype.hasOwnProperty;return Fn=function(a,c){var f=e(a),s=!f&&r(a),l=!f&&!s&&n(a),p=!f&&!s&&!l&&o(a),h=f||s||l||p,v=h?t(a.length,String):[],y=v.length;for(var g in a)!c&&!u.call(a,g)||h&&("length"==g||l&&("offset"==g||"parent"==g)||p&&("buffer"==g||"byteLength"==g||"byteOffset"==g)||i(g,y))||v.push(g);return v}}function bi(){if(Tn)return kn;return Tn=1,kn=function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}}function di(){if(zn)return An;zn=1;var t=wr(),r=Ue(),e=bi(),n=Object.prototype.hasOwnProperty;return An=function(i){if(!t(i))return e(i);var o=r(i),u=[];for(var a in i)("constructor"!=a||!o&&n.call(i,a))&&u.push(a);return u}}function _i(){if(Rn)return Nn;Rn=1;var t=gi(),r=di(),e=Ke();return Nn=function(n){return e(n)?t(n,!0):r(n)}}function mi(){if(Dn)return Cn;Dn=1;var t=hi(),r=_i();return Cn=function(e){return t(e,r(e))}}function ji(){if(qn)return En;qn=1;var t=Xr(),r=Ce(),e=qe(),n=Ie(),i=Be(),o=We(),u=Ve(),a=Qe(),c=fn(),f=Or(),s=wr(),l=sn(),p=si(),h=li(),v=mi();return En=function(y,g,b,d,_,m,j){var P=h(y,b),w=h(g,b),O=j.get(w);if(O)t(y,b,O);else{var x=m?m(P,w,b+"",y,g,j):void 0,F=void 0===x;if(F){var S=u(w),k=!S&&c(w),T=!S&&!k&&p(w);x=w,S||k||T?u(P)?x=P:a(P)?x=n(P):k?(F=!1,x=r(w,!0)):T?(F=!1,x=e(w,!0)):x=[]:l(w)||o(w)?(x=P,o(P)?x=v(P):s(P)&&!f(P)||(x=i(w))):F=!1}F&&(j.set(w,x),_(x,w,d,m,j),j.delete(w)),t(y,b,x)}}}function Pi(){if(Jn)return In;Jn=1;var t=Hr(),r=Xr(),e=Zr(),n=ji(),i=wr(),o=_i(),u=li();return In=function a(c,f,s,l,p){c!==f&&e(f,(function(e,o){if(p||(p=new t),i(e))n(c,f,o,s,a,l,p);else{var h=l?l(u(c,o),e,o+"",c,f,p):void 0;void 0===h&&(h=e),r(c,o,h)}}),o)},In}function wi(){if(Gn)return $n;return Gn=1,$n=function(t){return t}}function Oi(){if(Bn)return Un;return Bn=1,Un=function(t,r,e){switch(e.length){case 0:return t.call(r);case 1:return t.call(r,e[0]);case 2:return t.call(r,e[0],e[1]);case 3:return t.call(r,e[0],e[1],e[2])}return t.apply(r,e)}}function xi(){if(Mn)return Ln;Mn=1;var t=Oi(),r=Math.max;return Ln=function(e,n,i){return n=r(void 0===n?e.length-1:n,0),function(){for(var o=arguments,u=-1,a=r(o.length-n,0),c=Array(a);++u<a;)c[u]=o[n+u];u=-1;for(var f=Array(n+1);++u<n;)f[u]=o[u];return f[n]=i(c),t(e,this,f)}},Ln}function Fi(){if(Vn)return Wn;return Vn=1,Wn=function(t){return function(){return t}}}function Si(){if(Kn)return Hn;Kn=1;var t=Fi(),r=Kr();return Hn=r?function(e,n){return r(e,"toString",{configurable:!0,enumerable:!1,value:t(n),writable:!0})}:wi()}function ki(){if(Xn)return Qn;Xn=1;var t=Date.now;return Qn=function(r){var e=0,n=0;return function(){var i=t(),o=16-(i-n);if(n=i,o>0){if(++e>=800)return arguments[0]}else e=0;return r.apply(void 0,arguments)}},Qn}function Ti(){if(Zn)return Yn;Zn=1;var t=Si(),r=ki()(t);return Yn=r}function Ai(){if(ri)return ti;ri=1;var t=wi(),r=xi(),e=Ti();return ti=function(n,i){return e(r(n,i,t),n+"")}}function zi(){if(ni)return ei;ni=1;var t=ur(),r=Ke(),e=yi(),n=wr();return ei=function(i,o,u){if(!n(u))return!1;var a=typeof o;return!!("number"==a?r(u)&&e(o,u.length):"string"==a&&o in u)&&t(u[o],i)}}function Ni(){if(oi)return ii;oi=1;var t=Ai(),r=zi();return ii=function(e){return t((function(t,n){var i=-1,o=n.length,u=o>1?n[o-1]:void 0,a=o>2?n[2]:void 0;for(u=e.length>3&&"function"==typeof u?(o--,u):void 0,a&&r(n[0],n[1],a)&&(u=o<3?void 0:u,o=1),t=Object(t);++i<o;){var c=n[i];c&&e(t,c,i,u)}return t}))}}function Ri(){if(ai)return ui;ai=1;var t=Pi(),r=Ni()((function(r,e,n){t(r,e,n)}));return ui=r}var Ci=ir(Ri());class Di{constructor(){}isJSONFilePath(t){return t.endsWith(".json")||t.endsWith(".json.template")}isTemplateFilePath(t){return t.endsWith(".template")}getRealTemplateFilePath(t){return t.replace(".template","")}readFile(t){return i.readFileSync(t,"utf-8")}readJSONFile(t){return JSON.parse(this.readFile(t))}writeFile(t,r){i.writeFileSync(this.getRealTemplateFilePath(t),r,{encoding:"utf-8"})}replaceFile(t,r){let e=this.readFile(t);return Object.keys(r).forEach((t=>{const n=r[t];e=e.replace(new RegExp(`\\[TPL:${t}\\]`,"g"),"string"==typeof n?n:JSON.stringify(n))})),e}mergeJSONFile(t,r){const e=this.readJSONFile(t),n=Ci(r,e);this.writeFile(t,JSON.stringify(n,null,2))}composeConfigFile(t,r,e){if(this.isTemplateFilePath(r)){const n=this.replaceFile(r,t);if(this.isJSONFilePath(r)&&this.isJSONFilePath(e)){const t=this.getRealTemplateFilePath(e);return i.existsSync(t)?(this.mergeJSONFile(t,JSON.parse(n)),!0):(this.writeFile(t,n),!0)}return this.writeFile(e,n),!0}return!1}}const Ei=["pack-app"];exports.Copyer=p,exports.Generator=class{ora;context;subPackages;copyer;compose;constructor(r){const o=r.options?.templateRootPath;if(!o)throw new Error("template path not exit");if(!i.existsSync(o))throw new Error("template path not exit");this.ora=n.oraPromise,this.context=new t.FeScriptContext(r),this.subPackages=["node-lib","react-app"],this.copyer=new p(e.join(this.context.options.configsRootPath,"_common")),this.compose=new Di}get logger(){return this.context.logger}async steps(t){try{return await r.prompt(t)}catch(t){throw this.logger.error(t),t}}async action({label:t,task:r}){let e=r();e instanceof Promise||(e=Promise.resolve(e));const n=t;return this.ora(e,n),e}isPackageTemplate(t){return Ei.includes(t)}async getGeneratorContext(){const t=a(this.subPackages,Ei),r=await this.steps(t);if(this.isPackageTemplate(r.template)){const t=c(this.subPackages),e=await this.steps(t);Object.assign(r,e)}return r.targetPath=e.join(process.cwd(),r.projectName),r.releasePath=r.releasePath||"src",r}async generate(){const t=await this.getGeneratorContext();this.logger.debug("context is:",t,this.context.options.templateRootPath),t.subPackages?await this.action({label:"Generate Directories(subPackages)",task:async()=>{await this.generateTemplateDir(t),await this.generateSubPackages(t),await this.generateConfigs(t,t.targetPath,"_common")}}):await this.action({label:"Generate Directory",task:async()=>{await this.generateTemplateDir(t),await this.generateConfigs(t,t.targetPath,"_common"),await this.generateConfigs(t,t.targetPath,t.template)}})}async generateConfigs(t,r,n){const{configsRootPath:i,config:o}=this.context.options;o?await this.copyer.copyPaths({sourcePath:e.join(i,n),targetPath:r,copyCallback:(r,e)=>(this.logger.debug("copyCallback",r,e),this.compose.composeConfigFile(t,r,e))}):this.logger.debug("no copy config files")}generateTemplateDir(t){return this.copyer.copyPaths({sourcePath:e.join(this.context.options.templateRootPath,t.template),targetPath:t.targetPath})}async generateSubPackages(t){const{packagesNames:r="packages",subPackages:n=[],targetPath:i=""}=t,{templateRootPath:o}=this.context.options;for(const t of n){const n=e.join(o,t),u=e.join(i,r,t);this.logger.debug("copy sub package",n,u),await this.copyer.copyPaths({sourcePath:n,targetPath:u})}}},exports.createDefaultPrompts=a,exports.createPackagePrompts=c,exports.validRequiredString=u;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -19,11 +19,11 @@ type GeneratorOptions = {
|
|
|
19
19
|
*/
|
|
20
20
|
config?: boolean;
|
|
21
21
|
};
|
|
22
|
-
interface
|
|
22
|
+
interface GeneratorContext extends GeneratorOptions {
|
|
23
23
|
/**
|
|
24
24
|
* project name
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
projectName: string;
|
|
27
27
|
/**
|
|
28
28
|
* choose template name
|
|
29
29
|
*
|
|
@@ -45,10 +45,15 @@ interface GeneratorRuntimes extends GeneratorOptions {
|
|
|
45
45
|
* @default `./`
|
|
46
46
|
*/
|
|
47
47
|
targetPath?: string;
|
|
48
|
+
/**
|
|
49
|
+
* release path
|
|
50
|
+
* @default `src`
|
|
51
|
+
*/
|
|
52
|
+
releasePath?: string;
|
|
48
53
|
}
|
|
49
54
|
type TaskOptions = {
|
|
50
55
|
templateFiles: TemplateFile[];
|
|
51
|
-
result:
|
|
56
|
+
result: GeneratorContext;
|
|
52
57
|
};
|
|
53
58
|
type TemplateFile = {
|
|
54
59
|
path: string;
|
|
@@ -60,19 +65,20 @@ declare class Generator {
|
|
|
60
65
|
protected context: FeScriptContext<GeneratorOptions>;
|
|
61
66
|
private subPackages;
|
|
62
67
|
private copyer;
|
|
68
|
+
private compose;
|
|
63
69
|
constructor(context: Partial<FeScriptContext<GeneratorOptions>>);
|
|
64
70
|
get logger(): Logger;
|
|
65
|
-
steps(prompts: GeneratorPrompt[]): Promise<
|
|
71
|
+
steps(prompts: GeneratorPrompt[]): Promise<GeneratorContext>;
|
|
66
72
|
action({ label, task }: {
|
|
67
73
|
label: string;
|
|
68
74
|
task: (() => Promise<unknown>) | (() => unknown);
|
|
69
75
|
}): Promise<unknown>;
|
|
70
76
|
private isPackageTemplate;
|
|
71
|
-
private
|
|
72
|
-
private copyConfigs;
|
|
77
|
+
private getGeneratorContext;
|
|
73
78
|
generate(): Promise<void>;
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
generateConfigs(context: GeneratorContext, targetPath: string, configName: string): Promise<void>;
|
|
80
|
+
generateTemplateDir(context: GeneratorContext): Promise<void>;
|
|
81
|
+
generateSubPackages(context: GeneratorContext): Promise<void>;
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
declare const validRequiredString: (value: string, key: string) => string | true;
|
|
@@ -86,7 +92,6 @@ declare class Copyer {
|
|
|
86
92
|
static IGNORE_FILE: string;
|
|
87
93
|
constructor(ignoreTargetPath: string, ignoreFile?: string);
|
|
88
94
|
getIg(targetDir?: string): ignore.Ignore | undefined;
|
|
89
|
-
ensureDir(dir: string): void;
|
|
90
95
|
/**
|
|
91
96
|
* Asynchronously copy files from source to target directory.
|
|
92
97
|
* @param {string} sourcePath - Source directory.
|
|
@@ -104,4 +109,4 @@ declare class Copyer {
|
|
|
104
109
|
}): Promise<void>;
|
|
105
110
|
}
|
|
106
111
|
|
|
107
|
-
export { type CopyCallback, Copyer, Generator, type
|
|
112
|
+
export { type CopyCallback, Copyer, Generator, type GeneratorContext, type GeneratorOptions, type GeneratorPrompt, type TaskOptions, type TemplateFile, createDefaultPrompts, createPackagePrompts, validRequiredString };
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FeScriptContext as t}from"@qlover/scripts-context";import e from"inquirer";import{join as a,dirname as s}from"path";import{oraPromise as o}from"ora";import{existsSync as i,readFileSync as r,mkdirSync as c,promises as n}from"fs";import g from"ignore";const h=(t,e)=>"string"==typeof t&&""!==t.trim()||`${e} is required`;function p(t,e){return[{type:"input",name:"name",message:"Project name",validate:t=>h(t,"Project name")},{type:"list",name:"template",message:"Template name",choices:[...t,...e]}]}function l(t){return[{type:"checkbox",name:"subPackages",message:"Sub package names",choices:t}]}const{copyFile:m,stat:u}=n;class P{ignoreTargetPath;ignoreFile;static IGNORE_FILE=".gitignore.template";constructor(t,e=P.IGNORE_FILE){this.ignoreTargetPath=t,this.ignoreFile=e}getIg(t=this.ignoreTargetPath){const e=a(t,this.ignoreFile);if(!i(e))return;const s=r(e,"utf8").split("\n").map((t=>t.trim())).filter((t=>t&&!t.startsWith("#")));return g().add(s)}ensureDir(t){i(t)||c(t,{recursive:!0})}async copyFiles(t,e,o,i){const r=await n.readdir(t);await Promise.all(r.map((async r=>{const c=a(t,r),n=a(e,r);if(o&&o.ignores(r))return;this.ensureDir(s(n));if((await u(c)).isDirectory())await this.copyFiles(c,n,o);else{if(i&&await i(c,n))return;await m(c,n)}})))}copyPaths({sourcePath:t,targetPath:e,copyCallback:a}){this.ensureDir(e);const s=this.getIg();return this.copyFiles(t,e,s,a)}}const y=["pack-app"];class f{ora;context;subPackages;copyer;constructor(e){const s=e.options?.templateRootPath;if(!s)throw new Error("template path not exit");if(!i(s))throw new Error("template path not exit");this.ora=o,this.context=new t(e),this.subPackages=["node-lib","react-app"],this.copyer=new P(a(this.context.options.configsRootPath,"_common"))}get logger(){return this.context.logger}async steps(t){try{return await e.prompt(t)}catch(t){throw this.logger.error(t),t}}async action({label:t,task:e}){let a=e();a instanceof Promise||(a=Promise.resolve(a));const s=t;return this.ora(a,s),a}isPackageTemplate(t){return y.includes(t)}async getGeneratorResult(){const t=p(this.subPackages,y),e=await this.steps(t);if(this.isPackageTemplate(e.template)){const t=l(this.subPackages),a=await this.steps(t);Object.assign(e,a)}return e}async copyConfigs(t,e){const{configsRootPath:s,config:o}=this.context.options;o?await this.copyer.copyPaths({sourcePath:a(s,e),targetPath:t,copyCallback:(t,e)=>(this.logger.debug("copyCallback",t,e),!1)}):this.logger.debug("no copy config files")}async generate(){const t=await this.getGeneratorResult();t.targetPath=a(process.cwd(),t.name),this.logger.debug("result is:",t,this.context.options.templateRootPath),t.subPackages?await this.action({label:"Generate Directories(subPackages)",task:async()=>{await this.generateTemplateDir(t),await this.generateSubPackages(t),await this.copyConfigs(t.targetPath,"_common")}}):await this.action({label:"Generate Directory",task:async()=>{await this.generateTemplateDir(t),await this.copyConfigs(t.targetPath,"_common"),await this.copyConfigs(t.targetPath,t.template)}})}generateTemplateDir(t){return this.copyer.copyPaths({sourcePath:a(this.context.options.templateRootPath,t.template),targetPath:t.targetPath})}async generateSubPackages(t){const{packagesNames:e="packages",subPackages:s=[],targetPath:o=""}=t,{templateRootPath:i}=this.context.options;for(const t of s){const s=a(i,t),r=a(o,e,t);this.logger.debug("copy sub package",s,r),await this.copyer.copyPaths({sourcePath:s,targetPath:r})}}}export{P as Copyer,f as Generator,p as createDefaultPrompts,l as createPackagePrompts,h as validRequiredString};
|
|
1
|
+
import{FeScriptContext as t}from"@qlover/scripts-context";import r from"inquirer";import{join as e,dirname as n}from"path";import{oraPromise as i}from"ora";import{existsSync as o,mkdirSync as u,readFileSync as a,promises as c,writeFileSync as f}from"fs";import s from"ignore";const l=(t,r)=>"string"==typeof t&&""!==t.trim()||`${r} is required`;function p(t,r){return[{type:"input",name:"projectName",message:"Project name",validate:t=>l(t,"Project name")},{type:"list",name:"template",message:"Template name",choices:[...t,...r]}]}function h(t){return[{type:"checkbox",name:"subPackages",message:"Sub package names",choices:t}]}class v{static ensureDir(t){o(t)||u(t,{recursive:!0})}}const{copyFile:g,stat:y}=c;class b{ignoreTargetPath;ignoreFile;static IGNORE_FILE=".gitignore.template";constructor(t,r=b.IGNORE_FILE){this.ignoreTargetPath=t,this.ignoreFile=r}getIg(t=this.ignoreTargetPath){const r=e(t,this.ignoreFile);if(!o(r))return;const n=a(r,"utf8").split("\n").map((t=>t.trim())).filter((t=>t&&!t.startsWith("#")));return s().add(n)}async copyFiles(t,r,i,o){const u=await c.readdir(t);await Promise.all(u.map((async u=>{const a=e(t,u),c=e(r,u);if(i&&i.ignores(u))return;v.ensureDir(n(c));if((await y(a)).isDirectory())await this.copyFiles(a,c,i,o);else{if(o&&await o(a,c))return;await g(a,c)}})))}copyPaths({sourcePath:t,targetPath:r,copyCallback:e}){v.ensureDir(r);const n=this.getIg();return this.copyFiles(t,r,n,e)}}var _,d,m,j,P,w,O,F,x,k,S,T,A,z,N,R,C,E,D,I,J,$,G,U,q,B,L,M,W,V,H,K,Q,X,Y,Z,tt,rt,et,nt,it,ot,ut,at,ct,ft,st,lt,pt,ht,vt,gt,yt,bt,_t,dt,mt,jt,Pt,wt,Ot,Ft,xt,kt,St,Tt,At,zt,Nt,Rt,Ct,Et,Dt,It,Jt,$t,Gt,Ut,qt,Bt,Lt,Mt,Wt,Vt,Ht,Kt,Qt,Xt,Yt,Zt,tr,rr,er,nr,ir,or,ur,ar,cr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function fr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function sr(){if(d)return _;return d=1,_=function(){this.__data__=[],this.size=0}}function lr(){if(j)return m;return j=1,m=function(t,r){return t===r||t!=t&&r!=r}}function pr(){if(w)return P;w=1;var t=lr();return P=function(r,e){for(var n=r.length;n--;)if(t(r[n][0],e))return n;return-1}}function hr(){if(F)return O;F=1;var t=pr(),r=Array.prototype.splice;return O=function(e){var n=this.__data__,i=t(n,e);return!(i<0)&&(i==n.length-1?n.pop():r.call(n,i,1),--this.size,!0)}}function vr(){if(k)return x;k=1;var t=pr();return x=function(r){var e=this.__data__,n=t(e,r);return n<0?void 0:e[n][1]}}function gr(){if(T)return S;T=1;var t=pr();return S=function(r){return t(this.__data__,r)>-1}}function yr(){if(z)return A;z=1;var t=pr();return A=function(r,e){var n=this.__data__,i=t(n,r);return i<0?(++this.size,n.push([r,e])):n[i][1]=e,this}}function br(){if(R)return N;R=1;var t=sr(),r=hr(),e=vr(),n=gr(),i=yr();function o(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}return o.prototype.clear=t,o.prototype.delete=r,o.prototype.get=e,o.prototype.has=n,o.prototype.set=i,N=o}function _r(){if(E)return C;E=1;var t=br();return C=function(){this.__data__=new t,this.size=0}}function dr(){if(I)return D;return I=1,D=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e}}function mr(){if($)return J;return $=1,J=function(t){return this.__data__.get(t)}}function jr(){if(U)return G;return U=1,G=function(t){return this.__data__.has(t)}}function Pr(){if(B)return q;B=1;var t="object"==typeof cr&&cr&&cr.Object===Object&&cr;return q=t}function wr(){if(M)return L;M=1;var t=Pr(),r="object"==typeof self&&self&&self.Object===Object&&self,e=t||r||Function("return this")();return L=e}function Or(){if(V)return W;V=1;var t=wr().Symbol;return W=t}function Fr(){if(K)return H;K=1;var t=Or(),r=Object.prototype,e=r.hasOwnProperty,n=r.toString,i=t?t.toStringTag:void 0;return H=function(t){var r=e.call(t,i),o=t[i];try{t[i]=void 0;var u=!0}catch(t){}var a=n.call(t);return u&&(r?t[i]=o:delete t[i]),a}}function xr(){if(X)return Q;X=1;var t=Object.prototype.toString;return Q=function(r){return t.call(r)}}function kr(){if(Z)return Y;Z=1;var t=Or(),r=Fr(),e=xr(),n=t?t.toStringTag:void 0;return Y=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":n&&n in Object(t)?r(t):e(t)}}function Sr(){if(rt)return tt;return rt=1,tt=function(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)}}function Tr(){if(nt)return et;nt=1;var t=kr(),r=Sr();return et=function(e){if(!r(e))return!1;var n=t(e);return"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n}}function Ar(){if(ot)return it;ot=1;var t=wr()["__core-js_shared__"];return it=t}function zr(){if(at)return ut;at=1;var t,r=Ar(),e=(t=/[^.]+$/.exec(r&&r.keys&&r.keys.IE_PROTO||""))?"Symbol(src)_1."+t:"";return ut=function(t){return!!e&&e in t}}function Nr(){if(ft)return ct;ft=1;var t=Function.prototype.toString;return ct=function(r){if(null!=r){try{return t.call(r)}catch(t){}try{return r+""}catch(t){}}return""}}function Rr(){if(lt)return st;lt=1;var t=Tr(),r=zr(),e=Sr(),n=Nr(),i=/^\[object .+?Constructor\]$/,o=Function.prototype,u=Object.prototype,a=o.toString,c=u.hasOwnProperty,f=RegExp("^"+a.call(c).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");return st=function(o){return!(!e(o)||r(o))&&(t(o)?f:i).test(n(o))}}function Cr(){if(ht)return pt;return ht=1,pt=function(t,r){return null==t?void 0:t[r]}}function Er(){if(gt)return vt;gt=1;var t=Rr(),r=Cr();return vt=function(e,n){var i=r(e,n);return t(i)?i:void 0}}function Dr(){if(bt)return yt;bt=1;var t=Er()(wr(),"Map");return yt=t}function Ir(){if(dt)return _t;dt=1;var t=Er()(Object,"create");return _t=t}function Jr(){if(jt)return mt;jt=1;var t=Ir();return mt=function(){this.__data__=t?t(null):{},this.size=0}}function $r(){if(wt)return Pt;return wt=1,Pt=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}}function Gr(){if(Ft)return Ot;Ft=1;var t=Ir(),r=Object.prototype.hasOwnProperty;return Ot=function(e){var n=this.__data__;if(t){var i=n[e];return"__lodash_hash_undefined__"===i?void 0:i}return r.call(n,e)?n[e]:void 0}}function Ur(){if(kt)return xt;kt=1;var t=Ir(),r=Object.prototype.hasOwnProperty;return xt=function(e){var n=this.__data__;return t?void 0!==n[e]:r.call(n,e)}}function qr(){if(Tt)return St;Tt=1;var t=Ir();return St=function(r,e){var n=this.__data__;return this.size+=this.has(r)?0:1,n[r]=t&&void 0===e?"__lodash_hash_undefined__":e,this}}function Br(){if(zt)return At;zt=1;var t=Jr(),r=$r(),e=Gr(),n=Ur(),i=qr();function o(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}return o.prototype.clear=t,o.prototype.delete=r,o.prototype.get=e,o.prototype.has=n,o.prototype.set=i,At=o}function Lr(){if(Rt)return Nt;Rt=1;var t=Br(),r=br(),e=Dr();return Nt=function(){this.size=0,this.__data__={hash:new t,map:new(e||r),string:new t}}}function Mr(){if(Et)return Ct;return Et=1,Ct=function(t){var r=typeof t;return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t}}function Wr(){if(It)return Dt;It=1;var t=Mr();return Dt=function(r,e){var n=r.__data__;return t(e)?n["string"==typeof e?"string":"hash"]:n.map}}function Vr(){if($t)return Jt;$t=1;var t=Wr();return Jt=function(r){var e=t(this,r).delete(r);return this.size-=e?1:0,e}}function Hr(){if(Ut)return Gt;Ut=1;var t=Wr();return Gt=function(r){return t(this,r).get(r)}}function Kr(){if(Bt)return qt;Bt=1;var t=Wr();return qt=function(r){return t(this,r).has(r)}}function Qr(){if(Mt)return Lt;Mt=1;var t=Wr();return Lt=function(r,e){var n=t(this,r),i=n.size;return n.set(r,e),this.size+=n.size==i?0:1,this}}function Xr(){if(Vt)return Wt;Vt=1;var t=Lr(),r=Vr(),e=Hr(),n=Kr(),i=Qr();function o(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}return o.prototype.clear=t,o.prototype.delete=r,o.prototype.get=e,o.prototype.has=n,o.prototype.set=i,Wt=o}function Yr(){if(Kt)return Ht;Kt=1;var t=br(),r=Dr(),e=Xr();return Ht=function(n,i){var o=this.__data__;if(o instanceof t){var u=o.__data__;if(!r||u.length<199)return u.push([n,i]),this.size=++o.size,this;o=this.__data__=new e(u)}return o.set(n,i),this.size=o.size,this}}function Zr(){if(Xt)return Qt;Xt=1;var t=br(),r=_r(),e=dr(),n=mr(),i=jr(),o=Yr();function u(r){var e=this.__data__=new t(r);this.size=e.size}return u.prototype.clear=r,u.prototype.delete=e,u.prototype.get=n,u.prototype.has=i,u.prototype.set=o,Qt=u}function te(){if(Zt)return Yt;Zt=1;var t=Er(),r=function(){try{var r=t(Object,"defineProperty");return r({},"",{}),r}catch(t){}}();return Yt=r}function re(){if(rr)return tr;rr=1;var t=te();return tr=function(r,e,n){"__proto__"==e&&t?t(r,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):r[e]=n}}function ee(){if(nr)return er;nr=1;var t=re(),r=lr();return er=function(e,n,i){(void 0!==i&&!r(e[n],i)||void 0===i&&!(n in e))&&t(e,n,i)}}function ne(){if(or)return ir;return or=1,ir=function(t){return function(r,e,n){for(var i=-1,o=Object(r),u=n(r),a=u.length;a--;){var c=u[t?a:++i];if(!1===e(o[c],c,o))break}return r}}}function ie(){if(ar)return ur;ar=1;var t=ne()();return ur=t}var oe,ue,ae,ce,fe,se,le,pe,he,ve,ge,ye,be,_e,de,me,je,Pe,we,Oe,Fe,xe,ke,Se,Te,Ae,ze,Ne,Re,Ce,Ee,De,Ie,Je={exports:{}};function $e(){return oe||(oe=1,t=Je,r=Je.exports,e=wr(),n=r&&!r.nodeType&&r,i=n&&t&&!t.nodeType&&t,o=i&&i.exports===n?e.Buffer:void 0,u=o?o.allocUnsafe:void 0,t.exports=function(t,r){if(r)return t.slice();var e=t.length,n=u?u(e):new t.constructor(e);return t.copy(n),n}),Je.exports;var t,r,e,n,i,o,u}function Ge(){if(ae)return ue;ae=1;var t=wr().Uint8Array;return ue=t}function Ue(){if(fe)return ce;fe=1;var t=Ge();return ce=function(r){var e=new r.constructor(r.byteLength);return new t(e).set(new t(r)),e}}function qe(){if(le)return se;le=1;var t=Ue();return se=function(r,e){var n=e?t(r.buffer):r.buffer;return new r.constructor(n,r.byteOffset,r.length)}}function Be(){if(he)return pe;return he=1,pe=function(t,r){var e=-1,n=t.length;for(r||(r=Array(n));++e<n;)r[e]=t[e];return r}}function Le(){if(ge)return ve;ge=1;var t=Sr(),r=Object.create,e=function(){function e(){}return function(n){if(!t(n))return{};if(r)return r(n);e.prototype=n;var i=new e;return e.prototype=void 0,i}}();return ve=e}function Me(){if(be)return ye;return be=1,ye=function(t,r){return function(e){return t(r(e))}}}function We(){if(de)return _e;de=1;var t=Me()(Object.getPrototypeOf,Object);return _e=t}function Ve(){if(je)return me;je=1;var t=Object.prototype;return me=function(r){var e=r&&r.constructor;return r===("function"==typeof e&&e.prototype||t)}}function He(){if(we)return Pe;we=1;var t=Le(),r=We(),e=Ve();return Pe=function(n){return"function"!=typeof n.constructor||e(n)?{}:t(r(n))}}function Ke(){if(Fe)return Oe;return Fe=1,Oe=function(t){return null!=t&&"object"==typeof t}}function Qe(){if(ke)return xe;ke=1;var t=kr(),r=Ke();return xe=function(e){return r(e)&&"[object Arguments]"==t(e)}}function Xe(){if(Te)return Se;Te=1;var t=Qe(),r=Ke(),e=Object.prototype,n=e.hasOwnProperty,i=e.propertyIsEnumerable,o=t(function(){return arguments}())?t:function(t){return r(t)&&n.call(t,"callee")&&!i.call(t,"callee")};return Se=o}function Ye(){if(ze)return Ae;ze=1;var t=Array.isArray;return Ae=t}function Ze(){if(Re)return Ne;Re=1;return Ne=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}}function tn(){if(Ee)return Ce;Ee=1;var t=Tr(),r=Ze();return Ce=function(e){return null!=e&&r(e.length)&&!t(e)}}function rn(){if(Ie)return De;Ie=1;var t=tn(),r=Ke();return De=function(e){return r(e)&&t(e)}}var en,nn,on,un,an,cn,fn,sn,ln,pn={exports:{}};function hn(){if(nn)return en;return nn=1,en=function(){return!1}}function vn(){return on||(on=1,function(t,r){var e=wr(),n=hn(),i=r&&!r.nodeType&&r,o=i&&t&&!t.nodeType&&t,u=o&&o.exports===i?e.Buffer:void 0,a=(u?u.isBuffer:void 0)||n;t.exports=a}(pn,pn.exports)),pn.exports}function gn(){if(an)return un;an=1;var t=kr(),r=We(),e=Ke(),n=Function.prototype,i=Object.prototype,o=n.toString,u=i.hasOwnProperty,a=o.call(Object);return un=function(n){if(!e(n)||"[object Object]"!=t(n))return!1;var i=r(n);if(null===i)return!0;var c=u.call(i,"constructor")&&i.constructor;return"function"==typeof c&&c instanceof c&&o.call(c)==a}}function yn(){if(fn)return cn;fn=1;var t=kr(),r=Ze(),e=Ke(),n={};return n["[object Float32Array]"]=n["[object Float64Array]"]=n["[object Int8Array]"]=n["[object Int16Array]"]=n["[object Int32Array]"]=n["[object Uint8Array]"]=n["[object Uint8ClampedArray]"]=n["[object Uint16Array]"]=n["[object Uint32Array]"]=!0,n["[object Arguments]"]=n["[object Array]"]=n["[object ArrayBuffer]"]=n["[object Boolean]"]=n["[object DataView]"]=n["[object Date]"]=n["[object Error]"]=n["[object Function]"]=n["[object Map]"]=n["[object Number]"]=n["[object Object]"]=n["[object RegExp]"]=n["[object Set]"]=n["[object String]"]=n["[object WeakMap]"]=!1,cn=function(i){return e(i)&&r(i.length)&&!!n[t(i)]}}function bn(){if(ln)return sn;return ln=1,sn=function(t){return function(r){return t(r)}}}var _n,dn,mn,jn,Pn,wn,On,Fn,xn,kn,Sn,Tn,An,zn,Nn,Rn,Cn,En,Dn,In,Jn,$n,Gn,Un,qn,Bn,Ln,Mn,Wn,Vn,Hn,Kn,Qn,Xn,Yn,Zn,ti,ri,ei,ni,ii,oi,ui,ai,ci,fi,si,li,pi,hi={exports:{}};function vi(){return _n||(_n=1,t=hi,r=hi.exports,e=Pr(),n=r&&!r.nodeType&&r,i=n&&t&&!t.nodeType&&t,o=i&&i.exports===n&&e.process,u=function(){try{var t=i&&i.require&&i.require("util").types;return t||o&&o.binding&&o.binding("util")}catch(t){}}(),t.exports=u),hi.exports;var t,r,e,n,i,o,u}function gi(){if(mn)return dn;mn=1;var t=yn(),r=bn(),e=vi(),n=e&&e.isTypedArray,i=n?r(n):t;return dn=i}function yi(){if(Pn)return jn;return Pn=1,jn=function(t,r){if(("constructor"!==r||"function"!=typeof t[r])&&"__proto__"!=r)return t[r]}}function bi(){if(On)return wn;On=1;var t=re(),r=lr(),e=Object.prototype.hasOwnProperty;return wn=function(n,i,o){var u=n[i];e.call(n,i)&&r(u,o)&&(void 0!==o||i in n)||t(n,i,o)}}function _i(){if(xn)return Fn;xn=1;var t=bi(),r=re();return Fn=function(e,n,i,o){var u=!i;i||(i={});for(var a=-1,c=n.length;++a<c;){var f=n[a],s=o?o(i[f],e[f],f,i,e):void 0;void 0===s&&(s=e[f]),u?r(i,f,s):t(i,f,s)}return i}}function di(){if(Sn)return kn;return Sn=1,kn=function(t,r){for(var e=-1,n=Array(t);++e<t;)n[e]=r(e);return n}}function mi(){if(An)return Tn;An=1;var t=/^(?:0|[1-9]\d*)$/;return Tn=function(r,e){var n=typeof r;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&t.test(r))&&r>-1&&r%1==0&&r<e}}function ji(){if(Nn)return zn;Nn=1;var t=di(),r=Xe(),e=Ye(),n=vn(),i=mi(),o=gi(),u=Object.prototype.hasOwnProperty;return zn=function(a,c){var f=e(a),s=!f&&r(a),l=!f&&!s&&n(a),p=!f&&!s&&!l&&o(a),h=f||s||l||p,v=h?t(a.length,String):[],g=v.length;for(var y in a)!c&&!u.call(a,y)||h&&("length"==y||l&&("offset"==y||"parent"==y)||p&&("buffer"==y||"byteLength"==y||"byteOffset"==y)||i(y,g))||v.push(y);return v}}function Pi(){if(Cn)return Rn;return Cn=1,Rn=function(t){var r=[];if(null!=t)for(var e in Object(t))r.push(e);return r}}function wi(){if(Dn)return En;Dn=1;var t=Sr(),r=Ve(),e=Pi(),n=Object.prototype.hasOwnProperty;return En=function(i){if(!t(i))return e(i);var o=r(i),u=[];for(var a in i)("constructor"!=a||!o&&n.call(i,a))&&u.push(a);return u}}function Oi(){if(Jn)return In;Jn=1;var t=ji(),r=wi(),e=tn();return In=function(n){return e(n)?t(n,!0):r(n)}}function Fi(){if(Gn)return $n;Gn=1;var t=_i(),r=Oi();return $n=function(e){return t(e,r(e))}}function xi(){if(qn)return Un;qn=1;var t=ee(),r=$e(),e=qe(),n=Be(),i=He(),o=Xe(),u=Ye(),a=rn(),c=vn(),f=Tr(),s=Sr(),l=gn(),p=gi(),h=yi(),v=Fi();return Un=function(g,y,b,_,d,m,j){var P=h(g,b),w=h(y,b),O=j.get(w);if(O)t(g,b,O);else{var F=m?m(P,w,b+"",g,y,j):void 0,x=void 0===F;if(x){var k=u(w),S=!k&&c(w),T=!k&&!S&&p(w);F=w,k||S||T?u(P)?F=P:a(P)?F=n(P):S?(x=!1,F=r(w,!0)):T?(x=!1,F=e(w,!0)):F=[]:l(w)||o(w)?(F=P,o(P)?F=v(P):s(P)&&!f(P)||(F=i(w))):x=!1}x&&(j.set(w,F),d(F,w,_,m,j),j.delete(w)),t(g,b,F)}}}function ki(){if(Ln)return Bn;Ln=1;var t=Zr(),r=ee(),e=ie(),n=xi(),i=Sr(),o=Oi(),u=yi();return Bn=function a(c,f,s,l,p){c!==f&&e(f,(function(e,o){if(p||(p=new t),i(e))n(c,f,o,s,a,l,p);else{var h=l?l(u(c,o),e,o+"",c,f,p):void 0;void 0===h&&(h=e),r(c,o,h)}}),o)},Bn}function Si(){if(Wn)return Mn;return Wn=1,Mn=function(t){return t}}function Ti(){if(Hn)return Vn;return Hn=1,Vn=function(t,r,e){switch(e.length){case 0:return t.call(r);case 1:return t.call(r,e[0]);case 2:return t.call(r,e[0],e[1]);case 3:return t.call(r,e[0],e[1],e[2])}return t.apply(r,e)}}function Ai(){if(Qn)return Kn;Qn=1;var t=Ti(),r=Math.max;return Kn=function(e,n,i){return n=r(void 0===n?e.length-1:n,0),function(){for(var o=arguments,u=-1,a=r(o.length-n,0),c=Array(a);++u<a;)c[u]=o[n+u];u=-1;for(var f=Array(n+1);++u<n;)f[u]=o[u];return f[n]=i(c),t(e,this,f)}},Kn}function zi(){if(Yn)return Xn;return Yn=1,Xn=function(t){return function(){return t}}}function Ni(){if(ti)return Zn;ti=1;var t=zi(),r=te();return Zn=r?function(e,n){return r(e,"toString",{configurable:!0,enumerable:!1,value:t(n),writable:!0})}:Si()}function Ri(){if(ei)return ri;ei=1;var t=Date.now;return ri=function(r){var e=0,n=0;return function(){var i=t(),o=16-(i-n);if(n=i,o>0){if(++e>=800)return arguments[0]}else e=0;return r.apply(void 0,arguments)}},ri}function Ci(){if(ii)return ni;ii=1;var t=Ni(),r=Ri()(t);return ni=r}function Ei(){if(ui)return oi;ui=1;var t=Si(),r=Ai(),e=Ci();return oi=function(n,i){return e(r(n,i,t),n+"")}}function Di(){if(ci)return ai;ci=1;var t=lr(),r=tn(),e=mi(),n=Sr();return ai=function(i,o,u){if(!n(u))return!1;var a=typeof o;return!!("number"==a?r(u)&&e(o,u.length):"string"==a&&o in u)&&t(u[o],i)}}function Ii(){if(si)return fi;si=1;var t=Ei(),r=Di();return fi=function(e){return t((function(t,n){var i=-1,o=n.length,u=o>1?n[o-1]:void 0,a=o>2?n[2]:void 0;for(u=e.length>3&&"function"==typeof u?(o--,u):void 0,a&&r(n[0],n[1],a)&&(u=o<3?void 0:u,o=1),t=Object(t);++i<o;){var c=n[i];c&&e(t,c,i,u)}return t}))}}function Ji(){if(pi)return li;pi=1;var t=ki(),r=Ii()((function(r,e,n){t(r,e,n)}));return li=r}var $i=fr(Ji());class Gi{constructor(){}isJSONFilePath(t){return t.endsWith(".json")||t.endsWith(".json.template")}isTemplateFilePath(t){return t.endsWith(".template")}getRealTemplateFilePath(t){return t.replace(".template","")}readFile(t){return a(t,"utf-8")}readJSONFile(t){return JSON.parse(this.readFile(t))}writeFile(t,r){f(this.getRealTemplateFilePath(t),r,{encoding:"utf-8"})}replaceFile(t,r){let e=this.readFile(t);return Object.keys(r).forEach((t=>{const n=r[t];e=e.replace(new RegExp(`\\[TPL:${t}\\]`,"g"),"string"==typeof n?n:JSON.stringify(n))})),e}mergeJSONFile(t,r){const e=this.readJSONFile(t),n=$i(r,e);this.writeFile(t,JSON.stringify(n,null,2))}composeConfigFile(t,r,e){if(this.isTemplateFilePath(r)){const n=this.replaceFile(r,t);if(this.isJSONFilePath(r)&&this.isJSONFilePath(e)){const t=this.getRealTemplateFilePath(e);return o(t)?(this.mergeJSONFile(t,JSON.parse(n)),!0):(this.writeFile(t,n),!0)}return this.writeFile(e,n),!0}return!1}}const Ui=["pack-app"];class qi{ora;context;subPackages;copyer;compose;constructor(r){const n=r.options?.templateRootPath;if(!n)throw new Error("template path not exit");if(!o(n))throw new Error("template path not exit");this.ora=i,this.context=new t(r),this.subPackages=["node-lib","react-app"],this.copyer=new b(e(this.context.options.configsRootPath,"_common")),this.compose=new Gi}get logger(){return this.context.logger}async steps(t){try{return await r.prompt(t)}catch(t){throw this.logger.error(t),t}}async action({label:t,task:r}){let e=r();e instanceof Promise||(e=Promise.resolve(e));const n=t;return this.ora(e,n),e}isPackageTemplate(t){return Ui.includes(t)}async getGeneratorContext(){const t=p(this.subPackages,Ui),r=await this.steps(t);if(this.isPackageTemplate(r.template)){const t=h(this.subPackages),e=await this.steps(t);Object.assign(r,e)}return r.targetPath=e(process.cwd(),r.projectName),r.releasePath=r.releasePath||"src",r}async generate(){const t=await this.getGeneratorContext();this.logger.debug("context is:",t,this.context.options.templateRootPath),t.subPackages?await this.action({label:"Generate Directories(subPackages)",task:async()=>{await this.generateTemplateDir(t),await this.generateSubPackages(t),await this.generateConfigs(t,t.targetPath,"_common")}}):await this.action({label:"Generate Directory",task:async()=>{await this.generateTemplateDir(t),await this.generateConfigs(t,t.targetPath,"_common"),await this.generateConfigs(t,t.targetPath,t.template)}})}async generateConfigs(t,r,n){const{configsRootPath:i,config:o}=this.context.options;o?await this.copyer.copyPaths({sourcePath:e(i,n),targetPath:r,copyCallback:(r,e)=>(this.logger.debug("copyCallback",r,e),this.compose.composeConfigFile(t,r,e))}):this.logger.debug("no copy config files")}generateTemplateDir(t){return this.copyer.copyPaths({sourcePath:e(this.context.options.templateRootPath,t.template),targetPath:t.targetPath})}async generateSubPackages(t){const{packagesNames:r="packages",subPackages:n=[],targetPath:i=""}=t,{templateRootPath:o}=this.context.options;for(const t of n){const n=e(o,t),u=e(i,r,t);this.logger.debug("copy sub package",n,u),await this.copyer.copyPaths({sourcePath:n,targetPath:u})}}}export{b as Copyer,qi as Generator,p as createDefaultPrompts,h as createPackagePrompts,l as validRequiredString};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlover/create-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/es/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "rollup -c",
|
|
33
|
+
"test": "jest",
|
|
33
34
|
"create:app:build": "npm run build && npm run create:app",
|
|
34
35
|
"create:app": "node ./bin/create-app.js"
|
|
35
36
|
},
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"git": {
|
|
3
|
-
"commitMessage": "chore(tag): [PKG_NAME] v${version}",
|
|
4
|
-
"tagName": "[PKG_NAME]-v${version}",
|
|
5
|
-
"tagMatch": "[PKG_NAME]-v*",
|
|
6
|
-
"tagAnnotation": "chore(tag): [PKG_NAME] v${version}",
|
|
7
|
-
"push": true,
|
|
8
|
-
"pushArgs": ["--follow-tags"]
|
|
9
|
-
},
|
|
10
|
-
"npm": {
|
|
11
|
-
"publishPath": "",
|
|
12
|
-
"versionArgs": ["--allow-same-version", "--workspaces-update=false"]
|
|
13
|
-
},
|
|
14
|
-
"github": {
|
|
15
|
-
"release": true,
|
|
16
|
-
"releaseName": "chore(tag): [PKG_NAME] v${version}"
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
"plugins": {
|
|
20
|
-
"@release-it/conventional-changelog": {
|
|
21
|
-
"infile": "CHANGELOG.md",
|
|
22
|
-
"preset": {
|
|
23
|
-
"name": "conventionalcommits",
|
|
24
|
-
"types": [
|
|
25
|
-
{ "type": "feat", "section": "Features" },
|
|
26
|
-
{ "type": "fix", "section": "Bug Fixes" },
|
|
27
|
-
{ "type": "revert", "section": "Reverts" },
|
|
28
|
-
{ "type": "build", "hidden": true, "section": "Build System" },
|
|
29
|
-
{ "type": "chore", "hidden": true },
|
|
30
|
-
{ "type": "docs", "section": "Documentation" },
|
|
31
|
-
{ "type": "style", "hidden": true },
|
|
32
|
-
{ "type": "refactor", "hidden": true },
|
|
33
|
-
{ "type": "perf", "hidden": true },
|
|
34
|
-
{ "type": "test", "hidden": true }
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
"gitRawCommitsOpts": {
|
|
38
|
-
"path": "."
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|