create-zephyr-apps 0.0.6 → 0.0.8

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.
Files changed (80) hide show
  1. package/.github/workflows/pull_request.yml +56 -0
  2. package/.vscode/settings.json +75 -0
  3. package/biome.json +37 -0
  4. package/dist/index.cjs +135 -89
  5. package/dist/index.mjs +133 -87
  6. package/dist/package/utils/constants.d.ts +1 -1
  7. package/dist/package/utils/end.d.ts +1 -1
  8. package/package/index.ts +178 -113
  9. package/package/utils/constants.ts +64 -58
  10. package/package/utils/end.ts +19 -13
  11. package/package/utils/types.ts +1 -1
  12. package/package.json +33 -20
  13. package/rslib.config.ts +36 -37
  14. package/tsconfig.json +1 -2
  15. package/vite-mf/host/README.md +0 -50
  16. package/vite-mf/host/eslint.config.js +0 -25
  17. package/vite-mf/host/index.html +0 -13
  18. package/vite-mf/host/package.json +0 -31
  19. package/vite-mf/host/public/vite.svg +0 -1
  20. package/vite-mf/host/src/App.css +0 -42
  21. package/vite-mf/host/src/App.tsx +0 -37
  22. package/vite-mf/host/src/assets/react.svg +0 -1
  23. package/vite-mf/host/src/bootstrap.tsx +0 -10
  24. package/vite-mf/host/src/index.css +0 -68
  25. package/vite-mf/host/src/main.tsx +0 -8
  26. package/vite-mf/host/src/vite-env.d.ts +0 -1
  27. package/vite-mf/host/tsconfig.app.json +0 -24
  28. package/vite-mf/host/tsconfig.json +0 -4
  29. package/vite-mf/host/tsconfig.node.json +0 -22
  30. package/vite-mf/host/vite.config.ts +0 -40
  31. package/vite-mf/image.png +0 -0
  32. package/vite-mf/package.json +0 -12
  33. package/vite-mf/pnpm-lock.yaml +0 -9440
  34. package/vite-mf/pnpm-workspace.yaml +0 -2
  35. package/vite-mf/readme.md +0 -17
  36. package/vite-mf/remote/eslint.config.js +0 -25
  37. package/vite-mf/remote/index.html +0 -13
  38. package/vite-mf/remote/package.json +0 -31
  39. package/vite-mf/remote/public/vite.svg +0 -1
  40. package/vite-mf/remote/src/App.css +0 -38
  41. package/vite-mf/remote/src/App.tsx +0 -24
  42. package/vite-mf/remote/src/Button.css +0 -9
  43. package/vite-mf/remote/src/Button.tsx +0 -20
  44. package/vite-mf/remote/src/assets/react.svg +0 -1
  45. package/vite-mf/remote/src/bootstrap.tsx +0 -10
  46. package/vite-mf/remote/src/index.css +0 -68
  47. package/vite-mf/remote/src/main.tsx +0 -10
  48. package/vite-mf/remote/src/vite-env.d.ts +0 -1
  49. package/vite-mf/remote/tsconfig.app.json +0 -24
  50. package/vite-mf/remote/tsconfig.json +0 -4
  51. package/vite-mf/remote/tsconfig.node.json +0 -22
  52. package/vite-mf/remote/vite.config.ts +0 -25
  53. package/vite-mf/rspack/.babelrc +0 -6
  54. package/vite-mf/rspack/compilation.config.js +0 -31
  55. package/vite-mf/rspack/package.json +0 -32
  56. package/vite-mf/rspack/postcss.config.js +0 -6
  57. package/vite-mf/rspack/rspack.config.js +0 -110
  58. package/vite-mf/rspack/src/App.tsx +0 -21
  59. package/vite-mf/rspack/src/Image.tsx +0 -18
  60. package/vite-mf/rspack/src/assets/rspack-logo.png +0 -0
  61. package/vite-mf/rspack/src/global.d.ts +0 -4
  62. package/vite-mf/rspack/src/index.css +0 -7
  63. package/vite-mf/rspack/src/index.html +0 -12
  64. package/vite-mf/rspack/src/index.tsx +0 -1
  65. package/vite-mf/rspack/tailwind.config.js +0 -11
  66. package/vite-mf/rspack/tsconfig.json +0 -29
  67. package/vite-mf/webpack/.babelrc +0 -13
  68. package/vite-mf/webpack/compilation.config.js +0 -31
  69. package/vite-mf/webpack/package.json +0 -46
  70. package/vite-mf/webpack/postcss.config.js +0 -6
  71. package/vite-mf/webpack/src/App.tsx +0 -16
  72. package/vite-mf/webpack/src/Image.tsx +0 -18
  73. package/vite-mf/webpack/src/assets/webpack-logo.png +0 -0
  74. package/vite-mf/webpack/src/global.d.ts +0 -4
  75. package/vite-mf/webpack/src/index.html +0 -12
  76. package/vite-mf/webpack/src/index.scss +0 -7
  77. package/vite-mf/webpack/src/index.ts +0 -1
  78. package/vite-mf/webpack/tailwind.config.js +0 -11
  79. package/vite-mf/webpack/tsconfig.json +0 -29
  80. package/vite-mf/webpack/webpack.config.js +0 -91
