create-kosh-erp 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. package/README.md +5 -3
  2. package/index.js +29 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,12 +3,14 @@
3
3
  Install [Kosh](https://www.npmjs.com/package/kosh-erp) and set it up in one command:
4
4
 
5
5
  ```sh
6
- npm create kosh-erp@latest my-erp
6
+ npm create kosh-erp@latest my-erp # the project my-erp
7
+ npm create kosh-erp@latest # asks for the project name first
7
8
  ```
8
9
 
9
- It creates the folder, installs `kosh-erp` (Shutro comes with it), then asks for:
10
+ It creates the project folder, installs `kosh-erp` (Shutro comes with it), then asks for:
10
11
 
11
- - the PostgreSQL database (your server, or one started in Docker for you; a missing database is created)
12
+ - the PostgreSQL database: your server (username, password, port, host, database name; a missing database is
13
+ created), or one started in Docker for you
12
14
  - the company (name, currency, language, time zone)
13
15
  - the administrator (login, name, email, password) and its authenticator app
14
16
  - the apps (roles and approvals, reports and documents, chatter and attachments)
package/index.js CHANGED
@@ -18,15 +18,16 @@ import { createInterface } from 'node:readline/promises';
18
18
 
19
19
  const own = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
20
20
  /** What to install: kosh-erp of the same minor version (KOSH_ERP_SPEC overrides it, e.g. a local tarball). */
21
- const spec = process.env.KOSH_ERP_SPEC ?? `kosh-erp@^${own.version}`;
21
+ const [major, minor] = own.version.split('.');
22
+ const spec = process.env.KOSH_ERP_SPEC ?? `kosh-erp@^${major}.${minor}.0`;
22
23
 
23
- const argv = process.argv.slice(2);
24
- const dashes = argv.indexOf('--');
25
- const ours = dashes === -1 ? argv : argv.slice(0, dashes);
26
- const forInit = dashes === -1 ? argv.filter((a) => a.startsWith('-')) : argv.slice(dashes + 1);
27
- const positional = ours.find((a) => !a.startsWith('-'));
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);
28
29
 
29
- if (ours.includes('--help') || ours.includes('-h')) {
30
+ if (forInit.length === argv.length && (argv[0] === '--help' || argv[0] === '-h')) {
30
31
  process.stdout.write(`Usage: npm create kosh-erp@latest [folder] [-- kosh init options]
31
32
 
32
33
  Creates a Kosh installation in [folder]: installs kosh-erp, then asks for the database, the company, the
@@ -62,13 +63,30 @@ const add = (cwd, what) =>
62
63
  const installAll = (cwd) =>
63
64
  run(pm, pm === 'npm' ? ['install', '--no-audit', '--no-fund'] : ['install'], cwd);
64
65
 
66
+ /** A project name: a folder name and a valid package name (lower-case letters, digits, - and _). */
67
+ const validName = (name) => /^[a-z0-9][a-z0-9._-]{0,213}$/.test(name);
68
+
69
+ /** The project name: `npm create kosh-erp my-erp`, else asked (Enter: my-erp). */
65
70
  async function folder() {
66
- if (positional !== undefined) return positional;
71
+ if (positional !== undefined) {
72
+ if (!validName(basename(resolve(positional)))) {
73
+ process.stderr.write(
74
+ `"${positional}" is not a project name: lower-case letters, digits, - and _ (e.g. my-erp).\n`,
75
+ );
76
+ process.exit(2);
77
+ }
78
+ return positional;
79
+ }
67
80
  if (!process.stdin.isTTY) return 'my-erp';
68
81
  const rl = createInterface({ input: process.stdin, output: process.stdout });
69
- const answer = (await rl.question('Project folder [my-erp]: ')).trim();
70
- rl.close();
71
- return answer === '' ? 'my-erp' : answer;
82
+ for (;;) {
83
+ const answer = (await rl.question('Project name [my-erp]: ')).trim() || 'my-erp';
84
+ if (validName(answer)) {
85
+ rl.close();
86
+ return answer;
87
+ }
88
+ process.stdout.write(' Lower-case letters, digits, - and _ (e.g. my-erp, padma-traders).\n');
89
+ }
72
90
  }
73
91
 
74
92
  const target = resolve(await folder());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kosh-erp",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "npm create kosh-erp: install Kosh and set it up in one command (database, company, administrator, apps, port)",
5
5
  "keywords": [
6
6
  "kosh",