Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Typescript Notebook Support #327

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/api/constants.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os from 'node:os';
import path from 'node:path';
import Path from 'node:path';
import { fileURLToPath } from 'url';

// When running Srcbook as an npx executable, the cwd is not reliable.
// Commands that should be run from the root of the package, like npm scripts
// should therefore use DIST_DIR as the cwd.
const _filename = fileURLToPath(import.meta.url);
const _dirname = path.dirname(_filename);
const _dirname = Path.dirname(_filename);

export const HOME_DIR = os.homedir();
export const SRCBOOK_DIR = path.join(HOME_DIR, '.srcbook');
export const SRCBOOKS_DIR = path.join(SRCBOOK_DIR, 'srcbooks');
export const SRCBOOK_DIR = Path.join(HOME_DIR, '.srcbook');
export const SRCBOOKS_DIR = Path.join(SRCBOOK_DIR, 'srcbooks');
export const DIST_DIR = _dirname;
export const PROMPTS_DIR = path.join(DIST_DIR, 'prompts');
export const PROMPTS_DIR = Path.join(DIST_DIR, 'prompts');
export const IS_PRODUCTION = process.env.NODE_ENV === 'production';
6 changes: 3 additions & 3 deletions packages/api/db/index.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'node:path';
import Path from 'node:path';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
import * as schema from './schema.mjs';
Expand All @@ -8,9 +8,9 @@ import fs from 'node:fs';

// We can't use a relative directory for drizzle since this application
// can get run from anywhere, so use DIST_DIR as ground truth.
const drizzleFolder = path.join(DIST_DIR, 'drizzle');
const drizzleFolder = Path.join(DIST_DIR, 'drizzle');

const DB_PATH = `${HOME_DIR}/.srcbook/srcbook.db`;
const DB_PATH = Path.join(HOME_DIR, '.srcbook', 'srcbook.db');

// Creates the HOME/.srcbook/srcbooks dir
fs.mkdirSync(SRCBOOKS_DIR, { recursive: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/api/server/http.mts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ router.post('/file', cors(), async (req, res) => {

try {
const content = await fs.readFile(file, 'utf8');
const cell = file.includes('.srcbook/srcbooks') && !file.includes('node_modules');
const cell = file.includes(Path.join('.srcbook', 'srcbooks')) && !file.includes('node_modules');
const filename = cell ? file.split('/').pop() || file : file;

return res.json({
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/srcmd.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('encoding and decoding srcmd files', () => {
const languagePrefix = '<!-- srcbook:{"language": "javascript"} -->\n\n';

beforeAll(async () => {
srcmd = await getRelativeFileContents('srcmd_files/srcbook.src.md');
srcmd = await getRelativeFileContents(Path.join('srcmd_files', 'srcbook.src.md'));
});

it('is an error when there is no title', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/test/utils.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import Path from 'node:path';

export async function getRelativeFileContents(relativePath: string) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
return fs.readFile(path.join(__dirname, relativePath), { encoding: 'utf8' });
const __dirname = Path.dirname(__filename);
return fs.readFile(Path.join(__dirname, relativePath), { encoding: 'utf8' });
}
4 changes: 2 additions & 2 deletions packages/web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import Path from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';

Expand All @@ -7,7 +7,7 @@ export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@': Path.resolve(__dirname, './src'),
},
},
});
8 changes: 4 additions & 4 deletions srcbook/src/utils.mts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import fs from 'node:fs';
import net from 'node:net';
import path from 'node:path';
import Path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const __dirname = Path.dirname(__filename);

const ROOT_PATH = path.join(__dirname, '../../');
const ROOT_PATH = Path.join(__dirname, '../../');

export function pathTo(...paths: string[]) {
return path.join(ROOT_PATH, ...paths);
return Path.join(ROOT_PATH, ...paths);
}

export function getPackageJson() {
Expand Down