package/dist/index.mjs CHANGED
@@ -1,33 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import * as __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__ from "node:timers/promises";
3
2
  import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
4
- import * as __WEBPACK_EXTERNAL_MODULE_chalk__ from "chalk";
5
- import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__ from "node:timers/promises";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__ from "@clack/prompts";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_chalk__ from "chalk";
7
8
  import * as __WEBPACK_EXTERNAL_MODULE_tempy__ from "tempy";
8
- import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
9
- import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
10
- function end_note({ project }) {
11
- try {
12
- (0, __WEBPACK_EXTERNAL_MODULE_child_process__.exec)(`${project.path} && git config user.name`, (err, stdout, stderr)=>{
13
- console.log(stdout);
14
- const user_name = stdout.toString().trim();
15
- const repo_name = project.path.split('/').pop();
16
- let next_steps;
17
- next_steps = 'web' === project.type ? `cd ${repo_name} \npnpm install\nrm -rf .git\ngit remote add origin https://github.com/${user_name.length >= 1 ? user_name : 'YourUsername'}/${repo_name}.git\npnpm run build` : `cd ${repo_name} \npnpm install\nrm -rf .git\npnpm run build\nMake your first commit and link it to the remote repository!`;
18
- (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(next_steps, 'Next steps.');
19
- });
20
- } catch (error) {
21
- console.error(error);
22
- } finally{
23
- const end_notes = [
24
- `Discord: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://zephyr-cloud.io/discord'))}`,
25
- `Documentation: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://zephyr-cloud.io/docs'))}`,
26
- `Open an issue: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://github.com/ZephyrCloudIO/create-zephyr-apps/issues'))}`
27
- ];
28
- (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(Object.values(end_notes).join('\n'), 'Problems?');
29
- }
30
- }
31
9
  const TEMPLATES = {
32
10
  'rspack-project': {
33
11
  label: 'React + Rspack',
@@ -85,6 +63,69 @@ const TEMPLATES = {
85
63
  framework: 'react'
86
64
  }
87
65
  };
66
+ function end_note({ project }) {
67
+ try {
68
+ (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)('git config user.name', (err, stdout, stderr)=>{
69
+ const user_name = stdout.toString().trim();
70
+ const repo_name = project.path.split('/').pop();
71
+ let next_steps;
72
+ next_steps = 'web' === project.type ? [
73
+ `cd ${repo_name}`,
74
+ 'pnpm install',
75
+ 'pnpm run build'
76
+ ] : [
77
+ `cd ${repo_name}`,
78
+ 'pnpm install',
79
+ __WEBPACK_EXTERNAL_MODULE_chalk__["default"].magenta(`git remote add origin https://github.com/${user_name.length >= 1 ? user_name : 'YourUsername'}/${repo_name}.git`),
80
+ 'ZC=1 pnpm run start',
81
+ '\n--------------------------------\n',
82
+ 'Make sure to commit and add a remote to the remote repository!',
83
+ `Read more about how Module Federation works with Zephyr: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://docs.zephyr-cloud.io/how-to/mf-guide'))}`
84
+ ];
85
+ (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(next_steps.join('\n')), 'Next steps.');
86
+ });
87
+ } catch (error) {
88
+ console.error(error);
89
+ } finally{
90
+ const end_notes = [
91
+ `Discord: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://zephyr-cloud.io/discord'))}`,
92
+ `Documentation: ${'web' === project.type ? __WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://docs.zephyr-cloud.io/recipes')) : __WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://docs.zephyr-cloud.io/recipes/repack-mf'))}`,
93
+ `Open an issue: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://github.com/ZephyrCloudIO/create-zephyr-apps/issues'))}`
94
+ ];
95
+ (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(Object.values(end_notes).join('\n'), 'Problems?');
96
+ }
97
+ }
98
+ function runCmd(cmd, cwd) {
99
+ return new Promise((resolve, reject)=>{
100
+ (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(cmd, {
101
+ cwd
102
+ }, (err, stdout, stderr)=>{
103
+ if (err) {
104
+ console.error(`Error executing command: ${cmd}`, err);
105
+ reject(err);
106
+ } else resolve();
107
+ });
108
+ });
109
+ }
110
+ async function initializeGit(projectPath) {
111
+ const shouldInit = await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.confirm)({
112
+ message: 'Would you like to initialize a new Git repository?',
113
+ initialValue: true
114
+ });
115
+ if ((0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.isCancel)(shouldInit)) {
116
+ (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.cancel)('Operation cancelled');
117
+ process.exit(0);
118
+ }
119
+ if (shouldInit) {
120
+ await runCmd('git init', projectPath);
121
+ await runCmd('git config user.email "zephyrbot@zephyr-cloud.io"', projectPath);
122
+ await runCmd('git config user.name "Zephyr Bot"', projectPath);
123
+ await runCmd('git add .', projectPath);
124
+ await runCmd('git commit -m "Initial commit from Zephyr"', projectPath);
125
+ await runCmd('git config --unset user.email', projectPath);
126
+ await runCmd('git config --unset user.name', projectPath);
127
+ }
128
+ }
88
129
  async function main() {
89
130
  console.clear();
90
131
  await (0, __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__.setTimeout)(1000);
@@ -113,12 +154,13 @@ async function main() {
113
154
  options: [
114
155
  {
115
156
  value: 'web',
116
- label: 'Web'
157
+ label: 'Web',
158
+ hint: 'You will be choosing from a selection of templates provided by us.'
117
159
  },
118
160
  {
119
161
  value: 'react-native',
120
162
  label: 'React Native',
121
- hint: 'You will be building React Native powered by Re.Pack.'
163
+ hint: 'This is a comprehensive example project provided by us. You will be building React Native powered by Re.Pack.'
122
164
  }
123
165
  ]
124
166
  }),
@@ -146,64 +188,68 @@ async function main() {
146
188
  const project_path = project.path.replace('./', '').trim();
147
189
  const s = (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.spinner)();
148
190
  s.start(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(`Creating project in ${project_path}`));
149
- if ('web' === project.type) (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(command_web, async (err, stdout, stderr)=>{
150
- if (err) {
151
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning ${command_web} to ${project_path}...`)));
152
- console.error(err);
153
- process.exit(0);
154
- }
155
- if (!err) {
156
- const outputPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(process.cwd(), project.path);
157
- const clonedPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(temp_dir, 'examples', project.templates);
158
- try {
159
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.cp(clonedPath, outputPath, {
160
- recursive: true,
161
- force: true
162
- });
163
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(`Project successfully created at ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(project_path)}`));
164
- } catch (error) {
165
- console.error(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning to ${project_path}...`)));
166
- console.error(error);
167
- process.exit(2);
168
- } finally{
169
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(temp_dir, {
170
- recursive: true,
171
- force: true
172
- });
173
- end_note({
174
- project
175
- });
176
- }
177
- }
178
- });
179
- if ('react-native' === project.type) (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(command_react_native, async (err, stdout, stderr)=>{
180
- if (err) {
181
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning to ${project_path}...`)));
182
- console.error(err);
183
- process.exit(2);
184
- }
185
- if (!err) {
186
- const outputPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(process.cwd(), project.path);
187
- try {
188
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.cp(temp_dir, outputPath, {
189
- recursive: true,
190
- force: true
191
- });
192
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(`Project successfully created at ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(project_path)}`));
193
- } catch (error) {
194
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error clonin to ${project_path}`)));
195
- console.error(error);
196
- process.exit(2);
197
- } finally{
198
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(temp_dir, {
199
- recursive: true,
200
- force: true
201
- });
202
- end_note({
203
- project
204
- });
205
- }
206
- }
207
- });
191
+ const outputPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), project.path);
192
+ try {
193
+ if ('web' === project.type) await new Promise((resolve, reject)=>{
194
+ (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(command_web, async (err)=>{
195
+ if (err) {
196
+ s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning repository to ${project_path}...`)));
197
+ return reject(err);
198
+ }
199
+ const clonedPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(temp_dir, 'examples', project.templates);
200
+ try {
201
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(clonedPath, '.git'), {
202
+ recursive: true,
203
+ force: true
204
+ });
205
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.cp(clonedPath, outputPath, {
206
+ recursive: true,
207
+ force: true
208
+ });
209
+ s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(`Project successfully created at ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(project_path)}`));
210
+ resolve();
211
+ } catch (copyErr) {
212
+ s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error copying template to ${project_path}...`)));
213
+ reject(copyErr);
214
+ }
215
+ });
216
+ });
217
+ else if ('react-native' === project.type) await new Promise((resolve, reject)=>{
218
+ (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(command_react_native, async (err)=>{
219
+ if (err) {
220
+ s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning repository to ${project_path}...`)));
221
+ return reject(err);
222
+ }
223
+ try {
224
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(temp_dir, '.git'), {
225
+ recursive: true,
226
+ force: true
227
+ });
228
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.cp(temp_dir, outputPath, {
229
+ recursive: true,
230
+ force: true
231
+ });
232
+ s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(`Project successfully created at ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(project_path)}`));
233
+ resolve();
234
+ } catch (copyErr) {
235
+ s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error copying files to ${project_path}...`)));
236
+ reject(copyErr);
237
+ }
238
+ });
239
+ });
240
+ await initializeGit(outputPath);
241
+ (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)('Git repository and initial commit created successfully!');
242
+ } catch (error) {
243
+ console.error(error);
244
+ process.exit(2);
245
+ } finally{
246
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(temp_dir, {
247
+ recursive: true,
248
+ force: true
249
+ });
250
+ end_note({
251
+ project
252
+ });
253
+ }
208
254
  }
