jsnote-zeina 1.0.0

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,60 @@
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.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))
36
+ if (err.code === 'EADDRINUSE') {
37
+ console.log('Port is in use. Try running on a different port.');
38
+ }
39
+ else if (err instanceof Error) {
40
+ console.log('Here is the problem: ', err.message);
41
+ }
42
+ process.exit(1); // Exit the program if express server does not start successfully
43
+ }
44
+ }));
45
+ /*
46
+ -[filename]: specifices that there is an optional filename argument
47
+ that can be provided with the serve command
48
+ -<number>: specifies that if a user provides a port option
49
+ they have to provide a port numer
50
+ -notebook.js is the default file name that is going to save
51
+ the cells of the user in case the user does not provide any
52
+ filename
53
+ -process.cwd() gets the path of the current working directory that
54
+ the terminal is open in
55
+ -path.dirname gets the relative directory (if any) provided in the
56
+ filename that the user inputs
57
+
58
+
59
+
60
+ */