create-astratra-app 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Astratra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # create-astratra-app
2
+
3
+ Generateur CLI pour creer rapidement une application Astratra.
4
+
5
+ ## Installation
6
+
7
+ Commande recommandee :
8
+
9
+ ```bash
10
+ npm create astratra-app@latest my-app
11
+ ```
12
+
13
+ Equivalent :
14
+
15
+ ```bash
16
+ npx create-astratra-app my-app
17
+ ```
18
+
19
+ ## Templates
20
+
21
+ Template complet par defaut :
22
+
23
+ ```bash
24
+ npm create astratra-app@latest my-app
25
+ ```
26
+
27
+ Il genere :
28
+
29
+ - une API Express avec `@astratra/saas-kit` ;
30
+ - une interface React avec `@astratra/saas-kit-ui` ;
31
+ - les scripts `dev:api` et `dev:web` ;
32
+ - un `.env.example` avec le port API, le host et les origins CORS de
33
+ developpement.
34
+
35
+ Template API seule :
36
+
37
+ ```bash
38
+ npm create astratra-app@latest my-api -- --template api
39
+ ```
40
+
41
+ ## Apres generation
42
+
43
+ ```bash
44
+ cd my-app
45
+ npm install
46
+ npm run dev:api
47
+ npm run dev:web
48
+ ```
49
+
50
+ Pour le template `api`, seul `npm run dev:api` est cree.
51
+
52
+ Avant la production, il faut remplacer `JWT_SECRET`, brancher de vrais stores
53
+ et utiliser une vraie verification de mot de passe.
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { createProject, parseArgs } from '../src/createProject.js';
3
+
4
+ try {
5
+ const options = parseArgs(process.argv.slice(2));
6
+ const result = createProject(options);
7
+ console.log(`Astratra app created in ${result.targetDir}`);
8
+ console.log('');
9
+ console.log('Next steps:');
10
+ for (const command of result.nextSteps) {
11
+ console.log(` ${command}`);
12
+ }
13
+ } catch (error) {
14
+ console.error(`create-astratra-app: ${error.message}`);
15
+ process.exit(1);
16
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "create-astratra-app",
3
+ "version": "0.1.0",
4
+ "description": "CLI generator for new Astratra SaaS applications.",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-astratra-app": "bin/create-astratra-app.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src"
12
+ ],
13
+ "scripts": {
14
+ "test": "node --test __tests__/*.test.js"
15
+ },
16
+ "keywords": [
17
+ "astratra",
18
+ "create",
19
+ "starter",
20
+ "saas"
21
+ ],
22
+ "license": "MIT",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ }
26
+ }
@@ -0,0 +1,249 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const VALID_TEMPLATES = new Set(['api', 'fullstack']);
5
+
6
+ function toPackageName(projectName) {
7
+ return projectName
8
+ .trim()
9
+ .toLowerCase()
10
+ .replace(/[^a-z0-9._-]+/g, '-')
11
+ .replace(/^-+|-+$/g, '') || 'astratra-app';
12
+ }
13
+
14
+ function writeFile(targetDir, filePath, content) {
15
+ const absolutePath = path.join(targetDir, filePath);
16
+ fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
17
+ fs.writeFileSync(absolutePath, content);
18
+ }
19
+
20
+ function assertCanCreate(targetDir, force) {
21
+ if (!fs.existsSync(targetDir)) return;
22
+ const entries = fs.readdirSync(targetDir);
23
+ if (entries.length > 0 && !force) {
24
+ throw new Error(`Target directory is not empty: ${targetDir}`);
25
+ }
26
+ }
27
+
28
+ function packageJson(projectName, template) {
29
+ const dependencies = {
30
+ '@astratra/saas-kit': '^0.1.0',
31
+ express: '^4.18.3'
32
+ };
33
+ const devDependencies = {};
34
+
35
+ if (template === 'fullstack') {
36
+ dependencies['@astratra/saas-kit-ui'] = '^0.1.0';
37
+ dependencies.react = '^19.0.0';
38
+ dependencies['react-dom'] = '^19.0.0';
39
+ devDependencies['@vitejs/plugin-react'] = '^4.3.4';
40
+ devDependencies.vite = '^7.0.0';
41
+ }
42
+
43
+ return JSON.stringify({
44
+ name: toPackageName(projectName),
45
+ version: '0.1.0',
46
+ private: true,
47
+ type: 'module',
48
+ scripts: {
49
+ 'dev:api': 'node api/server.js',
50
+ ...(template === 'fullstack' ? { 'dev:web': 'vite --host 127.0.0.1' } : {}),
51
+ start: 'node api/server.js'
52
+ },
53
+ dependencies,
54
+ ...(Object.keys(devDependencies).length > 0 ? { devDependencies } : {})
55
+ }, null, 2);
56
+ }
57
+
58
+ function apiServer() {
59
+ return `import express from 'express';
60
+ import saasKit from '@astratra/saas-kit';
61
+
62
+ const { createSaasApp, createMemorySettingsStore } = saasKit;
63
+ const port = Number(process.env.PORT || 4000);
64
+ const host = process.env.HOST || '127.0.0.1';
65
+ const allowedOrigins = new Set((process.env.CORS_ORIGIN || 'http://127.0.0.1:5173,http://localhost:5173')
66
+ .split(',')
67
+ .map((origin) => origin.trim())
68
+ .filter(Boolean));
69
+
70
+ const app = express();
71
+ app.use((req, res, next) => {
72
+ const origin = req.headers.origin;
73
+ if (origin && allowedOrigins.has(origin)) {
74
+ res.setHeader('Access-Control-Allow-Origin', origin);
75
+ res.setHeader('Vary', 'Origin');
76
+ }
77
+ res.setHeader('Access-Control-Allow-Headers', 'content-type, authorization');
78
+ res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PATCH,OPTIONS');
79
+ if (req.method === 'OPTIONS') {
80
+ res.status(204).end();
81
+ return;
82
+ }
83
+ next();
84
+ });
85
+
86
+ app.use(createSaasApp({
87
+ jwtSecret: process.env.JWT_SECRET || 'change-me-in-production',
88
+ settingsStore: createMemorySettingsStore({
89
+ productName: 'Astratra App',
90
+ supportEmail: 'support@example.test',
91
+ onboardingEnabled: true
92
+ }),
93
+ verifyPassword: async (user, password) => user.password === password,
94
+ notify: async (message) => ({ delivered: true, message })
95
+ }));
96
+
97
+ app.listen(port, host, () => {
98
+ console.log(\`Astratra API listening on http://\${host}:\${port}\`);
99
+ console.log('Seeded owner: owner@example.test / password');
100
+ console.log('Seeded member: member@example.test / password');
101
+ });
102
+ `;
103
+ }
104
+
105
+ function viteConfig() {
106
+ return `import react from '@vitejs/plugin-react';
107
+ import { defineConfig } from 'vite';
108
+
109
+ export default defineConfig({
110
+ root: 'web',
111
+ plugins: [react()],
112
+ server: {
113
+ host: '127.0.0.1',
114
+ port: 5173
115
+ }
116
+ });
117
+ `;
118
+ }
119
+
120
+ function webIndex() {
121
+ return `<!doctype html>
122
+ <html lang="fr">
123
+ <head>
124
+ <meta charset="UTF-8" />
125
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
126
+ <title>Astratra App</title>
127
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
128
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
129
+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet" />
130
+ </head>
131
+ <body>
132
+ <div id="root"></div>
133
+ <script type="module" src="/src/main.jsx"></script>
134
+ </body>
135
+ </html>
136
+ `;
137
+ }
138
+
139
+ function webMain() {
140
+ return `import React from 'react';
141
+ import { createRoot } from 'react-dom/client';
142
+ import { AstratraDashboardApp } from '@astratra/saas-kit-ui';
143
+
144
+ createRoot(document.getElementById('root')).render(
145
+ <React.StrictMode>
146
+ <AstratraDashboardApp />
147
+ </React.StrictMode>
148
+ );
149
+ `;
150
+ }
151
+
152
+ function readme(projectName, template) {
153
+ const webSteps = template === 'fullstack'
154
+ ? `
155
+ Dans un deuxieme terminal :
156
+
157
+ \`\`\`bash
158
+ npm run dev:web
159
+ \`\`\`
160
+ `
161
+ : '';
162
+
163
+ return `# ${projectName}
164
+
165
+ Application generee avec Astratra.
166
+
167
+ ## Installation
168
+
169
+ \`\`\`bash
170
+ npm install
171
+ \`\`\`
172
+
173
+ ## Lancement
174
+
175
+ \`\`\`bash
176
+ npm run dev:api
177
+ \`\`\`
178
+ ${webSteps}
179
+ Comptes de test :
180
+
181
+ - \`owner@example.test\` / \`password\`
182
+ - \`member@example.test\` / \`password\`
183
+
184
+ Avant la production, remplace \`JWT_SECRET\`, branche de vrais stores et change
185
+ la verification de mot de passe.
186
+ `;
187
+ }
188
+
189
+ export function parseArgs(args) {
190
+ const options = {
191
+ targetDir: null,
192
+ template: 'fullstack',
193
+ force: false
194
+ };
195
+
196
+ for (let index = 0; index < args.length; index += 1) {
197
+ const arg = args[index];
198
+ if (arg === '--force') {
199
+ options.force = true;
200
+ } else if (arg === '--template') {
201
+ options.template = args[index + 1];
202
+ index += 1;
203
+ } else if (arg.startsWith('--template=')) {
204
+ options.template = arg.slice('--template='.length);
205
+ } else if (!options.targetDir) {
206
+ options.targetDir = arg;
207
+ } else {
208
+ throw new Error(`Unknown argument: ${arg}`);
209
+ }
210
+ }
211
+
212
+ if (!options.targetDir) {
213
+ throw new Error('Usage: create-astratra-app <directory> [--template api|fullstack] [--force]');
214
+ }
215
+ if (!VALID_TEMPLATES.has(options.template)) {
216
+ throw new Error(`Unknown template "${options.template}". Use api or fullstack.`);
217
+ }
218
+
219
+ return options;
220
+ }
221
+
222
+ export function createProject({ targetDir, template = 'fullstack', force = false }, cwd = process.cwd()) {
223
+ const absoluteTarget = path.resolve(cwd, targetDir);
224
+ const projectName = path.basename(absoluteTarget);
225
+
226
+ assertCanCreate(absoluteTarget, force);
227
+ fs.mkdirSync(absoluteTarget, { recursive: true });
228
+
229
+ writeFile(absoluteTarget, 'package.json', `${packageJson(projectName, template)}\n`);
230
+ writeFile(absoluteTarget, 'api/server.js', apiServer());
231
+ writeFile(absoluteTarget, '.env.example', 'PORT=4000\nHOST=127.0.0.1\nJWT_SECRET=change-me\nCORS_ORIGIN=http://127.0.0.1:5173,http://localhost:5173\n');
232
+ writeFile(absoluteTarget, 'README.md', readme(projectName, template));
233
+
234
+ if (template === 'fullstack') {
235
+ writeFile(absoluteTarget, 'vite.config.js', viteConfig());
236
+ writeFile(absoluteTarget, 'web/index.html', webIndex());
237
+ writeFile(absoluteTarget, 'web/src/main.jsx', webMain());
238
+ }
239
+
240
+ return {
241
+ targetDir: absoluteTarget,
242
+ nextSteps: [
243
+ `cd ${targetDir}`,
244
+ 'npm install',
245
+ 'npm run dev:api',
246
+ ...(template === 'fullstack' ? ['npm run dev:web'] : [])
247
+ ]
248
+ };
249
+ }