@nulib/canopy 0.0.0 → 2.0.1
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.
- package/bin/canopy.js +16 -0
- package/lib/AGENTS.md +107 -0
- package/lib/base-path.js +67 -0
- package/lib/build/appearance.js +76 -0
- package/lib/build/assets.js +30 -0
- package/lib/build/build.js +350 -0
- package/lib/build/dev.js +1355 -0
- package/lib/build/devtoast.config.json +6 -0
- package/lib/build/devtoast.css +14 -0
- package/lib/build/facets.js +19 -0
- package/lib/build/fonts.js +105 -0
- package/lib/build/iiif.js +2990 -0
- package/lib/build/log.js +31 -0
- package/lib/build/mdx.js +1967 -0
- package/lib/build/package-names.js +111 -0
- package/lib/build/pages.js +420 -0
- package/lib/build/rehype-task-list-labels.js +54 -0
- package/lib/build/runtimes.js +141 -0
- package/lib/build/search-index.js +55 -0
- package/lib/build/search-text.js +160 -0
- package/lib/build/search-workflow.js +72 -0
- package/lib/build/search.js +302 -0
- package/lib/build/sitemap.js +197 -0
- package/lib/build/styles.js +140 -0
- package/lib/build/theme-tokens.js +78 -0
- package/lib/build/ui-styles.js +25 -0
- package/lib/build/upgrade-notices.js +121 -0
- package/lib/cli.js +64 -0
- package/lib/common.js +580 -0
- package/lib/components/bibliography.js +197 -0
- package/lib/components/featured.js +237 -0
- package/lib/components/hero-slider-runtime.js +215 -0
- package/lib/components/image-story-runtime-entry.js +249 -0
- package/lib/components/map-runtime.js +114 -0
- package/lib/components/metadata-index.js +32 -0
- package/lib/components/nav-place.js +227 -0
- package/lib/components/navigation.js +381 -0
- package/lib/components/referenced.js +217 -0
- package/lib/components/slider-runtime-entry.js +106 -0
- package/lib/components/timeline-runtime.js +80 -0
- package/lib/components/viewer-runtime-entry.js +88 -0
- package/lib/config-path.js +78 -0
- package/lib/default-locale.js +113 -0
- package/lib/discovery/browser-loader.js +107 -0
- package/lib/discovery/browser.js +115 -0
- package/lib/discovery/config.js +25 -0
- package/lib/discovery/envelope.js +124 -0
- package/lib/discovery/export.js +226 -0
- package/lib/discovery/ingestion.js +62 -0
- package/lib/discovery/pagination.js +66 -0
- package/lib/discovery/provenance.js +79 -0
- package/lib/discovery/search.js +81 -0
- package/lib/discovery/tools.js +155 -0
- package/lib/discovery/validation.js +121 -0
- package/lib/head.js +154 -0
- package/lib/iiif/thumbnail.js +402 -0
- package/lib/index.js +9 -0
- package/lib/locale-runtime.js +69 -0
- package/lib/locales.js +203 -0
- package/lib/orchestrator.js +231 -0
- package/lib/page-context.js +24 -0
- package/lib/search/bundle.js +25 -0
- package/lib/search/data.js +202 -0
- package/lib/search/engine.js +86 -0
- package/lib/search/index-cache.js +95 -0
- package/lib/search/search-app.jsx +835 -0
- package/lib/search/search-engine-runtime.js +44 -0
- package/lib/search/search-form-runtime.js +462 -0
- package/lib/search/search.js +676 -0
- package/package.json +109 -3
- package/types/base-path.d.ts +4 -0
- package/types/orchestrator.d.ts +17 -0
- package/ui/dist/index.mjs +7358 -0
- package/ui/dist/index.mjs.map +7 -0
- package/ui/dist/server.mjs +12731 -0
- package/ui/dist/server.mjs.map +7 -0
- package/ui/fonts/OFL.txt +98 -0
- package/ui/fonts/google-sans-flex-latin-ext.woff2 +0 -0
- package/ui/fonts/google-sans-flex-latin.woff2 +0 -0
- package/ui/fonts/source-serif-4-italic-latin-ext.woff2 +0 -0
- package/ui/fonts/source-serif-4-italic-latin.woff2 +0 -0
- package/ui/fonts/source-serif-4-latin-ext.woff2 +0 -0
- package/ui/fonts/source-serif-4-latin.woff2 +0 -0
- package/ui/styles/base/_common.scss +97 -0
- package/ui/styles/base/_heading.scss +61 -0
- package/ui/styles/base/_markdown.scss +188 -0
- package/ui/styles/base/_type.scss +51 -0
- package/ui/styles/base/_utilities.scss +7 -0
- package/ui/styles/base/index.scss +5 -0
- package/ui/styles/components/_article-card.scss +108 -0
- package/ui/styles/components/_band.scss +104 -0
- package/ui/styles/components/_bibliography.scss +88 -0
- package/ui/styles/components/_buttons.scss +143 -0
- package/ui/styles/components/_card.scss +109 -0
- package/ui/styles/components/_diagram.scss +76 -0
- package/ui/styles/components/_feature.scss +66 -0
- package/ui/styles/components/_footer.scss +136 -0
- package/ui/styles/components/_gallery.scss +476 -0
- package/ui/styles/components/_image-story.scss +56 -0
- package/ui/styles/components/_interstitial-hero.scss +625 -0
- package/ui/styles/components/_layout.scss +83 -0
- package/ui/styles/components/_map.scss +296 -0
- package/ui/styles/components/_metadata-index.scss +68 -0
- package/ui/styles/components/_nav-tree.scss +80 -0
- package/ui/styles/components/_referenced-items.scss +69 -0
- package/ui/styles/components/_sub-navigation.scss +208 -0
- package/ui/styles/components/_swoosh.scss +50 -0
- package/ui/styles/components/_timeline.scss +350 -0
- package/ui/styles/components/_work.scss +71 -0
- package/ui/styles/components/header/_header.scss +294 -0
- package/ui/styles/components/header/_logo.scss +99 -0
- package/ui/styles/components/header/_navbar.scss +143 -0
- package/ui/styles/components/header/index.scss +3 -0
- package/ui/styles/components/iiif/_image.scss +32 -0
- package/ui/styles/components/iiif/_slider.scss +5 -0
- package/ui/styles/components/iiif/index.scss +2 -0
- package/ui/styles/components/index.scss +25 -0
- package/ui/styles/components/modal/_modal.scss +130 -0
- package/ui/styles/components/modal/index.scss +1 -0
- package/ui/styles/components/search/_filters.scss +259 -0
- package/ui/styles/components/search/_form.scss +187 -0
- package/ui/styles/components/search/_panel.scss +7 -0
- package/ui/styles/components/search/_results.scss +241 -0
- package/ui/styles/components/search/_tabs.scss +60 -0
- package/ui/styles/components/search/index.scss +4 -0
- package/ui/styles/index.css +5007 -0
- package/ui/styles/index.scss +11 -0
- package/ui/styles/settings/_breakpoints.scss +7 -0
- package/ui/styles/settings/_focus.scss +15 -0
- package/ui/styles/settings/_tokens.scss +170 -0
- package/ui/styles/settings/_type.scss +126 -0
- package/ui/styles/version-parity.css +116 -0
- package/ui/tailwind-canopy-iiif-plugin.js +39 -0
- package/ui/tailwind-canopy-iiif-preset.js +32 -0
- package/ui/tailwind-config.d.ts +29 -0
- package/ui/tailwind-config.js +159 -0
- package/ui/tailwind-default.config.mjs +4 -0
- package/ui/theme-color.js +130 -0
- package/ui/theme-palette.js +337 -0
- package/ui/theme.js +153 -0
- package/README.md +0 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const THEME_MARKER = "/* canopy-theme */";
|
|
2
|
+
const THEME_MARKER_END = "/* canopy-theme:end */";
|
|
3
|
+
const THEME_BLOCK_PATTERN =
|
|
4
|
+
/\/\* canopy-theme \*\/[\s\S]*?\/\* canopy-theme:end \*\/\n?/g;
|
|
5
|
+
const PRELUDE_AT_RULE = /^@(charset|import|layer|namespace)\b/i;
|
|
6
|
+
|
|
7
|
+
// Index just past the `;` that ends the statement starting at `start`, or -1
|
|
8
|
+
// when a `{` opens a block first. Skips quoted strings and parentheses, since
|
|
9
|
+
// font URLs often contain `;`.
|
|
10
|
+
function statementEnd(css, start) {
|
|
11
|
+
let quote = "";
|
|
12
|
+
let depth = 0;
|
|
13
|
+
for (let i = start; i < css.length; i++) {
|
|
14
|
+
const ch = css[i];
|
|
15
|
+
if (quote) {
|
|
16
|
+
if (ch === "\\") i++;
|
|
17
|
+
else if (ch === quote) quote = "";
|
|
18
|
+
} else if (ch === '"' || ch === "'") quote = ch;
|
|
19
|
+
else if (ch === "(") depth++;
|
|
20
|
+
else if (ch === ")") depth--;
|
|
21
|
+
else if (depth === 0 && ch === ";") return i + 1;
|
|
22
|
+
else if (depth === 0 && ch === "{") return -1;
|
|
23
|
+
}
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Length of the leading comments and `@charset` / `@import` / `@layer a, b;` /
|
|
28
|
+
// `@namespace` statements. Those must precede every other rule, so nothing
|
|
29
|
+
// can be inserted ahead of them without invalidating them.
|
|
30
|
+
function cssPreludeLength(css) {
|
|
31
|
+
let i = 0;
|
|
32
|
+
for (;;) {
|
|
33
|
+
while (i < css.length && /\s/.test(css[i])) i++;
|
|
34
|
+
if (css.startsWith("/*", i)) {
|
|
35
|
+
const end = css.indexOf("*/", i + 2);
|
|
36
|
+
if (end === -1) return i;
|
|
37
|
+
i = end + 2;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!PRELUDE_AT_RULE.test(css.slice(i, i + 12))) return i;
|
|
41
|
+
const end = statementEnd(css, i);
|
|
42
|
+
if (end === -1) return i;
|
|
43
|
+
i = end;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Tailwind's `@layer theme` holds its defaults (`--spacing`, `--text-*`) and a
|
|
48
|
+
// site's own `@theme` values. Declaring it ahead of `properties` keeps those
|
|
49
|
+
// below Canopy's tokens and `app/styles` overrides, so Tailwind's default
|
|
50
|
+
// `--color-gray-*` and `--font-*` values can't override them. Clover 4 draws in
|
|
51
|
+
// `@layer clover` (`@nulib/clover/styles.css`, imported by the UI stylesheet):
|
|
52
|
+
// above Tailwind's preflight (`base`), so its parts keep their own look, and
|
|
53
|
+
// below Canopy's `components` and `utilities`, so a site restyles them.
|
|
54
|
+
const LAYER_ORDER =
|
|
55
|
+
"@layer theme, properties, base, clover, components, utilities;";
|
|
56
|
+
|
|
57
|
+
// Places the generated theme ahead of the stylesheet's own rules. The theme
|
|
58
|
+
// and author overrides share `@layer properties`, so source order decides:
|
|
59
|
+
// putting the theme first lets `app/styles` overrides win without
|
|
60
|
+
// `!important`. A previously injected block is replaced, so repeat calls
|
|
61
|
+
// return identical output.
|
|
62
|
+
function withThemeBlock(css, themeCss) {
|
|
63
|
+
const sanitized = String(css || "").replace(THEME_BLOCK_PATTERN, "");
|
|
64
|
+
if (!themeCss) return sanitized;
|
|
65
|
+
const block = `${THEME_MARKER}\n${LAYER_ORDER}\n${themeCss}\n${THEME_MARKER_END}\n`;
|
|
66
|
+
const at = cssPreludeLength(sanitized);
|
|
67
|
+
const head = sanitized.slice(0, at);
|
|
68
|
+
const separator = head && !head.endsWith("\n") ? "\n" : "";
|
|
69
|
+
return `${head}${separator}${block}${sanitized.slice(at)}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
LAYER_ORDER,
|
|
74
|
+
THEME_MARKER,
|
|
75
|
+
THEME_MARKER_END,
|
|
76
|
+
cssPreludeLength,
|
|
77
|
+
withThemeBlock,
|
|
78
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// What comes ahead of the UI stylesheet's own rules in `ui/styles/index.css`, written by
|
|
2
|
+
// both of its compilers: the UI build (`ui/scripts/build-ui.mjs`) and the dev server's
|
|
3
|
+
// Sass watcher (`dev.js`). Clover's stylesheet comes first, in its own `@layer clover`,
|
|
4
|
+
// which the theme's layer order places between Tailwind's base and Canopy's components
|
|
5
|
+
// (`theme-tokens.js`); every site already imports this file. Its templates' sheet is for
|
|
6
|
+
// Scroll, Clover's Document template for now. Then 1.x's styling of Clover 3, carried
|
|
7
|
+
// over to Clover 4's markup (`version-parity.css`).
|
|
8
|
+
//
|
|
9
|
+
// The theme is added to each site's stylesheet at build time (`styles.js`); never bake it
|
|
10
|
+
// into this published file.
|
|
11
|
+
|
|
12
|
+
const UI_STYLES_IMPORTS = [
|
|
13
|
+
'@import "@nulib/clover/styles.css";',
|
|
14
|
+
'@import "@nulib/clover/templates.css";',
|
|
15
|
+
'@import "./version-parity.css";',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
function withUiStylesImports(css) {
|
|
19
|
+
return [...UI_STYLES_IMPORTS, css || ''].join('\n');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
UI_STYLES_IMPORTS,
|
|
24
|
+
withUiStylesImports,
|
|
25
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Notes for a site made before 2.0, said once when it builds: what it carries from 1.x
|
|
2
|
+
// that 2.x does without, and the package's new name. Each is a suggestion; the site
|
|
3
|
+
// builds as it is (the MDX API is a contract, AGENTS.md).
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const {PACKAGE_NAME, LEGACY_NAMES} = require('./package-names');
|
|
10
|
+
|
|
11
|
+
// What 1.x sites installed for Canopy and 2.x does without.
|
|
12
|
+
const LEFT_OVER = [
|
|
13
|
+
{name: '@samvera/clover-iiif', label: 'Clover 3', why: 'Canopy 2 brings Clover 4 itself'},
|
|
14
|
+
{name: 'embla-carousel', label: '', why: 'the hero’s carousel no longer uses it'},
|
|
15
|
+
];
|
|
16
|
+
const GUIDE = 'https://nulib-ds.github.io/canopy/docs/developers/upgrading.html';
|
|
17
|
+
const COMPONENT_EXTENSIONS = new Set(['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts']);
|
|
18
|
+
|
|
19
|
+
function readJson(file) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
22
|
+
} catch (_) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The site's own components that import a package, as paths from the site's root.
|
|
28
|
+
function filesImporting(root, name) {
|
|
29
|
+
const found = [];
|
|
30
|
+
const pattern = new RegExp(`['"]${name.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')}(?:/[^'"]*)?['"]`);
|
|
31
|
+
const stack = [path.join(root, 'app', 'components')];
|
|
32
|
+
while (stack.length) {
|
|
33
|
+
const dir = stack.pop();
|
|
34
|
+
let entries = [];
|
|
35
|
+
try {
|
|
36
|
+
entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
37
|
+
} catch (_) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
const full = path.join(dir, entry.name);
|
|
42
|
+
if (entry.isDirectory()) {
|
|
43
|
+
if (entry.name !== 'node_modules') stack.push(full);
|
|
44
|
+
} else if (COMPONENT_EXTENSIONS.has(path.extname(entry.name))) {
|
|
45
|
+
try {
|
|
46
|
+
if (pattern.test(fs.readFileSync(full, 'utf8'))) {
|
|
47
|
+
found.push(path.relative(root, full).split(path.sep).join('/'));
|
|
48
|
+
}
|
|
49
|
+
} catch (_) {}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return found.sort();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function upgradeNotices(root = process.cwd()) {
|
|
57
|
+
const pkg = readJson(path.join(root, 'package.json'));
|
|
58
|
+
if (!pkg || typeof pkg !== 'object') return [];
|
|
59
|
+
const deps = {...(pkg.devDependencies || {}), ...(pkg.dependencies || {})};
|
|
60
|
+
const notes = [];
|
|
61
|
+
|
|
62
|
+
const legacy = LEGACY_NAMES.find((name) => deps[name]);
|
|
63
|
+
if (legacy && !deps[PACKAGE_NAME]) {
|
|
64
|
+
notes.push(
|
|
65
|
+
`Canopy is published as ${PACKAGE_NAME} since 2.0. ${legacy} passes through to it and keeps ` +
|
|
66
|
+
`working; to switch, name ${PACKAGE_NAME} in package.json and app/styles/index.css. ${GUIDE}`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const {name, label, why} of LEFT_OVER) {
|
|
71
|
+
if (!deps[name]) continue;
|
|
72
|
+
const named = label ? `${name} (${label})` : name;
|
|
73
|
+
const users = filesImporting(root, name);
|
|
74
|
+
notes.push(
|
|
75
|
+
users.length
|
|
76
|
+
? `${users.join(', ')} import${users.length === 1 ? 's' : ''} ${named}, which Canopy 2 no ` +
|
|
77
|
+
'longer uses. It keeps working while it stays in package.json.'
|
|
78
|
+
: `${named} is in package.json and nothing imports it: ${why}, so it can be removed.`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const throughTsx = Object.entries(pkg.scripts || {})
|
|
83
|
+
.filter(([, command]) => /\btsx\b[^&|;]*canopy-build/.test(String(command)))
|
|
84
|
+
.map(([script]) => script);
|
|
85
|
+
if (throughTsx.length) {
|
|
86
|
+
notes.push(
|
|
87
|
+
`package.json runs Canopy through tsx (${throughTsx.join(', ')}). "canopy build" and ` +
|
|
88
|
+
'"canopy dev" do the same without it; tsx and app/scripts/canopy-build.mts can then go.',
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return notes;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Once a process, even when `npm run dev` reloads this module after a change under lib/.
|
|
96
|
+
function printUpgradeNotices(root = process.cwd()) {
|
|
97
|
+
if (globalThis.__CANOPY_UPGRADE_NOTICES__) return;
|
|
98
|
+
globalThis.__CANOPY_UPGRADE_NOTICES__ = true;
|
|
99
|
+
for (const note of upgradeNotices(root)) console.warn(`[canopy] ${note}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A search layout of the site's own, such as the one a 1.x template gave it, may render
|
|
103
|
+
// the search page with no `h1`, and so its results with no heading above them (1.3.1;
|
|
104
|
+
// the default layout opens with one since 2.0). Read from the page the layout renders.
|
|
105
|
+
function searchHeadingNotice(body) {
|
|
106
|
+
if (typeof body !== 'string' || /<h1[\s>]/i.test(body)) return null;
|
|
107
|
+
return (
|
|
108
|
+
'content/search/_layout.mdx gives the search page no h1, so its results have no ' +
|
|
109
|
+
'heading above them. Open it with one, such as <h1>{props.page?.title || "Search"}</h1>: ' +
|
|
110
|
+
'https://nulib-ds.github.io/canopy/docs/content/search.html'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function printSearchHeadingNotice(body) {
|
|
115
|
+
const note = searchHeadingNotice(body);
|
|
116
|
+
if (!note || globalThis.__CANOPY_SEARCH_HEADING_NOTICE__) return;
|
|
117
|
+
globalThis.__CANOPY_SEARCH_HEADING_NOTICE__ = true;
|
|
118
|
+
console.warn(`[canopy] ${note}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = {upgradeNotices, printUpgradeNotices, searchHeadingNotice, printSearchHeadingNotice};
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The `canopy` command (`bin/canopy.js`): `canopy build` and `canopy dev`, as a site's
|
|
2
|
+
// package.json scripts run them since 2.0. A 1.x site ran the same through `tsx` and its
|
|
3
|
+
// own `app/scripts/canopy-build.mts`, which keeps working.
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const {PACKAGE_NAME} = require('./build/package-names');
|
|
8
|
+
|
|
9
|
+
const COMMANDS = {
|
|
10
|
+
build: 'Build the site into site/.',
|
|
11
|
+
dev: 'Build the site, serve it at http://localhost:5001 (or $PORT), and rebuild it on change.',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function usage() {
|
|
15
|
+
return [
|
|
16
|
+
'Usage: canopy <command> [options]',
|
|
17
|
+
'',
|
|
18
|
+
'Commands:',
|
|
19
|
+
...Object.entries(COMMANDS).map(([name, about]) => ` ${name.padEnd(10)}${about}`),
|
|
20
|
+
'',
|
|
21
|
+
'Options:',
|
|
22
|
+
' --debug Log each IIIF request as it is made.',
|
|
23
|
+
' --help Show this help.',
|
|
24
|
+
` --version Show the version of ${PACKAGE_NAME}.`,
|
|
25
|
+
].join('\n');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A 1.x site's build ran through tsx, which let its MDX import a `.jsx`, `.tsx` or `.ts`
|
|
29
|
+
// file directly (the docs' home page and Style guide do). The command runs the build
|
|
30
|
+
// under tsx's loaders too, so that MDX keeps working as written (AGENTS.md, the MDX API
|
|
31
|
+
// is a contract). Once a process: under a site's own `tsx` script they are there already.
|
|
32
|
+
async function registerLoaders() {
|
|
33
|
+
if (globalThis.__CANOPY_TSX_LOADERS__) return;
|
|
34
|
+
globalThis.__CANOPY_TSX_LOADERS__ = true;
|
|
35
|
+
require('tsx/cjs/api').register();
|
|
36
|
+
// Its ES module API by import: the CommonJS build of it (4.23) names a loader file the
|
|
37
|
+
// package does not have.
|
|
38
|
+
const {register} = await import('tsx/esm/api');
|
|
39
|
+
register();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Resolves to the exit code; `dev` resolves only when the server stops.
|
|
43
|
+
async function run(argv = process.argv.slice(2), io = console) {
|
|
44
|
+
const [command, ...rest] = argv;
|
|
45
|
+
if (command === '--help' || command === '-h' || command === 'help') {
|
|
46
|
+
io.log(usage());
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
if (command === '--version' || command === '-v') {
|
|
50
|
+
io.log(require('../package.json').version);
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
if (!command || !Object.prototype.hasOwnProperty.call(COMMANDS, command)) {
|
|
54
|
+
io.error(command ? `[canopy][error] Unknown command: ${command}\n` : '');
|
|
55
|
+
io.error(usage());
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
await registerLoaders();
|
|
59
|
+
const {orchestrate} = require('./orchestrator');
|
|
60
|
+
await orchestrate({argv: [`--${command}`, ...rest]});
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {run, usage, registerLoaders, COMMANDS};
|