소스 검색

Clean up add/remove packages and make a create:package

Steven Silvester 7 년 전
부모
커밋
f834cee494

+ 3 - 0
CONTRIBUTING.md

@@ -220,6 +220,9 @@ The integrity script also allows you to automatically add a dependency for
 a package by importing from it in the TypeScript file, and then running:
 `npm run integrity && npm install` from the repo root.
 
+We also have scripts for creating and removing packages in `packages/`, 
+`npm run create:package` and `npm run remove:package <foo>`.
+
 
 ## Notes
 

+ 6 - 1
buildutils/package.json

@@ -11,7 +11,10 @@
   "files": [
     "lib/*.d.ts",
     "lib/*.js.map",
-    "lib/*.js"
+    "lib/*.js",
+    "template/package.json",
+    "template/tsconfig.json",
+    "template/src/index.ts"
   ],
   "main": "lib/index.js",
   "types": "lib/index.d.ts",
@@ -31,6 +34,7 @@
     "child_process": "~1.0.2",
     "fs-extra": "~4.0.2",
     "glob": "~7.1.2",
+    "inquirer": "~3.3.0",
     "path": "~0.12.7",
     "sort-package-json": "~1.7.1",
     "typescript": "~2.4.2"
@@ -38,6 +42,7 @@
   "devDependencies": {
     "@types/fs-extra": "~4.0.3",
     "@types/glob": "~5.0.33",
+    "@types/inquirer": "~0.0.35",
     "@types/node": "~8.0.47",
     "rimraf": "~2.6.2"
   }

+ 0 - 3
buildutils/src/add-sibling.ts

@@ -65,6 +65,3 @@ try {
     process.exit(1);
   }
 }
-
-// // Update the lerna symlinks.
-utils.run('npm install');

+ 41 - 0
buildutils/src/create-package.ts

@@ -0,0 +1,41 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) Jupyter Development Team.
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/
+
+import * as fs from 'fs-extra';
+import * as inquirer from 'inquirer';
+import * as path from 'path';
+import * as utils from './utils';
+
+let questions = [
+  {
+    type: 'input',
+    name: 'name',
+    message: 'name: '
+  },
+  {
+    type: 'input',
+    name: 'description',
+    message: 'description: ',
+  }
+];
+
+inquirer.prompt(questions).then(answers => {
+  let { name, description } = answers;
+  let dest = path.resolve(path.join('.', 'packages', name));
+  if (fs.existsSync(dest)) {
+    console.error('Package already exists: ', name);
+    process.exit(1);
+  }
+  fs.copySync(path.resolve(path.join(__dirname, '..', 'template')), dest);
+  let jsonPath = path.join(dest, 'package.json');
+  let data = utils.readJSONFile(jsonPath);
+  if (name.indexOf('@jupyterlab/') === -1) {
+    name = '@jupyterlab/' + name;
+  }
+  data.name = name;
+  data.description = description;
+  utils.ensurePackageData(data, jsonPath);
+  utils.run('npm run integrity');
+});

+ 7 - 6
buildutils/src/ensure-package.ts

@@ -33,7 +33,7 @@ function ensurePackage(options: IEnsurePackageOptions): string[] {
       seenDeps[name] = getDependency(name);
     }
     if (deps[name] !== seenDeps[name]) {
-      messages.push('Updated dependency: ' + name + '@' + seenDeps[name]);
+      messages.push(`Updated dependency: ${name}@${seenDeps[name]}`);
     }
     deps[name] = seenDeps[name];
   });
@@ -44,7 +44,7 @@ function ensurePackage(options: IEnsurePackageOptions): string[] {
       seenDeps[name] = getDependency(name);
     }
     if (devDeps[name] !== seenDeps[name]) {
-      messages.push('Updated devDependency: ' + name + '@' + seenDeps[name]);
+      messages.push(`Updated devDependency: ${name}@${seenDeps[name]}`);
     }
     devDeps[name] = seenDeps[name];
   });
@@ -56,7 +56,7 @@ function ensurePackage(options: IEnsurePackageOptions): string[] {
 
   if (filenames.length === 0) {
     if (utils.ensurePackageData(data, path.join(pkgPath, 'package.json'))) {
-      messages.push('Update package.json');
+      messages.push('Updated package.json');
     }
     return messages;
   }
@@ -88,11 +88,11 @@ function ensurePackage(options: IEnsurePackageOptions): string[] {
       return;
     }
     if (!deps[name]) {
-      messages.push('Adding dependency: ' + name);
       if (!(name in seenDeps)) {
         seenDeps[name] = getDependency(name);
       }
       deps[name] = seenDeps[name];
+      messages.push(`Added dependency: ${name}@${seenDeps[name]}`);
     }
   });
 