209
255
  main().catch(console.error);
@@ -60,4 +60,4 @@ declare const TEMPLATES: {
60
60
  framework: string;
61
61
  };
62
62
  };
63
- export { REPO_OWNER, REPO_NAME, REPACK_REPO, BASE_REPO, REPACK_REPO_PATH, TEMPLATES };
63
+ export { REPO_OWNER, REPO_NAME, REPACK_REPO, BASE_REPO, REPACK_REPO_PATH, TEMPLATES, };
@@ -1,4 +1,4 @@
1
- import { CLIOptions } from './types';
1
+ import type { CLIOptions } from './types';
2
2
  export default function end_note({ project }: {
3
3
  project: CLIOptions;
4
4
  }): void;
package/package/index.ts CHANGED
@@ -1,31 +1,79 @@
1
1
  #!/usr/bin/env node
2
- import { setTimeout } from 'node:timers/promises';
3
2
  import { exec } from 'node:child_process';
4
- import end_note from './utils/end'
3
+ import * as fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { setTimeout } from 'node:timers/promises';
5
6
  import {
6
- spinner,
7
+ cancel,
8
+ confirm,
7
9
  group,
8
10
  intro,
9
- outro,
10
11
  isCancel,
11
- password,
12
- cancel,
13
- text,
14
12
  note,
15
- confirm,
16
13
  select,
17
- multiselect,
18
- tasks,
19
- log,
14
+ spinner,
15
+ text,
20
16
  updateSettings,
21
17
  } from '@clack/prompts';
