create-kosh-erp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +42 -2
- package/index.js +126 -0
- package/package.json +37 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Isahaq
|
|
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
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-kosh-erp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install [Kosh](https://www.npmjs.com/package/kosh-erp) and set it up in one command:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm create kosh-erp@latest my-erp
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It creates the folder, installs `kosh-erp` (Shutro comes with it), then asks for:
|
|
10
|
+
|
|
11
|
+
- the PostgreSQL database (your server, or one started in Docker for you; a missing database is created)
|
|
12
|
+
- the company (name, currency, language, time zone)
|
|
13
|
+
- the administrator (login, name, email, password) and its authenticator app
|
|
14
|
+
- the apps (roles and approvals, reports and documents, chatter and attachments)
|
|
15
|
+
- file storage (a folder or S3), Valkey (optional), the API port
|
|
16
|
+
|
|
17
|
+
and sets everything up: the project files and `.env`, the database tables, the administrator, the seed data, and
|
|
18
|
+
the back-office's build tools. Then:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
cd my-erp
|
|
22
|
+
npm start # the API
|
|
23
|
+
npm run web # the back-office → http://localhost:5173
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Options for `kosh init` go after `--`:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm create kosh-erp@latest my-erp -- --docker-db
|
|
30
|
+
npm create kosh-erp@latest my-erp -- --yes --database-url postgres://user:pass@localhost:5432/my_erp \
|
|
31
|
+
--create-database --company "Padma Traders" --admin-password "a long passphrase here"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`pnpm create kosh-erp` and `yarn create kosh-erp` work too. The full guide (Docker, modules, migrations, seed data,
|
|
35
|
+
users, every command) is on the [kosh-erp page](https://www.npmjs.com/package/kosh-erp).
|
|
36
|
+
|
|
37
|
+
## Author
|
|
38
|
+
|
|
39
|
+
**Isahaq**, hmisahaq01@gmail.com, mobile +8801852376598
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `npm create kosh-erp@latest [folder] [-- kosh init options]`: a complete Kosh installation in one command.
|
|
4
|
+
*
|
|
5
|
+
* 1. creates the folder and a package.json (or uses the existing one),
|
|
6
|
+
* 2. installs kosh-erp (Shutro comes with it) with the package manager that ran this,
|
|
7
|
+
* 3. runs `kosh init`, which asks for the database, the company, the administrator, the apps, file storage and
|
|
8
|
+
* the port, then creates the database tables, the administrator and the seed data,
|
|
9
|
+
* 4. installs what the project needs next (the back-office's build tools),
|
|
10
|
+
* 5. prints how to start it.
|
|
11
|
+
*
|
|
12
|
+
* Plain JavaScript without dependencies: it runs before anything is installed.
|
|
13
|
+
*/
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { basename, join, resolve } from 'node:path';
|
|
17
|
+
import { createInterface } from 'node:readline/promises';
|
|
18
|
+
|
|
19
|
+
const own = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
20
|
+
/** What to install: kosh-erp of the same minor version (KOSH_ERP_SPEC overrides it, e.g. a local tarball). */
|
|
21
|
+
const [major, minor] = own.version.split('.');
|
|
22
|
+
const spec = process.env.KOSH_ERP_SPEC ?? `kosh-erp@^${major}.${minor}.0`;
|
|
23
|
+
|
|
24
|
+
// `npm create kosh-erp my-erp -- --yes …` reaches us without the `--` (npm consumes it); `npx create-kosh-erp`
|
|
25
|
+
// keeps it. Either way: an optional folder first, everything else is for kosh init.
|
|
26
|
+
const argv = process.argv.slice(2).filter((a, i, all) => !(a === '--' && all.indexOf('--') === i));
|
|
27
|
+
const positional = argv[0] !== undefined && !argv[0].startsWith('-') ? argv[0] : undefined;
|
|
28
|
+
const forInit = positional === undefined ? argv : argv.slice(1);
|
|
29
|
+
|
|
30
|
+
if (forInit.length === argv.length && (argv[0] === '--help' || argv[0] === '-h')) {
|
|
31
|
+
process.stdout.write(`Usage: npm create kosh-erp@latest [folder] [-- kosh init options]
|
|
32
|
+
|
|
33
|
+
Creates a Kosh installation in [folder]: installs kosh-erp, then asks for the database, the company, the
|
|
34
|
+
administrator, the apps, file storage and the port, and sets everything up.
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
npm create kosh-erp@latest my-erp
|
|
38
|
+
npm create kosh-erp@latest my-erp -- --docker-db
|
|
39
|
+
npm create kosh-erp@latest my-erp -- --yes --database-url postgres://… --admin-password "…"
|
|
40
|
+
`);
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The package manager that ran us (npm create, pnpm create, yarn create). */
|
|
45
|
+
const agent = process.env.npm_config_user_agent ?? '';
|
|
46
|
+
const pm = agent.startsWith('pnpm') ? 'pnpm' : agent.startsWith('yarn') ? 'yarn' : 'npm';
|
|
47
|
+
/**
|
|
48
|
+
* Runs a command in this terminal. The package manager is a .cmd script on Windows and needs a shell there, so its
|
|
49
|
+
* arguments are quoted; Node itself runs without one (its path may contain spaces: C:\Program Files\nodejs).
|
|
50
|
+
*/
|
|
51
|
+
const run = (command, args, cwd, env = {}) => {
|
|
52
|
+
const options = { cwd, stdio: 'inherit', env: { ...process.env, ...env } };
|
|
53
|
+
if (command === process.execPath || process.platform !== 'win32')
|
|
54
|
+
return spawnSync(command, args, options).status ?? 1;
|
|
55
|
+
// One command line, each part quoted when it needs it (the shell gets no separate argument list).
|
|
56
|
+
const quote = (a) => (/[\s"&|<>^]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a);
|
|
57
|
+
return (
|
|
58
|
+
spawnSync([command, ...args].map(quote).join(' '), { ...options, shell: true }).status ?? 1
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
const add = (cwd, what) =>
|
|
62
|
+
run(pm, pm === 'npm' ? ['install', '--no-audit', '--no-fund', ...what] : ['add', ...what], cwd);
|
|
63
|
+
const installAll = (cwd) =>
|
|
64
|
+
run(pm, pm === 'npm' ? ['install', '--no-audit', '--no-fund'] : ['install'], cwd);
|
|
65
|
+
|
|
66
|
+
async function folder() {
|
|
67
|
+
if (positional !== undefined) return positional;
|
|
68
|
+
if (!process.stdin.isTTY) return 'my-erp';
|
|
69
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
70
|
+
const answer = (await rl.question('Project folder [my-erp]: ')).trim();
|
|
71
|
+
rl.close();
|
|
72
|
+
return answer === '' ? 'my-erp' : answer;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const target = resolve(await folder());
|
|
76
|
+
const name =
|
|
77
|
+
basename(target)
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.replace(/[^a-z0-9-]+/g, '-') || 'kosh-app';
|
|
80
|
+
process.stdout.write(`\nCreating a Kosh installation in ${target}\n\n`);
|
|
81
|
+
mkdirSync(target, { recursive: true });
|
|
82
|
+
if (!existsSync(join(target, 'package.json')))
|
|
83
|
+
writeFileSync(
|
|
84
|
+
join(target, 'package.json'),
|
|
85
|
+
`${JSON.stringify({ name, version: '0.1.0', private: true, type: 'module' }, null, 2)}\n`,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
process.stdout.write(`Installing ${spec} …\n`);
|
|
89
|
+
if (add(target, [spec]) !== 0) {
|
|
90
|
+
process.stderr.write(`\nInstalling ${spec} failed (see above).\n`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const cli = join(target, 'node_modules', 'kosh-erp', 'dist', 'cli', 'bin.js');
|
|
95
|
+
if (!existsSync(cli)) {
|
|
96
|
+
process.stderr.write(`\n${cli} is missing: the kosh-erp installation is incomplete.\n`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
process.stdout.write('\n');
|
|
100
|
+
// kosh init asks its questions in this terminal (stdio inherited), then sets up the database.
|
|
101
|
+
const init = run(process.execPath, [cli, 'init', '.', ...forInit], target, { KOSH_CREATE: '1' });
|
|
102
|
+
if (init !== 0) {
|
|
103
|
+
process.stderr.write(
|
|
104
|
+
`\nThe setup stopped. Fix the problem above, then finish it with:\n cd ${positional ?? basename(target)}\n npx kosh init\n`,
|
|
105
|
+
);
|
|
106
|
+
process.exit(init);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
process.stdout.write('\nInstalling the back-office tools …\n');
|
|
110
|
+
if (installAll(target) !== 0) {
|
|
111
|
+
process.stderr.write(`\n${pm} install failed (see above); run it again in ${target}.\n`);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const cd = target === resolve('.') ? '' : ` cd ${positional ?? basename(target)}\n`;
|
|
116
|
+
const start = pm === 'npm' ? 'npm start' : `${pm} start`;
|
|
117
|
+
const web = pm === 'npm' ? 'npm run web' : `${pm} web`;
|
|
118
|
+
process.stdout.write(`
|
|
119
|
+
Kosh is installed.
|
|
120
|
+
|
|
121
|
+
${cd} ${start} # the API (reads .env)
|
|
122
|
+
${web} # the back-office, in a second terminal → http://localhost:5173
|
|
123
|
+
|
|
124
|
+
Everything in Docker instead: docker compose up -d --build → http://localhost:8080
|
|
125
|
+
Guide: https://www.npmjs.com/package/kosh-erp
|
|
126
|
+
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-kosh-erp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "npm create kosh-erp: install Kosh and set it up in one command (database, company, administrator, apps, port)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"kosh",
|
|
7
|
+
"kosh-erp",
|
|
8
|
+
"erp",
|
|
9
|
+
"create",
|
|
10
|
+
"starter",
|
|
11
|
+
"postgresql"
|
|
12
|
+
],
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Isahaq",
|
|
15
|
+
"email": "hmisahaq01@gmail.com"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"homepage": "https://github.com/isahaq1/kosh#readme",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/isahaq1/kosh.git",
|
|
22
|
+
"directory": "packages/create-kosh-erp"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/isahaq1/kosh/issues"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"bin": {
|
|
29
|
+
"create-kosh-erp": "index.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"index.js",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=24"
|
|
38
|
+
}
|
|
39
|
+
}
|