Commit e05f195c authored by 孙灵跃 leon's avatar 孙灵跃 leon

coopwire 改造批注功能

parent c300a7a8
import { createHash } from 'crypto';
import { readFile, writeFile } from 'fs/promises';
import * as path from 'path';
import { globSync } from 'glob';
/**
* Generate a manifest that maps asset paths to cache-busted URLs.
*
* The generated manifest file is suitable for use with the h-assets Python
* package (https://pypi.org/project/h-assets/) used by backend Hypothesis
* projects for serving static assets. The manifest looks like:
*
* ```
* {
* "scripts/app.bundle.js": "scripts/app.bundle.js?abc123",
* "styles/app.css": "styles/app.css?def456",
* ...
* }
* ```
*
* Returns the data that was written to the manifest.
*
* @param {object} options
* @param {string} [options.pattern] - Glob pattern that specifies which assets to include
* @param {string} [options.manifestPath] - File path to write the manifest to
* @return {Promise<Record<string, string>>}
*/
export async function generateManifest({
pattern = 'build/**/*.{css,js,map}',
manifestPath = 'build/manifest.json',
} = {}) {
const manifestDir = path.dirname(manifestPath);
const files = globSync(pattern).sort();
/** @type {Record<string, string>} */
const manifest = {};
await Promise.all(
files.map(async file => {
const fileContent = await readFile(file);
const hash = await createHash('sha1');
hash.update(fileContent);
const hashSuffix = hash.digest('hex').slice(0, 6);
const relativePath = path.relative(manifestDir, file).replace('\\','/');
manifest[relativePath] = `${relativePath}?${hashSuffix}`;
}),
);
const manifestData = Buffer.from(JSON.stringify(manifest, null, 2), 'utf-8');
await writeFile(manifestPath, manifestData);
return manifest;
}
import {
buildCSS,
buildJS,
generateManifest,
runTests,
watchJS,
} from '@hypothesis/frontend-build';
......@@ -13,6 +12,7 @@ import { servePackage } from './dev-server/serve-package.js';
import annotatorTailwindConfig from './tailwind-annotator.config.js';
import sidebarTailwindConfig from './tailwind-sidebar.config.js';
import tailwindConfig from './tailwind.config.js';
import { generateManifest } from './generateManifest.js'
gulp.task('build-js', () => buildJS('./rollup.config.js'));
gulp.task('watch-js', () => watchJS('./rollup.config.js'));
......
......@@ -115,6 +115,7 @@
"main": "./build/boot.js",
"scripts": {
"build": "cross-env NODE_ENV=production gulp build",
"dev": "cross-env NODE_ENV=development gulp watch",
"lint": "eslint --cache .",
"checkformatting": "prettier --cache --check '**/*.{js,scss,ts,tsx,d.ts}'",
"format": "prettier --cache --list-different --write '**/*.{js,scss,ts,tsx,d.ts}'",
......
......@@ -22,19 +22,19 @@ import { AnnotationActivityService } from './services/annotation-activity';
import { AnnotationsService } from './services/annotations';
import { AnnotationsExporter } from './services/annotations-exporter';
import { APIService } from './services/api';
import { APIRoutesService } from './services/api-routes';
import { AuthService } from './services/auth';
// import { APIRoutesService } from './services/api-routes';
// import { AuthService } from './services/auth';
import { AutosaveService } from './services/autosave';
import { DashboardService } from './services/dashboard';
import { FrameSyncService } from './services/frame-sync';
import { GroupsService } from './services/groups';
// import { GroupsService } from './services/groups';
import { ImportAnnotationsService } from './services/import-annotations';
import { LoadAnnotationsService } from './services/load-annotations';
import { LocalStorageService } from './services/local-storage';
import { PersistedDefaultsService } from './services/persisted-defaults';
import { RouterService } from './services/router';
import { ServiceURLService } from './services/service-url';
import { SessionService } from './services/session';
// import { RouterService } from './services/router';
import type { ServiceURLService } from './services/service-url';
// import { SessionService } from './services/session';
import { StreamFilter } from './services/stream-filter';
import { StreamerService } from './services/streamer';
import { TagsService } from './services/tags';
......@@ -77,19 +77,19 @@ function setupApi(api: APIService, streamer: StreamerService) {
*
* @inject
*/
function syncRoute(router: RouterService) {
router.sync();
}
// function syncRoute(router: RouterService) {
// router.sync();
// }
/**
* Perform the initial fetch of groups and user profile.
*
* @inject
*/
function loadGroupsAndProfile(groups: GroupsService, session: SessionService) {
groups.load();
session.load();
}
// function loadGroupsAndProfile(groups: GroupsService, session: SessionService) {
// groups.load();
// session.load();
// }
/**
* Initialize background processes provided by various services.
......@@ -146,19 +146,19 @@ function startApp(settings: SidebarSettings, appEl: HTMLElement) {
.register('annotationsService', AnnotationsService)
.register('annotationActivity', AnnotationActivityService)
.register('api', APIService)
.register('apiRoutes', APIRoutesService)
.register('auth', AuthService)
// .register('apiRoutes', APIRoutesService)
// .register('auth', AuthService)
.register('autosaveService', AutosaveService)
.register('dashboard', DashboardService)
.register('frameSync', FrameSyncService)
.register('groups', GroupsService)
// .register('groups', GroupsService)
.register('importAnnotationsService', ImportAnnotationsService)
.register('loadAnnotationsService', LoadAnnotationsService)
.register('localStorage', LocalStorageService)
.register('persistedDefaults', PersistedDefaultsService)
.register('router', RouterService)
.register('serviceURL', ServiceURLService)
.register('session', SessionService)
// .register('router', RouterService)
// .register('serviceURL', ServiceURLService)
// .register('session', SessionService)
.register('streamer', StreamerService)
.register('streamFilter', StreamFilter)
.register('tags', TagsService)
......@@ -179,10 +179,12 @@ function startApp(settings: SidebarSettings, appEl: HTMLElement) {
// We sync the route with the initial URL as the first step, because
// initialization of other services may depend on the route (eg. enabling
// sidebar-only behavior).
container.run(syncRoute);
// container.run(syncRoute);
container.run(initServices);
container.run(setupApi);
container.run(loadGroupsAndProfile);
// container.run(loadGroupsAndProfile);
container.run(startRPCServer);
container.run(setupFrameSync);
......
......@@ -23,7 +23,7 @@
// code for the browser.
"types": []
},
"include": ["**/*.js", "**/*.ts", "**/*.tsx", "types/*.d.ts"],
"include": ["**/*.js", "**/*.ts", "**/*.tsx", "types/*.d.ts", "../generateManifest.js"],
"exclude": [
// Tests are not checked.
"**/test/**/*.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment