create-strive 0.1.0-beta.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/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # create-strive
2
+
3
+ Создание нового приложения на [Strive](https://github.com/your-repo/strive).
4
+
5
+ ## Использование
6
+
7
+ ```bash
8
+ npx create-strive market
9
+ cd market
10
+ npm install
11
+ npm run dev
12
+ ```
13
+
14
+ Опция `--install` сразу запускает `npm install`:
15
+
16
+ ```bash
17
+ npx create-strive market --install
18
+ cd market && npm run dev
19
+ ```
20
+
21
+ ## Что создаётся
22
+
23
+ - `index.html` — точка входа HTML
24
+ - `strive.config.ts` — конфигурация Strive и Vite
25
+ - `package.json` — скрипты `dev`, `build`, `start` и зависимости
26
+ - `main.ts` — запуск production-сервера (вызов `strive({ mode: 'production', configPath: './strive.config.ts', ... })`)
27
+ - `src/entry.tsx` — одна строка, подключение клиентской гидрации из пакета
28
+ - `src/pages/index.page.tsx` — пример страницы
29
+
30
+ Client-entry и ssr-entry живут внутри пакета strivejs, их не нужно править в проекте.
31
+
32
+ В `strive.config.ts` можно передавать опции Vite в поле `vite` — они мержатся с конфигом при `dev` и `build`.
package/index.js ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'path';
4
+ import fs from 'fs';
5
+ import { fileURLToPath } from 'url';
6
+ import { spawnSync } from 'child_process';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const TEMPLATE_DIR = path.join(__dirname, 'template');
10
+
11
+ function copyRecursive(src, dest, name) {
12
+ const entries = fs.readdirSync(src, { withFileTypes: true });
13
+ for (const ent of entries) {
14
+ const srcPath = path.join(src, ent.name);
15
+ const destPath = path.join(dest, ent.name);
16
+ if (ent.isDirectory()) {
17
+ fs.mkdirSync(destPath, { recursive: true });
18
+ copyRecursive(srcPath, destPath, name);
19
+ } else {
20
+ let content = fs.readFileSync(srcPath, 'utf-8');
21
+ content = content.replace(/\{\{name\}\}/g, name);
22
+ fs.writeFileSync(destPath, content, 'utf-8');
23
+ }
24
+ }
25
+ }
26
+
27
+ const name = process.argv[2];
28
+ if (!name) {
29
+ console.log('Usage: npx create-strive <project-name>');
30
+ console.log('Example: npx create-strive market');
31
+ process.exit(1);
32
+ }
33
+
34
+ const dest = path.resolve(process.cwd(), name);
35
+ if (fs.existsSync(dest)) {
36
+ console.error(`Error: folder "${name}" already exists.`);
37
+ process.exit(1);
38
+ }
39
+
40
+ fs.mkdirSync(dest, { recursive: true });
41
+ copyRecursive(TEMPLATE_DIR, dest, name);
42
+
43
+ console.log(`\nCreated ${name}/\n`);
44
+ console.log('Next:');
45
+ console.log(` cd ${name}`);
46
+ console.log(' npm install');
47
+ console.log(' npm run dev\n');
48
+
49
+ const runInstall = process.argv.includes('--install') || process.argv.includes('-i');
50
+ if (runInstall) {
51
+ console.log('Running npm install...');
52
+ const r = spawnSync('npm', ['install'], { cwd: dest, stdio: 'inherit', shell: true });
53
+ if (r.status !== 0) process.exit(r.status ?? 1);
54
+ console.log('\nDone. Run: npm run dev\n');
55
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "create-strive",
3
+ "version": "0.1.0-beta.2",
4
+ "description": "Scaffold a new Strive app",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-strive": "index.js"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "template"
12
+ ],
13
+ "keywords": [
14
+ "strive",
15
+ "strivejs",
16
+ "scaffold",
17
+ "create"
18
+ ],
19
+ "license": "MIT"
20
+ }
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="ru">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>{{name}}</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"><!--app--></div>
10
+ <script type="module" src="/src/entry.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,16 @@
1
+ import { strive } from 'strivejs';
2
+
3
+ const PORT = Number(process.env.PORT) || 3000;
4
+
5
+ const app = await strive({
6
+ baseIndexHtmlPath: './dist/client/index.html',
7
+ routing: {
8
+ page: { dir: './src/pages', filePattern: /\.page\.(tsx|ts|jsx|js)$/ },
9
+ },
10
+ mode: 'production',
11
+ // configPath не указываем — strive ищет strive.config.ts в той же папке, что и main.ts (cwd)
12
+ });
13
+
14
+ app.listen(PORT, () => {
15
+ console.log(`[Strive] http://localhost:${PORT}`);
16
+ });
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "tsx node_modules/strivejs/scripts/run-dev.ts",
8
+ "build": "tsx node_modules/strivejs/scripts/run-build.ts",
9
+ "start": "node dist/server/server.js"
10
+ },
11
+ "dependencies": {
12
+ "strivejs": "^0.1.0-beta.2",
13
+ "express": "^5.2.1",
14
+ "react": "^18.3.1",
15
+ "react-dom": "^18.3.1"
16
+ },
17
+ "devDependencies": {
18
+ "tsx": "^4.19.2",
19
+ "typescript": "~5.9.3",
20
+ "@types/react": "^18.3.12",
21
+ "@types/react-dom": "^18.3.1",
22
+ "@types/node": "^22.10.5",
23
+ "vite": "^5.4.21",
24
+ "@vitejs/plugin-react": "^4.3.4"
25
+ }
26
+ }
@@ -0,0 +1 @@
1
+ import 'strivejs/client-entry';
@@ -0,0 +1,11 @@
1
+ import { defineStrivePage } from 'strivejs';
2
+
3
+ export default defineStrivePage({
4
+ render: 'ssr',
5
+ component: () => (
6
+ <div>
7
+ <h1>Добро пожаловать в Strive</h1>
8
+ <p>Страница из шаблона create-strive.</p>
9
+ </div>
10
+ ),
11
+ });
File without changes
@@ -0,0 +1,18 @@
1
+ import { defineStriveConfig } from 'strivejs';
2
+
3
+ export default defineStriveConfig({
4
+ baseIndexHtmlPath: './index.html',
5
+ staticDir: './static',
6
+ cacheDir: './dist/prerendered',
7
+ routing: {
8
+ page: {
9
+ dir: './src/pages',
10
+ filePattern: /\.page\.(tsx|ts|jsx|js)$/,
11
+ },
12
+ },
13
+ vite: {
14
+ // Конфигурация Vite (мержится с дефолтной при dev/build)
15
+ // server: { port: 3001 },
16
+ // resolve: { alias: { '@': '/src' } },
17
+ },
18
+ });
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "jsx": "react-jsx",
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "resolveJsonModule": true,
12
+ "isolatedModules": true,
13
+ "noEmit": true
14
+ },
15
+ "include": ["src", "strive.config.ts", "main.ts"]
16
+ }