create-zephyr-apps 0.0.8 → 0.0.39

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/package/index.ts DELETED
@@ -1,255 +0,0 @@
1
- #!/usr/bin/env node
2
- import { exec } from 'node:child_process';
3
- import * as fs from 'node:fs';
4
- import path from 'node:path';
5
- import { setTimeout } from 'node:timers/promises';
6
- import {
7
- cancel,
8
- confirm,
9
- group,
10
- intro,
11
- isCancel,
12
- note,
13
- select,
14
- spinner,
15
- text,
16
- updateSettings,
17
- } from '@clack/prompts';
18
- import c from 'chalk';
19
- import * as tempy from 'tempy';
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
- }
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
- }
77
-
78
- async function main() {
79
- console.clear();
80
-
81
- await setTimeout(1000);
82
-
83
- updateSettings({
84
- aliases: {
85
- w: 'up',
86
- s: 'down',
87
- a: 'left',
88
- d: 'right',
89
- },
90
- });
91
-
92
- note('npx create-zephyr-apps@latest');
93
- intro(`${c.bgCyan(c.black(' Create federated applications with Zephyr '))}`);
94
-
95
- const project = (await group(
96
- {
97
- path: ({ results }) => {
98
- return text({
99
- message: 'Where should we create your project?',
100
- placeholder: './sparkling-solid',
101
- validate: value => {
102
- if (!value) return 'Please enter a path.';
103
- if (value[0] !== '.') return 'Please enter a relative path.';
104
- },
105
- });
106
- },
107
-
108
- type: () =>
109
- select({
110
- message: 'What type of project you are creating?',
111
- initialValue: 'web',
112
- options: [
113
- {
114
- value: 'web',
115
- label: 'Web',
116
- hint: 'You will be choosing from a selection of templates provided by us.',
117
- },
118
- {
119
- value: 'react-native',
120
- label: 'React Native',
121
- hint: 'This is a comprehensive example project provided by us. You will be building React Native powered by Re.Pack.',
122
- },
123
- ],
124
- }),
125
-
126
- templates: ({ results }) => {
127
- if (results.type === 'web') {
128
- return select({
129
- message: 'Pick a template: ',
130
- initialValue: 'react-rspack-mf',
131
- maxItems: 5,
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
- });
140
- }
141
- },
142
- },
143
- {
144
- onCancel: () => {
145
- cancel('Operation cancelled.');
146
- process.exit(0);
147
- },
148
- },
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 });
252
- }
253
- }
254
-
255
- main().catch(console.error);
@@ -1,74 +0,0 @@
1
- const REPO_OWNER = 'ZephyrCloudIO';
2
- const REPO_NAME = 'zephyr-examples';
3
- const REPACK_REPO = 'zephyr-repack-example';
4
-
5
- const BASE_REPO = `${REPO_OWNER}/${REPO_NAME}`;
6
-
7
- const REPACK_REPO_PATH = `${REPO_OWNER}/${REPACK_REPO}`;
8
-
9
- const TEMPLATES = {
10
- 'rspack-project': {
11
- label: 'React + Rspack',
12
- hint: 'A simple application build by Rspack.',
13
- framework: 'react',
14
- },
15
- 'react-vite-ts': {
16
- label: 'A simple React application build by Vite',
17
- hint: 'You will be building React app powered by Vite.',
18
- framework: 'react',
19
- },
20
- 'react-vite-mf': {
21
- label: 'React + Vite + Webpack + Rspack',
22
- hint: 'You will be building federated React apps powered by Vite, Webpack and Rspack.',
23
- framework: 'react',
24
- },
25
- 'angular-vite': {
26
- label: 'Angular app with Vite',
27
- hint: 'You will be building an Angular app powered by Vite.',
28
- framework: 'angular',
29
- },
30
- 'react-webpack-mf': {
31
- label: 'React + Webpack',
32
- hint: 'A React application with Module Federation, using Webpack as the bundler.',
33
- framework: 'react',
34
- },
35
- 'nx-rspack-mf': {
36
- label: 'React + Nx + Rspack',
37
- hint: 'A React application with Module Federation, using Nx as Monorepo manager and Rspack as the bundler.',
38
- framework: 'react',
39
- },
40
- 'nx-webpack-mf': {
41
- label: 'React + Nx + Webpack',
42
- hint: 'React applications with Module Federation, using Nx as Monorepo manager and Webpack as the bundler.',
43
- framework: 'react',
44
- },
45
- 'ng-nx': {
46
- label: 'Angular app with Nx',
47
- hint: 'An Angular application with Nx as Monorepo manager.',
48
- framework: 'angular',
49
- },
50
- 'qwik-1.5': {
51
- label: 'Qwik + Vite',
52
- hint: 'A Qwik v1.5 app using Vite as the bundler.',
53
- framework: 'qwik',
54
- },
55
- 'react-rspack-tractor-2.0': {
56
- label: 'React + Rspack + Tractor 2.0',
57
- hint: 'A React application using Rspack as the bundler and Tractor 2.0 as the module federation manager.',
58
- framework: 'react',
59
- },
60
- 'turbo-rspack-mf': {
61
- label: 'Turbo + Rspack + Module Federation',
62
- hint: 'A monorepo using Turborepo, React, and Rspack as the bundler.',
63
- framework: 'react',
64
- },
65
- };
66
-
67
- export {
68
- REPO_OWNER,
69
- REPO_NAME,
70
- REPACK_REPO,
71
- BASE_REPO,
72
- REPACK_REPO_PATH,
73
- TEMPLATES,
74
- };
@@ -1,43 +0,0 @@
1
- import { exec } from 'node:child_process';
2
- import { note } from '@clack/prompts';
3
- import c from 'chalk';
4
- import type { CLIOptions } from './types';
5
-
6
- export default function end_note({ project }: { project: CLIOptions }) {
7
- try {
8
- exec('git config user.name', (err, stdout, stderr) => {
9
- const user_name = stdout.toString().trim();
10
- const repo_name = project.path.split('/').pop();
11
-
12
- let next_steps: string[];
13
-
14
- if (project.type === 'web') {
15
- next_steps = [`cd ${repo_name}`, 'pnpm install', 'pnpm run build'];
16
- } else {
17
- next_steps = [
18
- `cd ${repo_name}`,
19
- 'pnpm install',
20
- c.magenta(
21
- `git remote add origin https://github.com/${user_name.length >= 1 ? user_name : 'YourUsername'}/${repo_name}.git`,
22
- ),
23
- 'ZC=1 pnpm run start',
24
- '\n--------------------------------\n',
25
- 'Make sure to commit and add a remote to the remote repository!',
26
- `Read more about how Module Federation works with Zephyr: ${c.underline(c.cyan('https://docs.zephyr-cloud.io/how-to/mf-guide'))}`,
27
- ];
28
- }
29
-
30
- note(c.cyan(next_steps.join('\n')), 'Next steps.');
31
- });
32
- } catch (error) {
33
- console.error(error);
34
- } finally {
35
- const end_notes = [
36
- `Discord: ${c.underline(c.cyan('https://zephyr-cloud.io/discord'))}`,
37
- `Documentation: ${project.type === 'web' ? c.underline(c.cyan('https://docs.zephyr-cloud.io/recipes')) : c.underline(c.cyan('https://docs.zephyr-cloud.io/recipes/repack-mf'))}`,
38
- `Open an issue: ${c.underline(c.cyan('https://github.com/ZephyrCloudIO/create-zephyr-apps/issues'))}`,
39
- ];
40
-
41
- note(Object.values(end_notes).join('\n'), 'Problems?');
42
- }
43
- }
@@ -1,32 +0,0 @@
1
- export interface GithubTreeItem {
2
- path: string;
3
- type: 'tree' | 'blob';
4
- }
5
-
6
- export interface ExampleMetadata {
7
- name: string;
8
- description: string;
9
- path: string;
10
- }
11
-
12
- export interface WebCreationOptions {
13
- path: string;
14
- template: string;
15
- framework: string;
16
- }
17
-
18
- export interface ReactNativeCreationOptions {
19
- path: string;
20
- // host_name: string;
21
- // remote_names: string[];
22
- }
23
-
24
- export interface CLIOptions {
25
- path: string;
26
- type: 'web' | 'react-native';
27
- /** At the moment, if users opt for web they will only be asked for a template without host name and remote_name */
28
- templates: string | undefined;
29
- //host_name: string | undefined;
30
- //remote_names: string[] | undefined;
31
- install: boolean;
32
- }
package/rslib.config.ts DELETED
@@ -1,41 +0,0 @@
1
- import { defineConfig } from '@rslib/core';
2
-
3
- export default defineConfig({
4
- source: {
5
- entry: {
6
- index: './package/index.ts',
7
- },
8
- },
9
- lib: [
10
- {
11
- format: 'cjs',
12
- autoExtension: false,
13
- syntax: 'es2020',
14
- dts: {
15
- build: true,
16
- },
17
- output: {
18
- target: 'node',
19
- filename: {
20
- js: '[name].cjs',
21
- },
22
- cleanDistPath: true,
23
- },
24
- },
25
- {
26
- format: 'esm',
27
- autoExtension: false,
28
- syntax: 'es2020',
29
- dts: {
30
- build: true,
31
- },
32
- output: {
33
- target: 'node',
34
- filename: {
35
- js: '[name].mjs',
36
- },
37
- cleanDistPath: true,
38
- },
39
- },
40
- ],
41
- });
package/tsconfig.json DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // Enable latest features
4
- "lib": ["ESNext"],
5
- "target": "ES2020",
6
- "module": "ES2020",
7
- "moduleDetection": "force",
8
-
9
- "allowJs": true,
10
-
11
- // Bundler mode
12
- "moduleResolution": "bundler",
13
- "allowSyntheticDefaultImports": true,
14
- "allowImportingTsExtensions": true,
15
- //"verbatimModuleSyntax": true,
16
- "noEmit": true,
17
-
18
- // Best practices
19
- "strict": true,
20
- "skipLibCheck": true,
21
- "noFallthroughCasesInSwitch": true,
22
-
23
- // Some stricter flags (disabled by default)
24
- "noUnusedLocals": false,
25
- "noUnusedParameters": false,
26
- "noPropertyAccessFromIndexSignature": false,
27
- "outDir": "./dist",
28
- "types": ["node"]
29
- }
30
- }
File without changes