Skip to content

Commit

Permalink
Updated KITA_PROJECT_ROOT error message
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Apr 1, 2024
1 parent a6b78ab commit c42f222
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/funny-bobcats-repeat.md
@@ -0,0 +1,6 @@
---
'@kitajs/generator': patch
'@kitajs/runtime': patch
---

Updated KITA_PROJECT_ROOT error message
9 changes: 6 additions & 3 deletions packages/generator/src/templates/index.ts
@@ -1,20 +1,23 @@
import { Route, kKitaGlobalRoot, kKitaRoot } from '@kitajs/common';
import { ts } from 'ts-writer';

// TODO: FIx the globalRoot documentation link
export function generateIndex(routes: Route[]) {
return ts`${'index'}
'use strict';
const tslib = require("tslib");
// If you are seeing this error, you probably forgot to define the ${kKitaGlobalRoot} variable.
// Read more at https://kita.js.org/docs/runtime
// Read more at https://kita.js.org/concepts/routing#kita-project-root
if (!${kKitaGlobalRoot}) {
${kKitaGlobalRoot} = process.env.${kKitaRoot};
if (!${kKitaGlobalRoot}) {
throw new Error('Please define ${kKitaGlobalRoot} before importing any routes.');
throw new Error(
process.stdout.isTTY
? '\x1b[31mPlease define globalThis.KITA_PROJECT_ROOT before importing any routes.\x1b[0m\nhttps://kita.js.org/concepts/routing#kita-project-root\x1b[0m\n'
: 'Please define globalThis.KITA_PROJECT_ROOT before importing any routes.\nhttps://kita.js.org/concepts/routing#kita-project-root'
);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/test/index.test.js
Expand Up @@ -14,6 +14,7 @@ describe('Runtime tests', () => {
runtime.Kita();
assert.fail('Kita function should throw error');
} catch (error) {
console.log(error);
assert.equal(error.message, 'You must run `kita build` before using @kitajs/runtime.');
}
});
Expand Down

0 comments on commit c42f222

Please sign in to comment.