Skip to content

Commit cbb3fb2

Browse files
committed
Allow namespaced packages
This is in preparation for the move to @khanacademy/tota11y
1 parent 3318d8e commit cbb3fb2

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

gulpfile.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ const {
1616

1717
const libraries = getLibraries();
1818

19+
/**
20+
* Creates a Gulp task function to package the given library
21+
*
22+
* @param {Library} library - A library object
23+
* @returns {Task} A Gulp task function
24+
*/
1925
function makePackageTask(library) {
20-
const packageFn = function() {
26+
const packageFn = () => {
2127
const resourceZipStream =
2228
library.manifest.resources && library.manifest.resources.length
2329
? gulp
@@ -46,11 +52,17 @@ function makePackageTask(library) {
4652
};
4753

4854
packageFn.displayName = `Generate ${library.name}_${library.version}.zip`;
55+
4956
return packageFn;
5057
}
5158

5259
const defaultTask = gulp.parallel(...libraries.map(makePackageTask));
5360

61+
/**
62+
* A Gulp task to output a table of outdated libraries
63+
*
64+
* @returns {Promise} A promise which resolves when the outdated table is complete
65+
*/
5466
function outdated() {
5567
const allUpgradesPromises = libraries.map(library =>
5668
getUpgradeVersions(library).then(upgrades =>
@@ -76,8 +88,14 @@ ${formatPackageUpgrades(validUpgrades)}`);
7688
});
7789
}
7890

91+
/**
92+
* Creates a Gulp task function to upgrade libraries
93+
*
94+
* @param {string} upgradeType - patch, minor, or major
95+
* @returns {Task} A Gulp task function
96+
*/
7997
function makeUpgradeTask(upgradeType) {
80-
const upgradeFn = function() {
98+
const upgradeFn = () => {
8199
const allUpgradesPromises = libraries.map(library =>
82100
getUpgradeVersions(library).then(upgrades =>
83101
Object.assign(library, { upgrades })

utility/packages.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,37 @@
33
const path = require('path');
44
const glob = require('glob');
55
const semver = require('semver');
6+
const log = require('fancy-log');
7+
const chalk = require('chalk');
68
const packageJson = require('package-json');
79
const { dependencies } = require('../package.json');
810

11+
const validLibraryNames = new Set(Object.keys(dependencies));
12+
13+
/**
14+
* Gets the name of the npm package from a path to a library
15+
*
16+
* @private
17+
* @param {string} libraryPath - The path to the library directory
18+
* @returns {string} The name of the library on the npm registry
19+
*/
20+
function resolveLibraryName(libraryPath) {
21+
const name = path.basename(libraryPath);
22+
if (validLibraryNames.has(name)) {
23+
return name;
24+
}
25+
26+
for (const libraryName of validLibraryNames) {
27+
if (libraryName.endsWith(`/${name}`)) {
28+
return libraryName;
29+
}
30+
}
31+
32+
log.warn(chalk`Unable to find npm package name for {yellow ${name}}`);
33+
34+
return null;
35+
}
36+
937
/**
1038
* Gets the current list of DNN JS libraries in this repo
1139
*
@@ -19,7 +47,7 @@ function getLibraries() {
1947
manifest: require(path.resolve(manifestPath)),
2048
}))
2149
.map(library =>
22-
Object.assign(library, { name: path.basename(library.path) })
50+
Object.assign(library, { name: resolveLibraryName(library.path) })
2351
)
2452
.map(library =>
2553
Object.assign(library, { version: dependencies[library.name] })

0 commit comments

Comments
 (0)