@@ -102,13 +102,14 @@ function ensurePackage(options: IEnsurePackageOptions): string[] {
       return;
     }
     if (names.indexOf(name) === -1) {
-      messages.push('Removing dependency: ' + name);
+      let version = data.dependencies[name];
       delete data.dependencies[name];
+      messages.push(`Removed dependency: ${name}@${version}`);
     }
   });
 
   if (utils.ensurePackageData(data, path.join(pkgPath, 'package.json'))) {
-    messages.push('Update package.json');
+    messages.push('Updated package.json');
   }
   return messages;
 }

+ 7 - 9
buildutils/src/ensure-repo.ts

@@ -74,17 +74,17 @@ function ensureAllPackages(): string[] {
     if (index.indexOf(name) === -1) {
       valid = false;
     }
-    lines.push('import "' + name + '";');
+    lines.push(`import "${name}";`);
 
     if (!valid) {
-      messages.push('Updated: ' + name);
+      messages.push(`Updated: ${name}`);
     }
   });
 
   // Make sure there are no extra deps.
   Object.keys(allPackageData.dependencies).forEach(name => {
     if (!(name in seen)) {
-      messages.push('Removing dependency: ', name);
+      messages.push(`Removing dependency: ${name}`);
       delete allPackageData.dependencies[name];
     }
   });
@@ -211,7 +211,7 @@ function ensureIntegrity(): void {
   }
 
   // Handle the top level package.
-  let corePath: string = path.resolve('.', 'package.json');
+  let corePath = path.resolve('.', 'package.json');
   let coreData: any = utils.readJSONFile(corePath);
   if (utils.ensurePackageData(coreData, corePath)) {
     messages['top'] = ['Update package.json'];
@@ -242,13 +242,11 @@ function ensureIntegrity(): void {
     console.log(JSON.stringify(messages, null, 2));
     if (process.env.TRAVIS_BRANCH) {
       console.log('\n\nPlease run `npm run integrity` locally and commit the changes');
-    } else {
-      console.log('\n\nPlease commit the changes by running:');
-      console.log('git commit -a -m "Package integrity updates"');
-    }
-    if (process.env.TRAVIS_BRANCH) {
       process.exit(1);
     }
+    utils.run('npm install');
+    console.log('\n\nPlease commit the changes by running:');
+    console.log('git commit -a -m "Package integrity updates"');
   } else {
     console.log('Repo integrity verified!');
   }

+ 4 - 4
buildutils/src/get-dependency.ts

@@ -69,7 +69,7 @@ function getDependency(name: string): string {
     version = Object.keys(versions)
       .reduce((a, b) => { return versions[a] > versions[b] ? a : b; });
   } else {
-    let cmd = 'npm view ' + name + ' version';
+    let cmd = `npm view ${name} version`;
     version = '~' + String(childProcess.execSync(cmd)).trim();
   }
 
@@ -85,7 +85,7 @@ if (require.main === module) {
   }
   let name = process.argv[2];
   let version = getDependency(name);
-  console.log('deps: ', allDeps);
-  console.log('devDeps:', allDevDeps);
-  console.log('\n    ' + '"' + name + '": "' + version + '"');
+  console.log('dependency of: ', allDeps);
+  console.log('devDependency of:', allDevDeps);
+  console.log(`\n    "${name}": "${version}"`);
 }

+ 11 - 0
buildutils/src/prompt.d.ts

@@ -0,0 +1,11 @@
+// Type definitions for sort-package-json v1.7.1
+// https://github.com/keithamus/sort-package-json
+// Definitions by: Steven Silvester <https://github.com/blink1073>
+
+declare module 'prompt' {
+    export
+    function start(): void;
+
+    export
+    function get(items: string[], callback: (err: Error, result: any) => void): void;
+}

+ 0 - 0
buildutils/src/remove-sibling.ts → buildutils/src/remove-package.ts


+ 34 - 0
buildutils/template/package.json

@@ -0,0 +1,34 @@
+{
+  "name": "@jupyterlab/template",
+  "version": "0.1.0",
+  "description": "JupyterLab - Package Template",
+  "homepage": "https://github.com/jupyterlab/jupyterlab",
+  "bugs": {
+    "url": "https://github.com/jupyterlab/jupyterlab/issues"
+  },
+  "license": "BSD-3-Clause",
+  "author": "Project Jupyter",
+  "files": [
+    "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
+    "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
+  ],
+  "main": "lib/index.js",
+  "types": "lib/index.d.ts",
+  "directories": {
+    "lib": "lib/"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/jupyterlab/jupyterlab.git"
+  },
+  "scripts": {
+    "build": "tsc",
+    "clean": "rimraf lib",
+    "watch": "tsc -w"
+  },
+  "dependencies": {},
+  "devDependencies": {
+    "rimraf": "~2.6.2",
+    "typescript": "~2.4.2"
+  }
+}

