@qlover/create-app 0.0.4 → 0.1.2
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 +14 -0
- package/README.md +5 -0
- package/bin/create-app.js +7 -9
- package/dist/cjs/index.d.ts +39 -15
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.d.ts +39 -15
- package/dist/es/index.js +1 -1
- package/package.json +4 -2
- package/templates/node-lib/package.json +34 -0
- package/templates/node-lib/tsconfig.json +5 -0
- package/templates/pack-app/package.json +5 -7
- package/templates/{fe-react → react-app}/config/i18n.ts +1 -1
- package/templates/{fe-react → react-app}/lib/fe-react-theme/index.ts +1 -1
- package/templates/{fe-react → react-app}/lib/fe-react-theme/tw-generator.js +0 -1
- package/templates/{fe-react → react-app}/lib/openAiApi/index.ts +1 -1
- package/templates/{fe-react → react-app}/package.json +1 -1
- package/templates/{fe-react → react-app}/postcss.config.js +3 -3
- package/templates/{fe-react → react-app}/src/containers/globals.ts +1 -1
- package/templates/{fe-react → react-app}/src/containers/index.ts +1 -1
- package/templates/{fe-react → react-app}/src/hooks/useStrictEffect.ts +7 -4
- package/templates/{fe-react → react-app}/src/services/controllers/UserController.ts +1 -1
- package/templates/{fe-react → react-app}/src/services/feApi/FeApi.ts +1 -1
- package/templates/{fe-react → react-app}/src/services/feApi/FeApiMockPlugin.ts +3 -1
- package/templates/{fe-react → react-app}/src/services/feApi/FeApiType.ts +0 -1
- package/templates/{fe-react → react-app}/src/services/pageProcesser/PageProcesser.ts +1 -1
- package/templates/{fe-react → react-app}/src/utils/datetime.ts +10 -5
- package/templates/react-app/src/vite-env.d.ts +1 -0
- package/templates/react-vite-lib/.gitignore.template +27 -0
- package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/__tests__/Sum.test.ts +1 -1
- package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/eslint.config.js +12 -12
- package/templates/react-vite-lib/src/vite-env.d.ts +1 -0
- package/templates/fe-react/src/vite-env.d.ts +0 -1
- package/templates/pack-app/packages/browser/__tests__/calc.test.ts +0 -9
- package/templates/pack-app/packages/browser/package.json +0 -11
- package/templates/pack-app/packages/browser/rollup.config.js +0 -70
- package/templates/pack-app/packages/browser/src/calc.ts +0 -3
- package/templates/pack-app/packages/browser/src/index.ts +0 -1
- package/templates/pack-app/packages/browser/tsconfig.json +0 -15
- package/templates/pack-app/packages/node/package.json +0 -11
- package/templates/pack-app/packages/node/tsconfig.json +0 -17
- package/templates/pack-app/packages/react-vite-lib/src/vite-env.d.ts +0 -1
- /package/templates/{pack-app/packages/node → node-lib}/__tests__/readJson.test.ts +0 -0
- /package/templates/{pack-app/packages/node → node-lib}/rollup.config.js +0 -0
- /package/templates/{pack-app/packages/node → node-lib}/src/index.ts +0 -0
- /package/templates/{pack-app/packages/node → node-lib}/src/readJson.ts +0 -0
- /package/templates/{fe-react → react-app}/.env +0 -0
- /package/templates/{fe-react → react-app}/.gitignore.template +0 -0
- /package/templates/{fe-react → react-app}/README.md +0 -0
- /package/templates/{fe-react → react-app}/config/app.common.ts +0 -0
- /package/templates/{fe-react → react-app}/config/app.router.json +0 -0
- /package/templates/{fe-react → react-app}/config/feapi.mock.json +0 -0
- /package/templates/{fe-react → react-app}/config/theme.json +0 -0
- /package/templates/{fe-react → react-app}/eslint.config.js +0 -0
- /package/templates/{fe-react → react-app}/index.html +0 -0
- /package/templates/{fe-react → react-app}/lib/fe-react-controller/FeController.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/fe-react-controller/index.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/fe-react-controller/useController.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/fe-react-theme/ThemeController.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/fe-react-theme/ThemeStateGetter.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/fe-react-theme/type.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/openAiApi/OpenAIAuthPlugin.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/openAiApi/OpenAIClient.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/openAiApi/StreamProcessor.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/request-common-plugin/index.ts +0 -0
- /package/templates/{fe-react → react-app}/lib/tw-root10px/index.css +0 -0
- /package/templates/{fe-react → react-app}/lib/tw-root10px/index.js +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/about.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/common.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/executor.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/home.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/jsonStorage.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/login.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/en/request.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/about.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/common.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/executor.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/home.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/jsonStorage.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/login.json +0 -0
- /package/templates/{fe-react → react-app}/public/locales/zh/request.json +0 -0
- /package/templates/{fe-react → react-app}/public/logo.svg +0 -0
- /package/templates/{fe-react → react-app}/src/App.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/assets/react.svg +0 -0
- /package/templates/{fe-react → react-app}/src/components/Loading.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/components/LocaleLink.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/components/ProcessProvider.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/components/ThemeSwitcher.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/containers/context/BaseRouteContext.ts +0 -0
- /package/templates/{fe-react → react-app}/src/containers/context/BaseRouteProvider.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/hooks/useLanguageGuard.ts +0 -0
- /package/templates/{fe-react → react-app}/src/main.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/404.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/500.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/auth/Layout.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/auth/Login.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/auth/Register.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/About.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/Executor.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/Home.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/JSONStorage.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/Layout.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/RedirectPathname.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/Request.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/base/components/BaseHeader.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/pages/index.tsx +0 -0
- /package/templates/{fe-react → react-app}/src/services/controllers/ExecutorController.ts +0 -0
- /package/templates/{fe-react → react-app}/src/services/controllers/JSONStorageController.ts +0 -0
- /package/templates/{fe-react → react-app}/src/services/controllers/RequestController.ts +0 -0
- /package/templates/{fe-react → react-app}/src/services/controllers/RouterController.ts +0 -0
- /package/templates/{fe-react → react-app}/src/services/feApi/index.ts +0 -0
- /package/templates/{fe-react → react-app}/src/services/i18n/index.ts +0 -0
- /package/templates/{fe-react → react-app}/src/services/pageProcesser/index.ts +0 -0
- /package/templates/{fe-react → react-app}/src/styles/css/index.css +0 -0
- /package/templates/{fe-react → react-app}/src/styles/css/page.css +0 -0
- /package/templates/{fe-react → react-app}/src/styles/css/tailwind.css +0 -0
- /package/templates/{fe-react → react-app}/src/types/Page.ts +0 -0
- /package/templates/{fe-react → react-app}/src/types/UIDependenciesInterface.ts +0 -0
- /package/templates/{fe-react → react-app}/src/types/global.d.ts +0 -0
- /package/templates/{fe-react → react-app}/src/utils/RequestLogger.ts +0 -0
- /package/templates/{fe-react → react-app}/src/utils/thread.ts +0 -0
- /package/templates/{fe-react → react-app}/tailwind.config.js +0 -0
- /package/templates/{fe-react → react-app}/tsconfig.app.json +0 -0
- /package/templates/{fe-react → react-app}/tsconfig.json +0 -0
- /package/templates/{fe-react → react-app}/tsconfig.node.json +0 -0
- /package/templates/{fe-react → react-app}/vite.config.ts +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/README.md +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/__tests__/Text.test.tsx +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/index.html +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/package.json +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/public/vite.svg +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/src/calc.ts +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/src/commponents/Text.tsx +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/src/index.ts +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/tsconfig.json +0 -0
- /package/templates/{pack-app/packages/react-vite-lib → react-vite-lib}/vite.config.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [0.1.2](https://github.com/qlover/fe-base/compare/create-app-v0.1.1...create-app-v0.1.2) (2025-01-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add script-context ([#213](https://github.com/qlover/fe-base/issues/213)) ([e021441](https://github.com/qlover/fe-base/commit/e021441180d4c4bd89947b155d39224f89699fda))
|
|
9
|
+
|
|
10
|
+
## [0.1.1](https://github.com/qlover/fe-base/compare/create-app-v0.0.4...create-app-v0.1.1) (2025-01-15)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* create app v0.1 ([#209](https://github.com/qlover/fe-base/issues/209)) ([b730d76](https://github.com/qlover/fe-base/commit/b730d76512a9e1ce765ec77145abfe179b585178))
|
|
16
|
+
|
|
3
17
|
## [0.0.4](https://github.com/qlover/fe-base/compare/create-app-v0.0.3...create-app-v0.0.4) (2025-01-15)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
ADDED
package/bin/create-app.js
CHANGED
|
@@ -7,20 +7,18 @@ import { existsSync } from 'fs';
|
|
|
7
7
|
|
|
8
8
|
async function main() {
|
|
9
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const
|
|
10
|
+
const templateRootPath = join(__dirname, '../templates');
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
options: {
|
|
14
|
-
templatePath
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
if (!existsSync(templatePath)) {
|
|
12
|
+
if (!existsSync(templateRootPath)) {
|
|
19
13
|
console.error('Template is empty!');
|
|
20
14
|
process.exit(1);
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
const generator = new Generator(
|
|
17
|
+
const generator = new Generator({
|
|
18
|
+
options: {
|
|
19
|
+
templateRootPath
|
|
20
|
+
}
|
|
21
|
+
});
|
|
24
22
|
|
|
25
23
|
await generator.generate();
|
|
26
24
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,13 +3,20 @@ import { Logger } from '@qlover/fe-utils';
|
|
|
3
3
|
import { DistinctQuestion } from 'inquirer';
|
|
4
4
|
import ignore from 'ignore';
|
|
5
5
|
|
|
6
|
+
type GeneratorPrompt = DistinctQuestion;
|
|
6
7
|
type GeneratorOptions = {
|
|
7
|
-
prompts?:
|
|
8
|
-
|
|
8
|
+
prompts?: GeneratorPrompt[];
|
|
9
|
+
templateRootPath: string;
|
|
9
10
|
};
|
|
10
|
-
interface GeneratorResult {
|
|
11
|
+
interface GeneratorResult extends GeneratorOptions {
|
|
11
12
|
name: string;
|
|
12
|
-
|
|
13
|
+
template: string;
|
|
14
|
+
subPackages?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* @default `packages`
|
|
17
|
+
*/
|
|
18
|
+
packagesNames?: string;
|
|
19
|
+
targetPath?: string;
|
|
13
20
|
}
|
|
14
21
|
type TaskOptions = {
|
|
15
22
|
templateFiles: TemplateFile[];
|
|
@@ -19,17 +26,16 @@ type TemplateFile = {
|
|
|
19
26
|
path: string;
|
|
20
27
|
content: string;
|
|
21
28
|
};
|
|
29
|
+
|
|
22
30
|
declare class Generator {
|
|
23
|
-
private prompts;
|
|
24
31
|
private ora;
|
|
25
32
|
protected context: FeScriptContext<GeneratorOptions>;
|
|
26
33
|
constructor(context: Partial<FeScriptContext<GeneratorOptions>>);
|
|
27
34
|
get logger(): Logger;
|
|
28
|
-
steps(prompts:
|
|
29
|
-
getTemplateFiles(path: string): Promise<TemplateFile[]>;
|
|
35
|
+
steps(prompts: GeneratorPrompt[]): Promise<GeneratorResult>;
|
|
30
36
|
action({ label, task }: {
|
|
31
37
|
label: string;
|
|
32
|
-
task: () => Promise<unknown
|
|
38
|
+
task: (() => Promise<unknown>) | (() => unknown);
|
|
33
39
|
}): Promise<unknown>;
|
|
34
40
|
/**
|
|
35
41
|
* Creates files and directories based on the provided template files.
|
|
@@ -38,31 +44,49 @@ declare class Generator {
|
|
|
38
44
|
* to the file system. It handles both files and directories, ensuring that
|
|
39
45
|
* the directory structure is preserved.
|
|
40
46
|
*
|
|
41
|
-
* @param templateFiles - An array of template files to be created.
|
|
42
47
|
* @param result - The result object containing the name and template name.
|
|
43
48
|
*
|
|
44
49
|
* @returns A promise that resolves when all files have been created.
|
|
45
50
|
*
|
|
46
51
|
* @example
|
|
47
|
-
* const
|
|
48
|
-
* await
|
|
52
|
+
* const result = { name: 'my-app', template: 'react-app' };
|
|
53
|
+
* await this.create(result);
|
|
49
54
|
*/
|
|
50
|
-
create(
|
|
55
|
+
create(result: GeneratorResult): Promise<void>;
|
|
56
|
+
private isPackageTemplate;
|
|
57
|
+
getGeneratorResult(): Promise<GeneratorResult>;
|
|
51
58
|
generate(): Promise<void>;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
declare const validRequiredString: (value: string, key: string) => string | true;
|
|
62
|
+
declare const defaultPrompts: GeneratorPrompt[];
|
|
63
|
+
declare const packagePrompts: GeneratorPrompt[];
|
|
55
64
|
|
|
56
65
|
declare class Copyer {
|
|
57
66
|
static IGNORE_FILE: string;
|
|
58
67
|
getIg(targetDir: string): ignore.Ignore | undefined;
|
|
68
|
+
ensureDir(dir: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Asynchronously copy files from source to target directory.
|
|
71
|
+
* @param {string} sourcePath - Source directory.
|
|
72
|
+
* @param {string} targetDir - Target directory.
|
|
73
|
+
* @param {ignore.Ignore} ig - Ignore rules.
|
|
74
|
+
* @returns {Promise<void>} - A promise that resolves when the copy is complete.
|
|
75
|
+
* @example
|
|
76
|
+
* await copyer.copyFilesPromise('src', 'dest', ignoreInstance);
|
|
77
|
+
*/
|
|
78
|
+
copyFilesPromise(sourcePath: string, targetDir: string, ig?: ignore.Ignore): Promise<void>;
|
|
59
79
|
/**
|
|
60
80
|
* copy templates recursively
|
|
61
|
-
* @param {string}
|
|
81
|
+
* @param {string} sourePath - source directory
|
|
62
82
|
* @param {string} targetDir - target directory
|
|
63
83
|
* @param {ignore.Ignore} ig - ignore rules
|
|
64
84
|
*/
|
|
65
|
-
|
|
85
|
+
copyFilesSync(sourePath: string, targetDir: string, ig?: ignore.Ignore): void;
|
|
86
|
+
create(result: GeneratorResult): void;
|
|
87
|
+
createPromise(result: GeneratorResult): Promise<void>;
|
|
88
|
+
createPath(result: GeneratorResult): void;
|
|
89
|
+
createPathPromise(result: GeneratorResult): Promise<void>;
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
export { Copyer, Generator, type GeneratorOptions, type GeneratorResult, type TaskOptions, type TemplateFile, validRequiredString };
|
|
92
|
+
export { Copyer, Generator, type GeneratorOptions, type GeneratorPrompt, type GeneratorResult, type TaskOptions, type TemplateFile, defaultPrompts, packagePrompts, validRequiredString };
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@qlover/fe-scripts"),e=require("inquirer"),
|
|
1
|
+
"use strict";var t=require("@qlover/fe-scripts"),e=require("inquirer"),a=require("path"),r=require("ora"),s=require("fs"),i=require("ignore");const o=(t,e)=>"string"==typeof t&&""!==t.trim()||`${e} is required`,n=["node-lib","react-app","react-vite-lib"],c=[{type:"input",name:"name",message:"Project name",validate:t=>o(t,"Project name")},{type:"list",name:"template",message:"Template name",choices:[...n,"pack-app"]}],p=[{type:"checkbox",name:"subPackages",message:"Sub package names",choices:n}],{copyFile:h,stat:m}=s.promises;class l{static IGNORE_FILE=".gitignore.template";getIg(t){const e=a.join(t,l.IGNORE_FILE);if(!s.existsSync(e))return;const r=s.readFileSync(e,"utf8").split("\n").map((t=>t.trim())).filter((t=>t&&!t.startsWith("#")));return i().add(r)}ensureDir(t){s.existsSync(t)||s.mkdirSync(t,{recursive:!0})}async copyFilesPromise(t,e,r){const i=await s.promises.readdir(t);await Promise.all(i.map((async s=>{const i=a.join(t,s),o=a.join(e,s);if(r&&r.ignores(s))return;this.ensureDir(a.dirname(o));(await m(i)).isDirectory()?await this.copyFilesPromise(i,o,r):await h(i,o)})))}copyFilesSync(t,e,r){const i=s.readdirSync(t);for(const o of i){const i=a.join(t,o),n=a.join(e,o);r&&r.ignores(o)||(this.ensureDir(a.dirname(n)),s.statSync(i).isDirectory()?this.copyFilesSync(i,n,r):s.copyFileSync(i,n))}}create(t){const{targetPath:e,templateRootPath:r,subPackages:s,packagesNames:i="packages"}=t;if(!e||!r)throw new Error("targetPath and templatePath are required");if(this.createPath(t),s)for(const r of s){const s=a.join(e,i,r);this.createPath({...t,targetPath:s,template:r})}}async createPromise(t){const{targetPath:e,templateRootPath:r,subPackages:s,packagesNames:i="packages"}=t;if(!e||!r)throw new Error("targetPath and templatePath are required");if(await this.createPathPromise(t),s)for(const r of s){const s=a.join(e,i,r);await this.createPathPromise({...t,targetPath:s,template:r})}}createPath(t){const{targetPath:e="",templateRootPath:r,template:s}=t;this.ensureDir(e);const i=a.join(r,s),o=this.getIg(e);this.copyFilesSync(i,e,o)}createPathPromise(t){const{targetPath:e="",templateRootPath:r,template:s}=t;this.ensureDir(e);const i=a.join(r,s),o=this.getIg(e);return this.copyFilesPromise(i,e,o)}}exports.Copyer=l,exports.Generator=class{ora;context;constructor(e){const a=e.options?.templateRootPath;if(!a)throw new Error("template path not exit");if(!s.existsSync(a))throw new Error("template path not exit");this.ora=r.oraPromise,this.context=new t.FeScriptContext(e)}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 r=t;return this.ora(a,r),a}async create(t){const e=a.join(process.cwd(),t.name),r=new l,s={...t,targetPath:e,templateRootPath:this.context.options.templateRootPath};return this.logger.debug(s),r.createPromise(s)}isPackageTemplate(t){return"pack-app"===t}async getGeneratorResult(){const t=await this.steps(c);if(this.isPackageTemplate(t.template)){const e=await this.steps(p);Object.assign(t,e)}return t}async generate(){const t=await this.getGeneratorResult();await this.action({label:"Creating project",task:()=>this.create(t)})}},exports.defaultPrompts=c,exports.packagePrompts=p,exports.validRequiredString=o;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -3,13 +3,20 @@ import { Logger } from '@qlover/fe-utils';
|
|
|
3
3
|
import { DistinctQuestion } from 'inquirer';
|
|
4
4
|
import ignore from 'ignore';
|
|
5
5
|
|
|
6
|
+
type GeneratorPrompt = DistinctQuestion;
|
|
6
7
|
type GeneratorOptions = {
|
|
7
|
-
prompts?:
|
|
8
|
-
|
|
8
|
+
prompts?: GeneratorPrompt[];
|
|
9
|
+
templateRootPath: string;
|
|
9
10
|
};
|
|
10
|
-
interface GeneratorResult {
|
|
11
|
+
interface GeneratorResult extends GeneratorOptions {
|
|
11
12
|
name: string;
|
|
12
|
-
|
|
13
|
+
template: string;
|
|
14
|
+
subPackages?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* @default `packages`
|
|
17
|
+
*/
|
|
18
|
+
packagesNames?: string;
|
|
19
|
+
targetPath?: string;
|
|
13
20
|
}
|
|
14
21
|
type TaskOptions = {
|
|
15
22
|
templateFiles: TemplateFile[];
|
|
@@ -19,17 +26,16 @@ type TemplateFile = {
|
|
|
19
26
|
path: string;
|
|
20
27
|
content: string;
|
|
21
28
|
};
|
|
29
|
+
|
|
22
30
|
declare class Generator {
|
|
23
|
-
private prompts;
|
|
24
31
|
private ora;
|
|
25
32
|
protected context: FeScriptContext<GeneratorOptions>;
|
|
26
33
|
constructor(context: Partial<FeScriptContext<GeneratorOptions>>);
|
|
27
34
|
get logger(): Logger;
|
|
28
|
-
steps(prompts:
|
|
29
|
-
getTemplateFiles(path: string): Promise<TemplateFile[]>;
|
|
35
|
+
steps(prompts: GeneratorPrompt[]): Promise<GeneratorResult>;
|
|
30
36
|
action({ label, task }: {
|
|
31
37
|
label: string;
|
|
32
|
-
task: () => Promise<unknown
|
|
38
|
+
task: (() => Promise<unknown>) | (() => unknown);
|
|
33
39
|
}): Promise<unknown>;
|
|
34
40
|
/**
|
|
35
41
|
* Creates files and directories based on the provided template files.
|
|
@@ -38,31 +44,49 @@ declare class Generator {
|
|
|
38
44
|
* to the file system. It handles both files and directories, ensuring that
|
|
39
45
|
* the directory structure is preserved.
|
|
40
46
|
*
|
|
41
|
-
* @param templateFiles - An array of template files to be created.
|
|
42
47
|
* @param result - The result object containing the name and template name.
|
|
43
48
|
*
|
|
44
49
|
* @returns A promise that resolves when all files have been created.
|
|
45
50
|
*
|
|
46
51
|
* @example
|
|
47
|
-
* const
|
|
48
|
-
* await
|
|
52
|
+
* const result = { name: 'my-app', template: 'react-app' };
|
|
53
|
+
* await this.create(result);
|
|
49
54
|
*/
|
|
50
|
-
create(
|
|
55
|
+
create(result: GeneratorResult): Promise<void>;
|
|
56
|
+
private isPackageTemplate;
|
|
57
|
+
getGeneratorResult(): Promise<GeneratorResult>;
|
|
51
58
|
generate(): Promise<void>;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
declare const validRequiredString: (value: string, key: string) => string | true;
|
|
62
|
+
declare const defaultPrompts: GeneratorPrompt[];
|
|
63
|
+
declare const packagePrompts: GeneratorPrompt[];
|
|
55
64
|
|
|
56
65
|
declare class Copyer {
|
|
57
66
|
static IGNORE_FILE: string;
|
|
58
67
|
getIg(targetDir: string): ignore.Ignore | undefined;
|
|
68
|
+
ensureDir(dir: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Asynchronously copy files from source to target directory.
|
|
71
|
+
* @param {string} sourcePath - Source directory.
|
|
72
|
+
* @param {string} targetDir - Target directory.
|
|
73
|
+
* @param {ignore.Ignore} ig - Ignore rules.
|
|
74
|
+
* @returns {Promise<void>} - A promise that resolves when the copy is complete.
|
|
75
|
+
* @example
|
|
76
|
+
* await copyer.copyFilesPromise('src', 'dest', ignoreInstance);
|
|
77
|
+
*/
|
|
78
|
+
copyFilesPromise(sourcePath: string, targetDir: string, ig?: ignore.Ignore): Promise<void>;
|
|
59
79
|
/**
|
|
60
80
|
* copy templates recursively
|
|
61
|
-
* @param {string}
|
|
81
|
+
* @param {string} sourePath - source directory
|
|
62
82
|
* @param {string} targetDir - target directory
|
|
63
83
|
* @param {ignore.Ignore} ig - ignore rules
|
|
64
84
|
*/
|
|
65
|
-
|
|
85
|
+
copyFilesSync(sourePath: string, targetDir: string, ig?: ignore.Ignore): void;
|
|
86
|
+
create(result: GeneratorResult): void;
|
|
87
|
+
createPromise(result: GeneratorResult): Promise<void>;
|
|
88
|
+
createPath(result: GeneratorResult): void;
|
|
89
|
+
createPathPromise(result: GeneratorResult): Promise<void>;
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
export { Copyer, Generator, type GeneratorOptions, type GeneratorResult, type TaskOptions, type TemplateFile, validRequiredString };
|
|
92
|
+
export { Copyer, Generator, type GeneratorOptions, type GeneratorPrompt, type GeneratorResult, type TaskOptions, type TemplateFile, defaultPrompts, packagePrompts, validRequiredString };
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FeScriptContext as t}from"@qlover/fe-scripts";import e from"inquirer";import{join as
|
|
1
|
+
import{FeScriptContext as t}from"@qlover/fe-scripts";import e from"inquirer";import{join as a,dirname as r}from"path";import{oraPromise as s}from"ora";import{existsSync as o,readFileSync as i,mkdirSync as c,promises as n,readdirSync as p,statSync as h,copyFileSync as m}from"fs";import l from"ignore";const g=(t,e)=>"string"==typeof t&&""!==t.trim()||`${e} is required`,P=["node-lib","react-app","react-vite-lib"],u=[{type:"input",name:"name",message:"Project name",validate:t=>g(t,"Project name")},{type:"list",name:"template",message:"Template name",choices:[...P,"pack-app"]}],f=[{type:"checkbox",name:"subPackages",message:"Sub package names",choices:P}],{copyFile:y,stat:w}=n;class k{static IGNORE_FILE=".gitignore.template";getIg(t){const e=a(t,k.IGNORE_FILE);if(!o(e))return;const r=i(e,"utf8").split("\n").map((t=>t.trim())).filter((t=>t&&!t.startsWith("#")));return l().add(r)}ensureDir(t){o(t)||c(t,{recursive:!0})}async copyFilesPromise(t,e,s){const o=await n.readdir(t);await Promise.all(o.map((async o=>{const i=a(t,o),c=a(e,o);if(s&&s.ignores(o))return;this.ensureDir(r(c));(await w(i)).isDirectory()?await this.copyFilesPromise(i,c,s):await y(i,c)})))}copyFilesSync(t,e,s){const o=p(t);for(const i of o){const o=a(t,i),c=a(e,i);s&&s.ignores(i)||(this.ensureDir(r(c)),h(o).isDirectory()?this.copyFilesSync(o,c,s):m(o,c))}}create(t){const{targetPath:e,templateRootPath:r,subPackages:s,packagesNames:o="packages"}=t;if(!e||!r)throw new Error("targetPath and templatePath are required");if(this.createPath(t),s)for(const r of s){const s=a(e,o,r);this.createPath({...t,targetPath:s,template:r})}}async createPromise(t){const{targetPath:e,templateRootPath:r,subPackages:s,packagesNames:o="packages"}=t;if(!e||!r)throw new Error("targetPath and templatePath are required");if(await this.createPathPromise(t),s)for(const r of s){const s=a(e,o,r);await this.createPathPromise({...t,targetPath:s,template:r})}}createPath(t){const{targetPath:e="",templateRootPath:r,template:s}=t;this.ensureDir(e);const o=a(r,s),i=this.getIg(e);this.copyFilesSync(o,e,i)}createPathPromise(t){const{targetPath:e="",templateRootPath:r,template:s}=t;this.ensureDir(e);const o=a(r,s),i=this.getIg(e);return this.copyFilesPromise(o,e,i)}}class d{ora;context;constructor(e){const a=e.options?.templateRootPath;if(!a)throw new Error("template path not exit");if(!o(a))throw new Error("template path not exit");this.ora=s,this.context=new t(e)}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 r=t;return this.ora(a,r),a}async create(t){const e=a(process.cwd(),t.name),r=new k,s={...t,targetPath:e,templateRootPath:this.context.options.templateRootPath};return this.logger.debug(s),r.createPromise(s)}isPackageTemplate(t){return"pack-app"===t}async getGeneratorResult(){const t=await this.steps(u);if(this.isPackageTemplate(t.template)){const e=await this.steps(f);Object.assign(t,e)}return t}async generate(){const t=await this.getGeneratorResult();await this.action({label:"Creating project",task:()=>this.create(t)})}}export{k as Copyer,d as Generator,u as defaultPrompts,f as packagePrompts,g as validRequiredString};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlover/create-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/es/index.js",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"create-app": "./bin/create-app.js"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "
|
|
31
|
+
"build": "rollup -c",
|
|
32
|
+
"create:app:build": "npm run build && npm run create:app",
|
|
33
|
+
"create:app": "node ./bin/create-app.js"
|
|
32
34
|
},
|
|
33
35
|
"repository": {
|
|
34
36
|
"type": "git",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-lib",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": true,
|
|
6
|
+
"main": "./dist/es/index.js",
|
|
7
|
+
"module": "./dist/es/index.js",
|
|
8
|
+
"types": "./dist/es/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/es/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"types": "./dist/es/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./cjs/*": "./dist/cjs/*",
|
|
16
|
+
"./es/*": "./dist/es/*",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"package.json",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rollup -c",
|
|
26
|
+
"test": "jest"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@qlover/fe-standard": "latest"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@qlover/fe-utils": "latest"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -10,10 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://github.com/qlover/fe-base#readme",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "pnpm run build:
|
|
14
|
-
"build:
|
|
15
|
-
"build:browser": "pnpm run build --filter=@qlover/pack-app-browser",
|
|
16
|
-
"build:react": "pnpm run build --filter=@qlover/pack-app-react",
|
|
13
|
+
"build": "pnpm run build:[PKG_NAME]",
|
|
14
|
+
"build:[PKG_NAME]": "pnpm run build --filter=@qlover/${PKG_NAME}",
|
|
17
15
|
"prettier": "prettier --ignore-path .prettierignore **/*.{js,ts,json,cjs,mjs} --write",
|
|
18
16
|
"lint": "eslint . --fix",
|
|
19
17
|
"test": "jest",
|
|
@@ -33,9 +31,9 @@
|
|
|
33
31
|
"node": ">=18.19.0"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
36
|
-
"@qlover/fe-scripts": "
|
|
37
|
-
"@qlover/fe-standard": "
|
|
38
|
-
"@qlover/fe-utils": "
|
|
34
|
+
"@qlover/fe-scripts": "latest",
|
|
35
|
+
"@qlover/fe-standard": "latest",
|
|
36
|
+
"@qlover/fe-utils": "latest",
|
|
39
37
|
"@rollup/plugin-commonjs": "^28.0.1",
|
|
40
38
|
"@rollup/plugin-json": "^6.1.0",
|
|
41
39
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
@@ -14,8 +14,11 @@ export const useStrictEffect = (
|
|
|
14
14
|
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
// Check if the dependencies have changed
|
|
17
|
-
const depsChanged =
|
|
18
|
-
|
|
17
|
+
const depsChanged =
|
|
18
|
+
!deps ||
|
|
19
|
+
!depsRef.current ||
|
|
20
|
+
deps.some((dep, i) => dep !== depsRef.current![i]);
|
|
21
|
+
|
|
19
22
|
// Update the dependency reference
|
|
20
23
|
depsRef.current = deps;
|
|
21
24
|
|
|
@@ -24,6 +27,6 @@ export const useStrictEffect = (
|
|
|
24
27
|
mountedRef.current = true;
|
|
25
28
|
return effect();
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
31
|
}, deps);
|
|
29
|
-
};
|
|
32
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutorPlugin, JSONStorage } from '@qlover/fe-utils';
|
|
2
2
|
import { sleep } from '@/utils/thread';
|
|
3
3
|
import { FeController } from '@lib/fe-react-controller';
|
|
4
|
-
import { FeApi
|
|
4
|
+
import { FeApi } from '@/services/feApi';
|
|
5
5
|
import { FeApiGetUserInfo, FeApiLogin } from '@/services/feApi/FeApiType';
|
|
6
6
|
import { adjustExpirationTime } from '@/utils/datetime';
|
|
7
7
|
import { RouterController } from './RouterController';
|
|
@@ -9,7 +9,9 @@ import { sleep } from '@/utils/thread';
|
|
|
9
9
|
export class FeApiMockPlugin implements ExecutorPlugin {
|
|
10
10
|
readonly pluginName = 'FeApiMockPlugin';
|
|
11
11
|
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(
|
|
13
|
+
private readonly mockDataJson: typeof import('@config/feapi.mock.json')
|
|
14
|
+
) {}
|
|
13
15
|
|
|
14
16
|
async onExec({
|
|
15
17
|
parameters
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adjusts the expiration time based on the provided `expiresIn` value.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* @param {number} baseTime - The base time in milliseconds to adjust.
|
|
5
5
|
* @returns {number} - The adjusted time in milliseconds.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @example
|
|
8
8
|
* const adjustedTime = userController.adjustExpirationTime(Date.now());
|
|
9
9
|
*/
|
|
10
|
-
export function adjustExpirationTime(
|
|
10
|
+
export function adjustExpirationTime(
|
|
11
|
+
baseTime: number,
|
|
12
|
+
expiresIn: number | 'day' | 'week' | 'month' | 'year'
|
|
13
|
+
): number {
|
|
11
14
|
const dayInMs = 24 * 60 * 60 * 1000;
|
|
12
15
|
|
|
13
16
|
switch (expiresIn) {
|
|
@@ -20,6 +23,8 @@ export function adjustExpirationTime(baseTime: number, expiresIn: number | 'day'
|
|
|
20
23
|
case 'year':
|
|
21
24
|
return baseTime + 365 * dayInMs; // Approximation
|
|
22
25
|
default:
|
|
23
|
-
return
|
|
26
|
+
return (
|
|
27
|
+
baseTime + (typeof expiresIn === 'number' ? expiresIn : 30 * dayInMs)
|
|
28
|
+
);
|
|
24
29
|
}
|
|
25
|
-
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// / <reference types="vite/client" />
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
|
|
15
|
+
# Editor directories and files
|
|
16
|
+
.vscode/*
|
|
17
|
+
!.vscode/extensions.json
|
|
18
|
+
.idea
|
|
19
|
+
.DS_Store
|
|
20
|
+
*.suo
|
|
21
|
+
*.ntvs*
|
|
22
|
+
*.njsproj
|
|
23
|
+
*.sln
|
|
24
|
+
*.sw?
|
|
25
|
+
|
|
26
|
+
tsconfig.app.json
|
|
27
|
+
tsconfig.node.json
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import js from '@eslint/js'
|
|
2
|
-
import globals from 'globals'
|
|
3
|
-
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
-
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
-
import tseslint from 'typescript-eslint'
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh';
|
|
5
|
+
import tseslint from 'typescript-eslint';
|
|
6
6
|
|
|
7
7
|
export default tseslint.config(
|
|
8
8
|
{ ignores: ['dist'] },
|
|
@@ -11,18 +11,18 @@ export default tseslint.config(
|
|
|
11
11
|
files: ['**/*.{ts,tsx}'],
|
|
12
12
|
languageOptions: {
|
|
13
13
|
ecmaVersion: 2020,
|
|
14
|
-
globals: globals.browser
|
|
14
|
+
globals: globals.browser
|
|
15
15
|
},
|
|
16
16
|
plugins: {
|
|
17
17
|
'react-hooks': reactHooks,
|
|
18
|
-
'react-refresh': reactRefresh
|
|
18
|
+
'react-refresh': reactRefresh
|
|
19
19
|
},
|
|
20
20
|
rules: {
|
|
21
21
|
...reactHooks.configs.recommended.rules,
|
|
22
22
|
'react-refresh/only-export-components': [
|
|
23
23
|
'warn',
|
|
24
|
-
{ allowConstantExport: true }
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
)
|
|
24
|
+
{ allowConstantExport: true }
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// / <reference types="vite/client" />
|