create-sy 2.2.2 → 2.2.7-alpha.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/README.md +1 -4
- package/package.json +2 -2
- package/build/constants.js +0 -5
- package/build/createSyngrisiProject.js +0 -37
- package/build/index.js +0 -60
- package/build/types.js +0 -1
- package/build/utils.js +0 -106
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ dependencies, allowing you to get started quickly.
|
|
|
5
5
|
|
|
6
6
|
## Prerequisites
|
|
7
7
|
|
|
8
|
-
This initializer is for installing Syngrisi in native mode, therefore you need `Node.js >=
|
|
8
|
+
This initializer is for installing Syngrisi in native mode, therefore you need `Node.js >= v20.9.0`and `MongoDB >= 7.0` or remote MongoDB instance. If you want to install a dockerized Syngrisi service, please read the [Syngrisi documentation](https://github.com/syngrisi/syngrisi/tree/main/packages/syngrisi#readme).
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
@@ -37,6 +37,3 @@ npm init sy my-app-dir -- -f -y
|
|
|
37
37
|
|
|
38
38
|
This command initializes a Syngrisi project in my-app-dir, bypassing pre-install checks and confirming prompts
|
|
39
39
|
automatically.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sy",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7-alpha.0",
|
|
4
4
|
"description": "Install and setup Syngrisi",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Viktar Silakou",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"read-pkg-up": "^10.1.0",
|
|
73
73
|
"semver": "^7.3.8"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "57c6a0fe6a65e619c9b61cf1bab75784ea40a8e9"
|
|
76
76
|
}
|
package/build/constants.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export const MONGODB_SETUP_MANUAL_URL = 'https://www.mongodb.com/docs/manual/installation/';
|
|
2
|
-
export const DOCKER_SETUP_MANUAL_URL = 'https://docs.docker.com/engine/install/';
|
|
3
|
-
export const SYNGRISI_DOCUMENTATION_LINK = 'https://github.com/syngrisi/syngrisi/tree/main/packages/syngrisi#readme';
|
|
4
|
-
export const NODE_VERSION = '>=14';
|
|
5
|
-
export const MONGODB_VERSION = '>=7.0';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { readPackageUp } from 'read-pkg-up';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import ora from 'ora';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { getSyngrisiVersion, printAndExit, runProgram } from './utils.js';
|
|
7
|
-
export const createSyngrisiProject = async (opts) => {
|
|
8
|
-
if (!opts.installDir) {
|
|
9
|
-
printAndExit('installDir is empty');
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
let npmTag = '';
|
|
13
|
-
if (opts.npmTag) {
|
|
14
|
-
npmTag = opts.npmTag?.startsWith('@') ? opts.npmTag : `@${opts.npmTag}`;
|
|
15
|
-
}
|
|
16
|
-
const root = opts.installDir;
|
|
17
|
-
/**
|
|
18
|
-
* check if a package.json exists and if not create one
|
|
19
|
-
*/
|
|
20
|
-
const project = await readPackageUp({ cwd: root });
|
|
21
|
-
if (!project) {
|
|
22
|
-
await fs.mkdir(root, { recursive: true });
|
|
23
|
-
await fs.writeFile(path.resolve(root, 'package.json'), JSON.stringify({
|
|
24
|
-
name: 'syngrisi_new_project',
|
|
25
|
-
}, null, 2));
|
|
26
|
-
/**
|
|
27
|
-
* create a package-lock.json
|
|
28
|
-
*/
|
|
29
|
-
await runProgram('npm', ['install'], { cwd: root, stdio: 'ignore' });
|
|
30
|
-
}
|
|
31
|
-
const spinner = ora(chalk.green(`Installing ${chalk.bold('Syngrisi')}`)).start();
|
|
32
|
-
await runProgram('npm', ['install', `@syngrisi/syngrisi${npmTag}`], { cwd: root, stdio: 'ignore' });
|
|
33
|
-
spinner.stop();
|
|
34
|
-
console.log(chalk.green(`✔ Syngrisi ${chalk.greenBright(getSyngrisiVersion(root))} successfully installed in the following directory: ${root}`));
|
|
35
|
-
console.log(chalk.white(`To run the application use the ${chalk.whiteBright('npx sy')} command`));
|
|
36
|
-
console.log(chalk.white.bold('For detailed configuration see https://github.com/syngrisi/syngrisi/tree/main/packages/syngrisi'));
|
|
37
|
-
};
|
package/build/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// noinspection ExceptionCaughtLocallyJS
|
|
2
|
-
import * as utils from './utils.js';
|
|
3
|
-
import { MONGODB_SETUP_MANUAL_URL, MONGODB_VERSION, NODE_VERSION, SYNGRISI_DOCUMENTATION_LINK } from './constants.js';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { createSyngrisiProject } from './createSyngrisiProject.js';
|
|
6
|
-
import { checkMongoDB } from './utils.js';
|
|
7
|
-
export async function run() {
|
|
8
|
-
try {
|
|
9
|
-
const args = utils.parseArguments();
|
|
10
|
-
if (args.help || args._.includes('--help')) {
|
|
11
|
-
console.log(`
|
|
12
|
-
Usage: syngrisi [DIRECTORY] [OPTIONS]
|
|
13
|
-
|
|
14
|
-
DIRECTORY:
|
|
15
|
-
Specify the directory where Syngrisi will be installed. If not provided, the current directory will be used.
|
|
16
|
-
|
|
17
|
-
Options:
|
|
18
|
-
-f, --force Force the installation even if the checks are not passed
|
|
19
|
-
-y, --yes Automatically agree to continue the installation
|
|
20
|
-
--help Show usage information and exit
|
|
21
|
-
`);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (args.yes === undefined && !args._.includes('--yes')) {
|
|
25
|
-
const continueInstallation = await utils.prompt('Do you want to continue with the installation?');
|
|
26
|
-
if (!continueInstallation) {
|
|
27
|
-
console.log(chalk.yellow('❌ Installation canceled'));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (args.force === undefined && !args._.includes('--force')) {
|
|
32
|
-
const mongoCheck = checkMongoDB();
|
|
33
|
-
if (!mongoCheck || (!mongoCheck.supported && (mongoCheck.version === 'unknown'))) {
|
|
34
|
-
console.log(chalk.yellow('⚠️ MongoDB is not installed.'
|
|
35
|
-
+ `Please install MongoDB if you want to run Syngrisi in the native mode. ${MONGODB_SETUP_MANUAL_URL}\n`));
|
|
36
|
-
}
|
|
37
|
-
if (!mongoCheck.supported && (mongoCheck.version !== 'unknown')) {
|
|
38
|
-
console.log(chalk.yellow(`⚠️ Wrong MongoDB version: '${mongoCheck.version}' `
|
|
39
|
-
+ `Please install the proper MongoDB version: '${MONGODB_VERSION}' if you want to run Syngrisi in the native mode. ${MONGODB_SETUP_MANUAL_URL}\n`
|
|
40
|
-
+ `Or use standalone remote MongoDB instance, for more information read Syngrisi documentation ${SYNGRISI_DOCUMENTATION_LINK}.`));
|
|
41
|
-
}
|
|
42
|
-
const versionObj = utils.checkNodeVersion();
|
|
43
|
-
if (!versionObj.supported) {
|
|
44
|
-
const msg = `❌ This version: '${versionObj.version}' of Node.js is not supported. Please use Node.js version ${NODE_VERSION}\n`;
|
|
45
|
-
console.log(chalk.yellow(msg));
|
|
46
|
-
process.exitCode = 1;
|
|
47
|
-
throw new Error(msg);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const dirParam = args._[0] || '.';
|
|
51
|
-
const installDir = dirParam !== '.' ? dirParam : utils.getDirectoryName();
|
|
52
|
-
return createSyngrisiProject({
|
|
53
|
-
installDir,
|
|
54
|
-
npmTag: args.npmTag || ''
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error(chalk.red(error.message));
|
|
59
|
-
}
|
|
60
|
-
}
|
package/build/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/utils.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import child_process from 'node:child_process';
|
|
3
|
-
import fss from 'node:fs';
|
|
4
|
-
import inquirer from 'inquirer';
|
|
5
|
-
import { MONGODB_VERSION, NODE_VERSION } from './constants.js';
|
|
6
|
-
import semver from 'semver';
|
|
7
|
-
import minimist from 'minimist';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import spawn from 'cross-spawn';
|
|
10
|
-
export const checkNodeVersion = () => {
|
|
11
|
-
const unsupportedNodeVersion = !semver.satisfies(process.version, NODE_VERSION);
|
|
12
|
-
return {
|
|
13
|
-
supported: !unsupportedNodeVersion,
|
|
14
|
-
version: process.version
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export const checkDocker = () => {
|
|
18
|
-
try {
|
|
19
|
-
child_process.execSync('docker-compose -v');
|
|
20
|
-
console.log(chalk.green('✔ Docker Compose is installed.'));
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
console.log(chalk.yellow(err));
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
// export const checkEmptyDirectory = (directory: string): boolean => {
|
|
29
|
-
// return fs.readdirSync(directory).length <= 0
|
|
30
|
-
// }
|
|
31
|
-
export const getDirectoryName = () => process.cwd();
|
|
32
|
-
export const getSyngrisiVersion = (installDir) => {
|
|
33
|
-
return JSON.parse(fss.readFileSync(path.join(installDir, 'package.json')).toString()).dependencies?.syngrisi;
|
|
34
|
-
};
|
|
35
|
-
export const installDependencies = (directory) => {
|
|
36
|
-
child_process.execSync('npm install', { cwd: directory, stdio: 'inherit' });
|
|
37
|
-
};
|
|
38
|
-
export const prompt = async (message) => {
|
|
39
|
-
const { answer } = await inquirer.prompt([
|
|
40
|
-
{
|
|
41
|
-
type: 'confirm',
|
|
42
|
-
name: 'answer',
|
|
43
|
-
default: 'y',
|
|
44
|
-
message,
|
|
45
|
-
},
|
|
46
|
-
]);
|
|
47
|
-
return answer;
|
|
48
|
-
};
|
|
49
|
-
export const getInstalledMongoVersion = () => {
|
|
50
|
-
const versionOutput = child_process.execSync('mongod --version').toString();
|
|
51
|
-
const versionMatch = versionOutput.match(/db version v(\d+\.\d+\.\d+)/);
|
|
52
|
-
if (!versionMatch) {
|
|
53
|
-
throw new Error(chalk.red(`❌ Cannot parse MongoDB version, output: '${versionOutput}'`));
|
|
54
|
-
}
|
|
55
|
-
return versionMatch[1];
|
|
56
|
-
};
|
|
57
|
-
export const checkMongoDB = () => {
|
|
58
|
-
try {
|
|
59
|
-
const installedVersion = getInstalledMongoVersion();
|
|
60
|
-
if (!semver.satisfies(installedVersion, MONGODB_VERSION)) {
|
|
61
|
-
console.error(chalk.red(`❌ MongoDB version is not satisfies requirements: '${MONGODB_VERSION}'. Installed version is '${installedVersion}'.`));
|
|
62
|
-
return { version: installedVersion, supported: false };
|
|
63
|
-
}
|
|
64
|
-
console.log(chalk.green(`✔ MongoDB version is satisfactory. Installed version is ${installedVersion}.`));
|
|
65
|
-
return { version: installedVersion, supported: true };
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.error(chalk.yellow(`Error checking MongoDB version: ${error.message}`));
|
|
69
|
-
return { version: 'unknown', supported: false };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
export function printAndExit(error, signal) {
|
|
73
|
-
if (signal === 'SIGINT') {
|
|
74
|
-
console.log('\n\nGoodbye 👋');
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
console.error(`\n\nRuntime error: '${error}'`);
|
|
78
|
-
}
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
export function getArgs() {
|
|
82
|
-
const args = process.argv.slice(2);
|
|
83
|
-
return minimist(args);
|
|
84
|
-
}
|
|
85
|
-
export function parseArguments() {
|
|
86
|
-
const parsedArgs = getArgs();
|
|
87
|
-
// Handle shorthands
|
|
88
|
-
parsedArgs.force = parsedArgs.force || parsedArgs.f;
|
|
89
|
-
parsedArgs.yes = parsedArgs.yes || parsedArgs.y;
|
|
90
|
-
return parsedArgs;
|
|
91
|
-
}
|
|
92
|
-
export function runProgram(command, args, options) {
|
|
93
|
-
const child = spawn(command, args, { stdio: 'inherit', ...options });
|
|
94
|
-
return new Promise((resolve, rejects) => {
|
|
95
|
-
let error;
|
|
96
|
-
child.on('error', (e) => (error = e));
|
|
97
|
-
child.on('close', (code, signal) => {
|
|
98
|
-
if (code !== 0) {
|
|
99
|
-
const errorMessage = (error && error.message) || `Error calling: ${command} ${args.join(' ')}`;
|
|
100
|
-
printAndExit(errorMessage, signal);
|
|
101
|
-
return rejects(errorMessage);
|
|
102
|
-
}
|
|
103
|
-
resolve();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|