create-o2s-app 0.9.1

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/.eslintrc.js ADDED
@@ -0,0 +1,10 @@
1
+ /** @type {import("eslint").Linter.Config} */
2
+ module.exports = {
3
+ root: true,
4
+ extends: ['@o2s/eslint-config/api.js'],
5
+ parser: '@typescript-eslint/parser',
6
+ parserOptions: {
7
+ project: './tsconfig.lint.json',
8
+ tsconfigRootDir: __dirname,
9
+ },
10
+ };
@@ -0,0 +1,11 @@
1
+ import baseConfig from "@o2s/prettier-config/base.mjs";
2
+
3
+ /**
4
+ * @see https://prettier.io/docs/en/configuration.html
5
+ * @type {import("prettier").Config}
6
+ */
7
+ const config = {
8
+ ...baseConfig,
9
+ };
10
+
11
+ export default config;
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # create-o2s-app
2
+
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 2c79c35: initial release
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const child_process_1 = require("child_process");
8
+ const cli_progress_1 = __importDefault(require("cli-progress"));
9
+ const commander_1 = require("commander");
10
+ const fs_1 = require("fs");
11
+ const prompts_1 = __importDefault(require("prompts"));
12
+ const simple_git_1 = __importDefault(require("simple-git"));
13
+ const program = new commander_1.Command();
14
+ program
15
+ .name('create-project')
16
+ .description('Create a new O2S project')
17
+ .argument('[name]', 'Name of the new project')
18
+ .option('--directory [directory]', 'Specify the destination directory', 'my-o2s-project')
19
+ .action(async (name, options) => {
20
+ const projectName = name
21
+ ? name
22
+ : (await (0, prompts_1.default)({
23
+ type: 'text',
24
+ name: 'name',
25
+ message: 'Enter the name of your project',
26
+ initial: 'my-o2s-project',
27
+ })).name;
28
+ const targetDirectory = projectName || options.directory;
29
+ const githubRepo = 'https://github.com/o2sdev/openselfservice';
30
+ const githubBranch = 'main';
31
+ if ((0, fs_1.existsSync)(targetDirectory)) {
32
+ console.error(`Directory ${targetDirectory} already exists. Please choose a different name or remove the existing directory.`);
33
+ return;
34
+ }
35
+ const bar = new cli_progress_1.default.SingleBar({}, cli_progress_1.default.Presets.shades_classic);
36
+ try {
37
+ (0, fs_1.mkdirSync)(targetDirectory, { recursive: true });
38
+ console.log();
39
+ console.log(`Cloning repository "${githubRepo}" (branch: "${githubBranch}") into "${targetDirectory}"...`);
40
+ console.log();
41
+ bar.start(100, 0);
42
+ const git = (0, simple_git_1.default)({
43
+ progress({ progress }) {
44
+ bar.update(Math.round(progress));
45
+ },
46
+ });
47
+ await git.clone(githubRepo, targetDirectory, ['--branch', githubBranch]);
48
+ bar.stop();
49
+ console.log();
50
+ console.log();
51
+ console.log('Organizing the project structure...');
52
+ (0, fs_1.rmSync)(`${targetDirectory}/.git`, { recursive: true });
53
+ (0, fs_1.rmSync)(`${targetDirectory}/.github`, { recursive: true });
54
+ (0, fs_1.rmSync)(`${targetDirectory}/.changeset`, { recursive: true });
55
+ (0, fs_1.rmSync)(`${targetDirectory}/vercel.json`, { recursive: true });
56
+ (0, fs_1.rmSync)(`${targetDirectory}/apps/docs`, { recursive: true });
57
+ (0, fs_1.rmSync)(`${targetDirectory}/packages/framework`, { recursive: true });
58
+ (0, fs_1.rmSync)(`${targetDirectory}/packages/integrations`, { recursive: true });
59
+ (0, fs_1.rmSync)(`${targetDirectory}/packages/utils`, { recursive: true });
60
+ (0, fs_1.rmSync)(`${targetDirectory}/packages/create-o2s-app`, { recursive: true });
61
+ let file = (0, fs_1.readFileSync)(targetDirectory + '/package-lock.json', 'utf8');
62
+ file = removeSymLinks(file);
63
+ (0, fs_1.writeFileSync)(targetDirectory + '/package-lock.json', file);
64
+ console.log();
65
+ console.log(`Installing dependencies in "${targetDirectory}"...`);
66
+ try {
67
+ (0, child_process_1.execSync)('npm install', {
68
+ cwd: targetDirectory,
69
+ stdio: 'inherit',
70
+ });
71
+ console.log(`Dependencies installed successfully.`);
72
+ }
73
+ catch (error) {
74
+ console.error('Error while installing dependencies:', error);
75
+ return;
76
+ }
77
+ console.log();
78
+ console.log(`Locking O2S packages to the latest stable release...`);
79
+ try {
80
+ (0, child_process_1.execSync)('npm install @o2s/framework@latest @o2s/utils.logger@latest @o2s/integrations.mocked --workspace=@o2s/api-harmonization', {
81
+ cwd: targetDirectory,
82
+ stdio: 'inherit',
83
+ });
84
+ console.log(`Dependencies installed successfully.`);
85
+ }
86
+ catch (error) {
87
+ console.error('Error while installing dependencies:', error);
88
+ return;
89
+ }
90
+ console.log();
91
+ console.log('Project successfully created! 🎉');
92
+ console.log(`Location: ${targetDirectory}`);
93
+ }
94
+ catch (error) {
95
+ bar.stop();
96
+ console.log();
97
+ if (error instanceof Error) {
98
+ console.error('Error while creating the project', error.message);
99
+ }
100
+ else {
101
+ console.error('Error while creating the project');
102
+ }
103
+ }
104
+ });
105
+ program.parse(process.argv);
106
+ const removeSymLinks = (file) => {
107
+ const names = [
108
+ ['docs', 'apps/docs'],
109
+ ['create-o2s-app', 'packages/create-o2s-app'],
110
+ ['utils.logger', 'packages/utils/logger'],
111
+ ['framework', 'packages/framework'],
112
+ ['integrations.mocked', 'packages/integrations/mocked'],
113
+ ['integrations.strapi-cms', 'packages/integrations/strapi-cms'],
114
+ ['integrations.redis', 'packages/integrations/redis'],
115
+ ];
116
+ let newFile = file;
117
+ names.forEach(([name, path]) => {
118
+ newFile = newFile.replaceAll(`
119
+ "node_modules/@o2s/${name}": {
120
+ "resolved": "${path}",
121
+ "link": true
122
+ },`, '');
123
+ });
124
+ return newFile;
125
+ };
@@ -0,0 +1,4 @@
1
+ export default {
2
+ '*.{js,jsx,ts,tsx,css,scss}': ['prettier --write'],
3
+ '*.{js,jsx,ts,tsx}': () => 'tsc --noEmit',
4
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "create-o2s-app",
3
+ "version": "0.9.1",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "create-o2s-app": "./dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "create-o2s-app": "ts-node ./src/index.ts",
12
+ "build": "tsc && tsc-alias",
13
+ "lint": "tsc --noEmit && eslint . --max-warnings 0",
14
+ "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,json}\""
15
+ },
16
+ "dependencies": {
17
+ "@types/adm-zip": "^0.5.7",
18
+ "@types/prompts": "^2.4.9",
19
+ "adm-zip": "^0.5.16",
20
+ "cli-progress": "^3.12.0",
21
+ "commander": "^13.1.0",
22
+ "node-fetch": "^2.7.0",
23
+ "node-fetch-progress": "^1.0.2",
24
+ "prompts": "^2.4.2",
25
+ "replace-in-file": "^8.3.0",
26
+ "simple-git": "^3.27.0",
27
+ "ts-node": "^10.9.2"
28
+ },
29
+ "devDependencies": {
30
+ "@o2s/eslint-config": "*",
31
+ "@o2s/prettier-config": "*",
32
+ "@o2s/typescript-config": "*",
33
+ "@types/cli-progress": "^3.11.6",
34
+ "@types/node-fetch": "^2.6.12",
35
+ "eslint": "^8.57.0",
36
+ "prettier": "^3.4.1",
37
+ "typescript": "^5.7.3"
38
+ }
39
+ }
package/src/index.ts ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'child_process';
3
+ import cliProgress from 'cli-progress';
4
+ import { Command } from 'commander';
5
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
6
+ import prompts from 'prompts';
7
+ import simpleGit from 'simple-git';
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .name('create-project')
13
+ .description('Create a new O2S project')
14
+ .argument('[name]', 'Name of the new project')
15
+ .option('--directory [directory]', 'Specify the destination directory', 'my-o2s-project')
16
+ .action(async (name, options) => {
17
+ const projectName = name
18
+ ? name
19
+ : (
20
+ await prompts({
21
+ type: 'text',
22
+ name: 'name',
23
+ message: 'Enter the name of your project',
24
+ initial: 'my-o2s-project',
25
+ })
26
+ ).name;
27
+
28
+ const targetDirectory = projectName || options.directory;
29
+
30
+ const githubRepo = 'https://github.com/o2sdev/openselfservice';
31
+ const githubBranch = 'main';
32
+
33
+ if (existsSync(targetDirectory)) {
34
+ console.error(
35
+ `Directory ${targetDirectory} already exists. Please choose a different name or remove the existing directory.`,
36
+ );
37
+ return;
38
+ }
39
+
40
+ const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
41
+
42
+ try {
43
+ mkdirSync(targetDirectory, { recursive: true });
44
+
45
+ console.log();
46
+ console.log(`Cloning repository "${githubRepo}" (branch: "${githubBranch}") into "${targetDirectory}"...`);
47
+ console.log();
48
+
49
+ bar.start(100, 0);
50
+
51
+ const git = simpleGit({
52
+ progress({ progress }) {
53
+ bar.update(Math.round(progress));
54
+ },
55
+ });
56
+ await git.clone(githubRepo, targetDirectory, ['--branch', githubBranch]);
57
+
58
+ bar.stop();
59
+
60
+ console.log();
61
+ console.log();
62
+ console.log('Organizing the project structure...');
63
+
64
+ rmSync(`${targetDirectory}/.git`, { recursive: true });
65
+ rmSync(`${targetDirectory}/.github`, { recursive: true });
66
+ rmSync(`${targetDirectory}/.changeset`, { recursive: true });
67
+
68
+ rmSync(`${targetDirectory}/vercel.json`, { recursive: true });
69
+
70
+ rmSync(`${targetDirectory}/apps/docs`, { recursive: true });
71
+ rmSync(`${targetDirectory}/packages/framework`, { recursive: true });
72
+ rmSync(`${targetDirectory}/packages/integrations`, { recursive: true });
73
+ rmSync(`${targetDirectory}/packages/utils`, { recursive: true });
74
+ rmSync(`${targetDirectory}/packages/create-o2s-app`, { recursive: true });
75
+
76
+ let file = readFileSync(targetDirectory + '/package-lock.json', 'utf8');
77
+ file = removeSymLinks(file);
78
+ writeFileSync(targetDirectory + '/package-lock.json', file);
79
+
80
+ console.log();
81
+ console.log(`Installing dependencies in "${targetDirectory}"...`);
82
+
83
+ try {
84
+ execSync('npm install', {
85
+ cwd: targetDirectory,
86
+ stdio: 'inherit',
87
+ });
88
+ console.log(`Dependencies installed successfully.`);
89
+ } catch (error) {
90
+ console.error('Error while installing dependencies:', error);
91
+ return;
92
+ }
93
+
94
+ console.log();
95
+ console.log(`Locking O2S packages to the latest stable release...`);
96
+
97
+ try {
98
+ execSync(
99
+ 'npm install @o2s/framework@latest @o2s/utils.logger@latest @o2s/integrations.mocked --workspace=@o2s/api-harmonization',
100
+ {
101
+ cwd: targetDirectory,
102
+ stdio: 'inherit',
103
+ },
104
+ );
105
+ console.log(`Dependencies installed successfully.`);
106
+ } catch (error) {
107
+ console.error('Error while installing dependencies:', error);
108
+ return;
109
+ }
110
+
111
+ console.log();
112
+ console.log('Project successfully created! 🎉');
113
+ console.log(`Location: ${targetDirectory}`);
114
+ } catch (error) {
115
+ bar.stop();
116
+
117
+ console.log();
118
+
119
+ if (error instanceof Error) {
120
+ console.error('Error while creating the project', error.message);
121
+ } else {
122
+ console.error('Error while creating the project');
123
+ }
124
+ }
125
+ });
126
+
127
+ program.parse(process.argv);
128
+
129
+ const removeSymLinks = (file: string) => {
130
+ const names = [
131
+ ['docs', 'apps/docs'],
132
+ ['create-o2s-app', 'packages/create-o2s-app'],
133
+ ['utils.logger', 'packages/utils/logger'],
134
+ ['framework', 'packages/framework'],
135
+ ['integrations.mocked', 'packages/integrations/mocked'],
136
+ ['integrations.strapi-cms', 'packages/integrations/strapi-cms'],
137
+ ['integrations.redis', 'packages/integrations/redis'],
138
+ ];
139
+
140
+ let newFile = file;
141
+
142
+ names.forEach(([name, path]) => {
143
+ newFile = newFile.replaceAll(
144
+ `
145
+ "node_modules/@o2s/${name}": {
146
+ "resolved": "${path}",
147
+ "link": true
148
+ },`,
149
+ '',
150
+ );
151
+ });
152
+
153
+ return newFile;
154
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@o2s/typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "paths": {},
5
+ "outDir": "./dist"
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["node_modules", "dist"]
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@o2s/typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src", "turbo"],
7
+ "exclude": ["node_modules", "dist"]
8
+ }