22
- import c from "chalk";
23
- import { TEMPLATES } from './utils/constants';
24
- import { CLIOptions } from './utils/types';
18
+ import c from 'chalk';
25
19
  import * as tempy from 'tempy';
26
- import path from 'path';
27
- import * as fs from 'node:fs'
20
+ import { TEMPLATES } from './utils/constants';
21
+ import end_note from './utils/end';
22
+ import type { CLIOptions } from './utils/types';
23
+
24
+ /**
25
+ * Helper function to execute a command in the given working directory.
26
+ */
27
+ function runCmd(cmd: string, cwd: string): Promise<void> {
28
+ return new Promise((resolve, reject) => {
29
+ exec(cmd, { cwd }, (err, stdout, stderr) => {
30
+ if (err) {
31
+ console.error(`Error executing command: ${cmd}`, err);
32
+ reject(err);
33
+ } else {
34
+ resolve();
35
+ }
36
+ });
37
+ });
38
+ }
28
39
 
40
+ /**
41
+ * Initialize Git in the project directory, set temporary user configuration,
42
+ * commit the changes, and then remove the local configuration.
43
+ */
44
+ async function initializeGit(projectPath: string): Promise<void> {
45
+ // Ask the user if they want to initialize a Git repository.
46
+ const shouldInit = await confirm({
47
+ message: 'Would you like to initialize a new Git repository?',
48
+ initialValue: true,
49
+ });
50
+
51
+ if (isCancel(shouldInit)) {
52
+ cancel('Operation cancelled');
53
+ process.exit(0);
54
+ }
55
+
56
+ if (shouldInit) {
57
+ // Initialize the repository.
58
+ await runCmd('git init', projectPath);
59
+
60
+ // Set temporary Git user configuration.
61
+ await runCmd(
62
+ 'git config user.email "zephyrbot@zephyr-cloud.io"',
63
+ projectPath,
64
+ );
65
+ await runCmd('git config user.name "Zephyr Bot"', projectPath);
66
+
67
+ // Stage all files and commit them.
68
+ await runCmd('git add .', projectPath);
69
+ await runCmd('git commit -m "Initial commit from Zephyr"', projectPath);
70
+
71
+ // Remove the temporary local Git configuration so that the user's global
72
+ // settings will be used for future commits.
73
+ await runCmd('git config --unset user.email', projectPath);
74
+ await runCmd('git config --unset user.name', projectPath);
75
+ }
76
+ }
29
77
 
