jsnote-zeina 1.0.4 → 1.0.5

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.
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.serveCommand = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const commander_1 = require("commander");
18
+ const local_api_1 = require("@jsnote-zeina/local-api");
19
+ const isProduction = process.env.NODE_ENV === 'production';
20
+ exports.serveCommand = new commander_1.Command()
21
+ .command('serve [filename]') // Watch for serve command in the cmd
22
+ .description('Open a file for editing')
23
+ .option('-p, --port <number>', 'port to run server on', '4005')
24
+ .action((...args_1) => __awaiter(void 0, [...args_1], void 0, function* (filename = 'notebook.js', options) {
25
+ const isLocalApiError = (err) => {
26
+ return typeof err === 'object' && err !== null && typeof err.code === 'string';
27
+ };
28
+ try {
29
+ const dir = path_1.default.join(process.cwd(), path_1.default.dirname(filename)); // getting the directory
30
+ filename = path_1.default.basename(filename); // Getting the filename
31
+ yield (0, local_api_1.serve)(parseInt(options.port), filename, dir, !isProduction);
32
+ console.log(`Opened ${filename}. Navigate to http://localhost:${options.port} to edit the file.`);
33
+ }
34
+ catch (err) {
35
+ if (isLocalApiError(err) && err.code === 'EADDRINUSE') {
36
+ console.log('Port is in use. Try running on a different port.');
37
+ }
38
+ else if (err instanceof Error) {
39
+ console.log('Here is the problem: ', err.message);
40
+ }
41
+ else {
42
+ console.log('An unknown error occurred while starting the server.');
43
+ }
44
+ process.exit(1);
45
+ }
46
+ }));
47
+ /*
48
+ -[filename]: specifies that there is an optional filename argument
49
+ that can be provided with the serve command
50
+ -<number>: specifies that if a user provides a port option
51
+ they have to provide a port number
52
+ -notebook.js is the default file name that is going to save
53
+ the cells of the user in case the user does not provide any
54
+ filename
55
+ -process.cwd() gets the path of the current working directory that
56
+ the terminal is open in
57
+ -path.dirname gets the relative directory (if any) provided in the
58
+ filename that the user inputs
59
+
60
+
61
+
62
+ */