UNPKG

3.33 kBJavaScriptView Raw
1"use strict";
2/*-----------------------------------------------------------------------------
3| Copyright (c) Jupyter Development Team.
4| Distributed under the terms of the Modified BSD License.
5|----------------------------------------------------------------------------*/
6var __importStar = (this && this.__importStar) || function (mod) {
7 if (mod && mod.__esModule) return mod;
8 var result = {};
9 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
10 result["default"] = mod;
11 return result;
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14const fs = __importStar(require("fs-extra"));
15const path = __importStar(require("path"));
16const utils = __importStar(require("./utils"));
17/**
18 * Add an extension to the source tree of JupyterLab.
19 * It takes as an argument either a path to a directory
20 * on the local filesystem or a URL to a git repository.
21 * In the former case, it copies the directory into the
22 * source tree, in the latter it adds the repository as
23 * a git submodule.
24 *
25 * It also adds the relevant metadata to the build files.
26 */
27// Make sure we have required command line arguments.
28if (process.argv.length < 3) {
29 let msg = '** Must supply a target extension';
30 process.stderr.write(msg);
31 process.exit(1);
32}
33// Extract the desired git repository and repository name.
34let target = process.argv[2];
35let basePath = path.resolve('.');
36let packageDirName = path.basename(target);
37let packagePath = path.resolve(target);
38if (fs.existsSync(packagePath)) {
39 // Copy the package directory contents to the sibling package.
40 let newPackagePath = path.join(basePath, 'packages', packageDirName);
41 fs.copySync(packagePath, newPackagePath);
42 packagePath = newPackagePath;
43}
44else {
45 // Otherwise treat it as a git reposotory and try to add it.
46 packageDirName = target
47 .split('/')
48 .pop()
49 .split('.')[0];
50 packagePath = path.join(basePath, 'packages', packageDirName);
51 utils.run('git clone ' + target + ' ' + packagePath);
52}
53// Remove any existing node_modules in the extension.
54if (fs.existsSync(path.join(packagePath, 'node_modules'))) {
55 fs.removeSync(path.join(packagePath, 'node_modules'));
56}
57// Make sure composite is set to true in the new package.
58let packageTsconfigPath = path.join(packagePath, 'tsconfig.json');
59if (fs.existsSync(packageTsconfigPath)) {
60 let packageTsconfig = utils.readJSONFile(packageTsconfigPath);
61 packageTsconfig.compilerOptions.composite = true;
62 utils.writeJSONFile(packageTsconfigPath, packageTsconfig);
63}
64// Get the package.json of the extension.
65let pkgJSONPath = path.join(packagePath, 'package.json');
66let data = utils.readJSONFile(pkgJSONPath);
67if (data.private !== true) {
68 data.publishConfig = {};
69 data.publishConfig.access = 'public';
70 utils.writeJSONFile(pkgJSONPath, data);
71}
72// Add the extension path to packages/metapackage/tsconfig.json
73let tsconfigPath = path.join(basePath, 'packages', 'metapackage', 'tsconfig.json');
74let tsconfig = utils.readJSONFile(tsconfigPath);
75tsconfig.references.push({
76 path: path.join('..', '..', packageDirName)
77});
78utils.writeJSONFile(tsconfigPath, tsconfig);
79// Update the core jupyterlab build dependencies.
80utils.run('jlpm run integrity');
81//# sourceMappingURL=add-sibling.js.map
\No newline at end of file