30
78
  async function main() {
31
79
  console.clear();
@@ -44,7 +92,7 @@ async function main() {
44
92
  note('npx create-zephyr-apps@latest');
45
93
  intro(`${c.bgCyan(c.black(' Create federated applications with Zephyr '))}`);
46
94
 
47
- const project = await group(
95
+ const project = (await group(
48
96
  {
49
97
  path: ({ results }) => {
50
98
  return text({
@@ -65,33 +113,32 @@ async function main() {
65
113
  {
66
114
  value: 'web',
67
115
  label: 'Web',
116
+ hint: 'You will be choosing from a selection of templates provided by us.',
68
117
  },
69
118
  {
70
119
  value: 'react-native',
71
120
  label: 'React Native',
72
- hint: 'You will be building React Native powered by Re.Pack.',
121
+ hint: 'This is a comprehensive example project provided by us. You will be building React Native powered by Re.Pack.',
73
122
  },
74
123
  ],
75
124
  }),
76
125
 
77
126
  templates: ({ results }) => {
78
-
79
127
  if (results.type === 'web') {
80
128
  return select({
81
129
  message: 'Pick a template: ',
82
130
  initialValue: 'react-rspack-mf',
83
131
  maxItems: 5,
84
- options: Object.keys(TEMPLATES).map((template) => {
85
- return {
86
- value: template as keyof typeof TEMPLATES,
87
- label: c.cyan(TEMPLATES[template as keyof typeof TEMPLATES].label),
88
- hint: TEMPLATES[template as keyof typeof TEMPLATES].hint
89
- }
90
- })
91
- })
132
+ options: Object.keys(TEMPLATES).map(template => ({
133
+ value: template as keyof typeof TEMPLATES,
134
+ label: c.cyan(
135
+ TEMPLATES[template as keyof typeof TEMPLATES].label,
136
+ ),
137
+ hint: TEMPLATES[template as keyof typeof TEMPLATES].hint,
138
+ })),
139
+ });
92
140
  }
93
141
  },
94
-
95
142
  },
96
143
  {
97
144
  onCancel: () => {
@@ -99,92 +146,110 @@ async function main() {
99
146
  process.exit(0);
100
147
  },
101
148
  },
102
- ) as CLIOptions;
103
-
104
-
105
-
106
- const temp_dir = tempy.temporaryDirectory()
107
-
108
- const command_web = `git clone --depth 1 https://github.com/ZephyrCloudIO/zephyr-examples.git -b main ${temp_dir}`
109
- const command_react_native = `git clone --depth 1 https://github.com/ZephyrCloudIO/zephyr-repack-example.git -b main ${temp_dir}`
110
-
111
- const project_path = project.path.replace('./', '').trim()
112
-
113
- const s = spinner()
114
- s.start(c.cyan(`Creating project in ${project_path}`))
115
- if (project.type === 'web') {
116
-
117
-
118
- exec(command_web, async (err, stdout, stderr) => {
119
-
120
- if (err) {
121
- s.stop(c.bgRed(c.black(`Error cloning ${command_web} to ${project_path}...`)))
122
- console.error(err);
123
- process.exit(0);
124
-
125
- }
126
-
127
- if (!err) {
128
- const outputPath = path.join(process.cwd(), project.path);
129
-
130
- const clonedPath = path.join(temp_dir, 'examples', project.templates as string)
131
-
132
- try {
133
- const result2 = await fs.promises.cp(clonedPath, outputPath, {
134
- recursive: true,
135
- force: true
136
- });
137
-
138
- s.stop(c.green(`Project successfully created at ${c.underline(project_path)}`))
139
-
140
- } catch (error) {
141
- console.error(c.bgRed(c.black(`Error cloning to ${project_path}...`)))
142
- console.error(error)
143
- process.exit(2)
144
- } finally {
145
- await fs.promises.rm(temp_dir, { recursive: true, force: true })
146
- end_note({ project })
147
- }
148
- }
149
- })
150
-
151
- }
152
-
153
-
154
- if (project.type === 'react-native') {
155
-
156
-
157
- exec(command_react_native, async (err, stdout, stderr) => {
158
- if (err) {
159
- s.stop(c.bgRed(c.black(`Error cloning to ${project_path}...`)))
160
- console.error(err)
161
- process.exit(2)
162
- }
163
-
164
- if (!err) {
165
-
166
- const outputPath = path.join(process.cwd(), project.path);
167
- try {
168
- const result2 = await fs.promises.cp(temp_dir, outputPath, {
169
- recursive: true,
170
- force: true
171
- });
172
- s.stop(c.green(`Project successfully created at ${c.underline(project_path)}`))
173
- } catch (error) {
174
- s.stop(c.bgRed(c.black(`Error clonin to ${project_path}`)))
175
- console.error(error)
176
- process.exit(2)
177
- } finally {
178
- await fs.promises.rm(temp_dir, { recursive: true, force: true })
179
- end_note({ project })
180
- }
181
-
182
- }
183
- })
149
+ )) as CLIOptions;
150
+
151
+ const temp_dir = tempy.temporaryDirectory();
152
+ const command_web = `git clone --depth 1 https://github.com/ZephyrCloudIO/zephyr-examples.git -b main ${temp_dir}`;
153
+ const command_react_native = `git clone --depth 1 https://github.com/ZephyrCloudIO/zephyr-repack-example.git -b main ${temp_dir}`;
154
+
155
+ const project_path = project.path.replace('./', '').trim();
156
+ const s = spinner();
157
+ s.start(c.cyan(`Creating project in ${project_path}`));
158
+ const outputPath = path.join(process.cwd(), project.path);
159
+
160
+ try {
161
+ if (project.type === 'web') {
162
+ await new Promise<void>((resolve, reject) => {
163
+ exec(command_web, async err => {
164
+ if (err) {
165
+ s.stop(
166
+ c.bgRed(
167
+ c.black(`Error cloning repository to ${project_path}...`),
168
+ ),
169
+ );
170
+ return reject(err);
171
+ }
172
+
173
+ const clonedPath = path.join(
174
+ temp_dir,
175
+ 'examples',
176
+ project.templates as string,
177
+ );
178
+
179
+ try {
180
+ // Remove .git folder from the cloned template
181
+ await fs.promises.rm(path.join(clonedPath, '.git'), {
182
+ recursive: true,
183
+ force: true,
184
+ });
185
+
186
+ await fs.promises.cp(clonedPath, outputPath, {
187
+ recursive: true,
188
+ force: true,
189
+ });
190
+ s.stop(
191
+ c.green(
192
+ `Project successfully created at ${c.underline(project_path)}`,
193
+ ),
194
+ );
195
+ resolve();
196
+ } catch (copyErr) {
197
+ s.stop(
198
+ c.bgRed(c.black(`Error copying template to ${project_path}...`)),
199
+ );
200
+ reject(copyErr);
201
+ }
202
+ });
203
+ });
204
+ } else if (project.type === 'react-native') {
205
+ await new Promise<void>((resolve, reject) => {
206
+ exec(command_react_native, async err => {
207
+ if (err) {
208
+ s.stop(
209
+ c.bgRed(
210
+ c.black(`Error cloning repository to ${project_path}...`),
211
+ ),
212
+ );
213
+ return reject(err);
214
+ }
215
+
216
+ try {
217
+ // Remove .git folder from the cloned template
218
+ await fs.promises.rm(path.join(temp_dir, '.git'), {
219
+ recursive: true,
220
+ force: true,
221
+ });
222
+
223
+ await fs.promises.cp(temp_dir, outputPath, {
224
+ recursive: true,
225
+ force: true,
226
+ });
227
+ s.stop(
228
+ c.green(
229
+ `Project successfully created at ${c.underline(project_path)}`,
230
+ ),
231
+ );
232
+ resolve();
233
+ } catch (copyErr) {
234
+ s.stop(
235
+ c.bgRed(c.black(`Error copying files to ${project_path}...`)),
236
+ );
237
+ reject(copyErr);
238
+ }
239
+ });
240
+ });
241
+ }
242
+
243
+ // Initialize Git only if user confirms
244
+ await initializeGit(outputPath);
245
+ note('Git repository and initial commit created successfully!');
246
+ } catch (error) {
247
+ console.error(error);
248
+ process.exit(2);
249
+ } finally {
250
+ await fs.promises.rm(temp_dir, { recursive: true, force: true });
251
+ end_note({ project });
184
252
  }
185
-
186
-
187
253
  }
188
254
 
189
255
  main().catch(console.error);
190
-