vovk 0.2.3-beta.124 → 0.2.3-beta.125

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/cli/index.js CHANGED
@@ -13,34 +13,46 @@ const {
13
13
  // TODO not documented
14
14
  project = process.cwd(), // Path to Next.js project
15
15
  clientOut = path.join(process.cwd(), './node_modules/.vovk'), // Path to output directory
16
+ standalone = false, // Start Vovk Server without Next.js
16
17
  } = flags;
17
18
 
18
19
  if (command === 'dev') {
20
+ const portAttempts = 30;
19
21
  void (async () => {
20
- let PORT =
21
- process.env.PORT ||
22
- (await getAvailablePort(3000, 30).catch(() => {
23
- throw new Error(' 🐺 Failed to find available Next port');
24
- }));
22
+ let PORT = standalone
23
+ ? process.env.PORT
24
+ : process.env.PORT ||
25
+ (await getAvailablePort(3000, portAttempts).catch(() => {
26
+ throw new Error(` 🐺 ❌ Failed to find available Next port after ${portAttempts} attempts`);
27
+ }));
28
+
29
+ if (!PORT) {
30
+ throw new Error(' 🐺 ❌ PORT env variable is required in standalone mode');
31
+ }
25
32
 
26
33
  const env = getVars(config, { VOVK_CLIENT_OUT: clientOut, PORT });
27
34
 
28
35
  let VOVK_PORT = parseInt(env.VOVK_PORT);
29
36
 
30
- env.VOVK_PORT = await getAvailablePort(VOVK_PORT, 30).catch(() => {
31
- throw new Error(' 🐺 Failed to find available Vovk port');
37
+ env.VOVK_PORT = await getAvailablePort(VOVK_PORT, portAttempts).catch(() => {
38
+ throw new Error(` 🐺 Failed to find available Vovk port after ${portAttempts} attempts`);
32
39
  });
33
40
 
34
- await parallel(
35
- [
36
- {
37
- command: `node ${__dirname}/server.js`,
38
- name: 'Vovk',
39
- },
40
- { command: `cd ${project} && npx next dev ${restArgs}`, name: 'Next' },
41
- ],
42
- env
43
- ).catch((e) => console.error(e));
41
+ const commands = [
42
+ {
43
+ command: `node ${__dirname}/server.js`,
44
+ name: 'Vovk',
45
+ },
46
+ ];
47
+
48
+ if (!standalone) {
49
+ commands.push({
50
+ command: `cd ${project} && npx next dev ${restArgs}`,
51
+ name: 'Next',
52
+ });
53
+ }
54
+
55
+ await parallel(commands, env).catch((e) => console.error(e));
44
56
  console.info(' 🐺 All processes have ended');
45
57
  })();
46
58
  } else if (command === 'generate') {
@@ -5,7 +5,7 @@ function toCamelCase(str) {
5
5
  return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
6
6
  }
7
7
 
8
- /** @typedef {{ config?: string; project?: string; clientOut?: string }} Flags */
8
+ /** @typedef {{ config?: string; project?: string; clientOut?: string; standalone?: true }} Flags */
9
9
  /** @typedef {'dev' | 'build' | 'generate' | 'help'} Command */
10
10
  function parseCommandLineArgs() {
11
11
  const args = process.argv.slice(2); // Slice off node and script path
@@ -27,7 +27,8 @@ function parseCommandLineArgs() {
27
27
  } else if (arg.startsWith('--')) {
28
28
  const [key, value = true] = arg.slice(2).split('=');
29
29
  const camelKey = /** @type {keyof Flags} */ (toCamelCase(key));
30
- flags[camelKey] = /** @type {string} */ (value);
30
+ // @ts-expect-error Type 'string | true | undefined' is not assignable to type 'undefined'. Why?
31
+ flags[camelKey] = /** @type {Flags[keyof Flags]} */ (value);
31
32
  } else if (!command) {
32
33
  command = /** @type {Command} */ (arg);
33
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "0.2.3-beta.124",
3
+ "version": "0.2.3-beta.125",
4
4
  "description": "Structural add-on for Next.js",
5
5
  "bin": "./cli/index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "test:unit:watch": "jest --watch",
14
14
  "deploy-docs": "npm run --prefix docs deploy",
15
15
  "postpublish": "node ../post-publish-test/post-publish.js",
16
- "serve:unit": "npm --prefix test run build && npm --prefix test run start",
16
+ "serve:unit": "npm --prefix test run generate && npm --prefix test run build && npm --prefix test run start",
17
17
  "build": "rm -rf dist && npm run toc && tsc && cp package.json dist && cp README.md dist && cp package-lock.json dist && cp -r cli dist",
18
18
  "lint-nofix": "eslint . --ext .ts,.tsx",
19
19
  "lint": "npm run lint-nofix -- --fix",