+ 4 - 0
buildutils/template/src/index.ts

@@ -0,0 +1,4 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) Jupyter Development Team.
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/

+ 16 - 0
buildutils/template/tsconfig.json

@@ -0,0 +1,16 @@
+{
+  "compilerOptions": {
+    "declaration": true,
+    "noImplicitAny": true,
+    "noEmitOnError": true,
+    "noUnusedLocals": true,
+    "module": "commonjs",
+    "moduleResolution": "node",
+    "target": "ES5",
+    "outDir": "./lib",
+    "lib": [
+      "ES5", "ES2015.Promise", "DOM", "ES2015.Collection", "ES2016", "ES6"
+    ]
+  },
+  "include": ["src/*"]
+}

+ 2 - 2
docs/extensions_dev.md

@@ -116,7 +116,7 @@ have to graft it into the source tree of JupyterLab itself.
 This may be done using the command
 
 ```
-npm run addsibling <path-or-url> && npm install
+npm run add:sibling <path-or-url> && npm install
 ```
 
 in the JupyterLab root directory, where `<path-or-url>` refers either to an
@@ -125,7 +125,7 @@ repository for an extension npm package. This operation may be subsequently
 reversed by running
 
 ```
-npm run removesibling <extension-dir-name>
+npm run remove:package <extension-dir-name>
 ```
 
 This will remove the package metadata from the source tree, but wil **not**

+ 1 - 0
lerna.json

@@ -9,6 +9,7 @@
     "packages/services/examples/browser",
     "packages/services/examples/typescript-browser-with-output",
     "buildutils",
+    "buildutils/template",
     "test"
   ],
   "version": "independent"

+ 5 - 4
package.json

@@ -1,8 +1,8 @@
 {
   "private": true,
   "scripts": {
-    "addsibling": "node buildutils/lib/add-sibling.js",
-    "build": "npm run build:packages && cd jupyterlab && npm run build",
+    "add:sibling": "node buildutils/lib/add-sibling.js",
+    "build": "npm run integrity && npm run build:packages && cd jupyterlab && npm run build",
     "build:examples": "lerna run build --scope \"@jupyterlab/example-*\"",
     "build:main": "npm run build",
     "build:main:prod": "npm run build:packages && cd jupyterlab && npm run build:prod",
@@ -14,10 +14,11 @@
     "clean": "node buildutils/lib/clean-packages.js examples packages",
     "clean:examples": "node buildutils/lib/clean-packages.js examples",
     "clean:main": "cd jupyterlab && npm run clean",
-    "clean:slate": "git clean -dfx && npm install && npm run integrity && npm install && npm run build",
+    "clean:slate": "git clean -dfx && npm install && npm run build",
     "clean:src": "node buildutils/lib/clean-packages.js packages",
     "clean:tests": "lerna run clean --scope \"@jupyterlab/test-*\"",
     "coverage": "lerna run coverage --stream",
+    "create:package": "node buildutils/lib/create-package.js",
     "docs": "lerna run docs",
     "get:dependency": "node buildutils/lib/get-dependency.js",
     "install": "lerna bootstrap --hoist && npm run build:utils",
@@ -25,7 +26,7 @@
     "patch:release": "node buildutils/lib/patch-release.js",
     "publish": "npm run clean:slate && lerna publish --force-publish=* -m \"Publish\"",
     "remove:dependency": "node buildutils/lib/remove-dependency.js",
-    "removesibling": "node buildutils/lib/remove-sibling.js",
+    "remove:package": "node buildutils/lib/remove-package.js",
     "test": "cd test && npm test",
     "test:chrome": "lerna run test:chrome --stream",
     "test:firefox": "lerna run test:firefox --stream",

+ 2 - 2
scripts/travis_script.sh

@@ -110,9 +110,9 @@ if [[ $GROUP == other ]]; then
     postcss packages/**/style/*.css --dir /tmp
 
     # Make sure we can add and remove a sibling package.
-    npm run addsibling jupyterlab/tests/mock_packages/extension
+    npm run add:sibling jupyterlab/tests/mock_packages/extension
     npm run build
-    npm run removesibling extension
+    npm run remove:package extension
     npm run build
     npm run integrity