create-zephyr-apps 0.0.7 → 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.
package/dist/index.mjs CHANGED
@@ -1,53 +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)("git config user.name", (err, stdout, stderr)=>{
13
- const user_name = stdout.toString().trim();
14
- const repo_name = project.path.split('/').pop();
15
- let next_steps;
16
- next_steps = 'web' === project.type ? [
17
- `cd ${repo_name}`,
18
- "pnpm install",
19
- "rm -rf .git",
20
- "git init",
21
- `git remote add origin https://github.com/${user_name.length >= 1 ? user_name : 'YourUsername'}/${repo_name}.git`,
22
- "git add .",
23
- 'git commit -m "Initial commit"',
24
- "pnpm run build"
25
- ] : [
26
- `cd ${repo_name}`,
27
- "pnpm install",
28
- "rm -rf .git",
29
- "git init",
30
- __WEBPACK_EXTERNAL_MODULE_chalk__["default"].magenta(`git remote add origin https://github.com/${user_name.length >= 1 ? user_name : 'YourUsername'}/${repo_name}.git`),
31
- "git add .",
32
- 'git commit -m "Initial commit"',
33
- "ZC=1 pnpm run start",
34
- `\n--------------------------------\n`,
35
- "Make your first commit and link it to the remote repository!",
36
- `Read more about how Module Federation works with Zephyr and why steps above are required: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://docs.zephyr-cloud.io/how-to/mf-guide'))}`
37
- ];
38
- (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(next_steps.join('\n')), 'Next steps.');
39
- });
40
- } catch (error) {
41
- console.error(error);
42
- } finally{
43
- const end_notes = [
44
- `Discord: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://zephyr-cloud.io/discord'))}`,
45
- `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'))}`,
46
- `Open an issue: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan('https://github.com/ZephyrCloudIO/create-zephyr-apps/issues'))}`
47
- ];
48
- (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(Object.values(end_notes).join('\n'), 'Problems?');
49
- }
50
- }
51
9
  const TEMPLATES = {
52
10
  'rspack-project': {
53
11
  label: 'React + Rspack',
@@ -105,6 +63,69 @@ const TEMPLATES = {
105
63
  framework: 'react'
106
64
  }
107
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
+ }
108
129
  async function main() {
109
130
  console.clear();
110
131
  await (0, __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__.setTimeout)(1000);
@@ -167,64 +188,68 @@ async function main() {
167
188
  const project_path = project.path.replace('./', '').trim();
168
189
  const s = (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.spinner)();
169
190
  s.start(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(`Creating project in ${project_path}`));
170
- if ('web' === project.type) (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(command_web, async (err, stdout, stderr)=>{
171
- if (err) {
172
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning ${command_web} to ${project_path}...`)));
173
- console.error(err);
174
- process.exit(0);
175
- }
176
- if (!err) {
177
- const outputPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(process.cwd(), project.path);
178
- const clonedPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(temp_dir, 'examples', project.templates);
179
- try {
180
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.cp(clonedPath, outputPath, {
181
- recursive: true,
182
- force: true
183
- });
184
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(`Project successfully created at ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(project_path)}`));
185
- } catch (error) {
186
- console.error(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning to ${project_path}...`)));
187
- console.error(error);
188
- process.exit(2);
189
- } finally{
190
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(temp_dir, {
191
- recursive: true,
192
- force: true
193
- });
194
- end_note({
195
- project
196
- });
197
- }
198
- }
199
- });
200
- if ('react-native' === project.type) (0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.exec)(command_react_native, async (err, stdout, stderr)=>{
201
- if (err) {
202
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error cloning to ${project_path}...`)));
203
- console.error(err);
204
- process.exit(2);
205
- }
206
- if (!err) {
207
- const outputPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(process.cwd(), project.path);
208
- try {
209
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.cp(temp_dir, outputPath, {
210
- recursive: true,
211
- force: true
212
- });
213
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(`Project successfully created at ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(project_path)}`));
214
- } catch (error) {
215
- s.stop(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].bgRed(__WEBPACK_EXTERNAL_MODULE_chalk__["default"].black(`Error clonin to ${project_path}`)));
216
- console.error(error);
217
- process.exit(2);
218
- } finally{
219
- await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.rm(temp_dir, {
220
- recursive: true,
221
- force: true
222
- });
223
- end_note({
224
- project
225
- });
226
- }
227
- }
228
- });
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
+ }
229
254
  }
230
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({
@@ -76,23 +124,21 @@ async function main() {
76
124
  }),
77
125
 
78
126
  templates: ({ results }) => {
79
-
80
127
  if (results.type === 'web') {
81
128
  return select({
82
129
  message: 'Pick a template: ',
83
130
  initialValue: 'react-rspack-mf',
84
131
  maxItems: 5,
85
- options: Object.keys(TEMPLATES).map((template) => {
86
- return {
87
- value: template as keyof typeof TEMPLATES,
88
- label: c.cyan(TEMPLATES[template as keyof typeof TEMPLATES].label),
89
- hint: TEMPLATES[template as keyof typeof TEMPLATES].hint
90
- }
91
- })
92
- })
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
+ });
93
140
  }
94
141
  },
95
-
96
142
  },
97
143
  {
98
144
  onCancel: () => {
@@ -100,92 +146,110 @@ async function main() {
100
146
  process.exit(0);
101
147
  },
102
148
  },
103
- ) as CLIOptions;
104
-
105
-
106
-
107
- const temp_dir = tempy.temporaryDirectory()
108
-
109
- const command_web = `git clone --depth 1 https://github.com/ZephyrCloudIO/zephyr-examples.git -b main ${temp_dir}`
110
- const command_react_native = `git clone --depth 1 https://github.com/ZephyrCloudIO/zephyr-repack-example.git -b main ${temp_dir}`
111
-
112
- const project_path = project.path.replace('./', '').trim()
113
-
114
- const s = spinner()
115
- s.start(c.cyan(`Creating project in ${project_path}`))
116
- if (project.type === 'web') {
117
-
118
-
119
- exec(command_web, async (err, stdout, stderr) => {
120
-
121
- if (err) {
122
- s.stop(c.bgRed(c.black(`Error cloning ${command_web} to ${project_path}...`)))
123
- console.error(err);
124
- process.exit(0);
125
-
126
- }
127
-
128
- if (!err) {
129
- const outputPath = path.join(process.cwd(), project.path);
130
-
131
- const clonedPath = path.join(temp_dir, 'examples', project.templates as string)
132
-
133
- try {
134
- const result2 = await fs.promises.cp(clonedPath, outputPath, {
135
- recursive: true,
136
- force: true
137
- });
138
-
139
- s.stop(c.green(`Project successfully created at ${c.underline(project_path)}`))
140
-
141
- } catch (error) {
142
- console.error(c.bgRed(c.black(`Error cloning to ${project_path}...`)))
143
- console.error(error)
144
- process.exit(2)
145
- } finally {
146
- await fs.promises.rm(temp_dir, { recursive: true, force: true })
147
- end_note({ project })
148
- }
149
- }
150
- })
151
-
152
- }
153
-
154
-
155
- if (project.type === 'react-native') {
156
-
157
-
158
- exec(command_react_native, async (err, stdout, stderr) => {
159
- if (err) {
160
- s.stop(c.bgRed(c.black(`Error cloning to ${project_path}...`)))
161
- console.error(err)
162
- process.exit(2)
163
- }
164
-
165
- if (!err) {
166
-
167
- const outputPath = path.join(process.cwd(), project.path);
168
- try {
169
- const result2 = await fs.promises.cp(temp_dir, outputPath, {
170
- recursive: true,
171
- force: true
172
- });
173
- s.stop(c.green(`Project successfully created at ${c.underline(project_path)}`))
174
- } catch (error) {
175
- s.stop(c.bgRed(c.black(`Error clonin to ${project_path}`)))
176
- console.error(error)
177
- process.exit(2)
178
- } finally {
179
- await fs.promises.rm(temp_dir, { recursive: true, force: true })
180
- end_note({ project })
181
- }
182
-
183
- }
184
- })
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 });
185
252
  }
186
-
187
-
188
253
  }
189
254
 
190
255
  main().catch(console.error);
191
-