Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
e05f195c
Commit
e05f195c
authored
Nov 29, 2024
by
孙灵跃 leon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coopwire 改造批注功能
parent
c300a7a8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
23 deletions
+82
-23
generateManifest.js
generateManifest.js
+56
-0
gulpfile.js
gulpfile.js
+1
-1
package.json
package.json
+1
-0
index.tsx
src/sidebar/index.tsx
+23
-21
tsconfig.json
src/tsconfig.json
+1
-1
No files found.
generateManifest.js
0 → 100644
View file @
e05f195c
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;
}
gulpfile.js
View file @
e05f195c
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'
));
...
...
package.json
View file @
e05f195c
...
...
@@ -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}'"
,
...
...
src/sidebar/index.tsx
View file @
e05f195c
...
...
@@ -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
);
...
...
src/tsconfig.json
View file @
e05f195c
...
...
@@ -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"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment