@jpmorganchase/mosaic-source-local-folder 0.1.0-beta.3 → 0.1.0-beta.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @jpmorganchase/mosaic-source-local-folder
2
2
 
3
+ ## 0.1.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - bd285df: added dist to package.json
8
+ - Updated dependencies [bd285df]
9
+ - @jpmorganchase/mosaic-types@0.1.0-beta.4
10
+
3
11
  ## 0.1.0-beta.3
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-source-local-folder",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "author": "",
5
- "description": "",
5
+ "description": "Mosaic local folder source for core file system",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "engines": {
10
10
  "node": ">= 12.0.0"
11
11
  },
12
+ "files": [
13
+ "dist"
14
+ ],
12
15
  "scripts": {
13
16
  "build": "tsc",
14
17
  "clean": "rm -fr dist"
@@ -18,7 +21,7 @@
18
21
  "url": "git@github.com:jpmorganchase/mosaic.git"
19
22
  },
20
23
  "dependencies": {
21
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.3",
24
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.4",
22
25
  "rxjs": "^7.5.5"
23
26
  }
24
27
  }
@@ -1,2 +0,0 @@
1
- @jpmorganchase/mosaic-source-local-folder:build: cache hit, replaying output 43f8c76914427868
2
- @jpmorganchase/mosaic-source-local-folder:build: $ tsc
@@ -1,2 +0,0 @@
1
- @jpmorganchase/mosaic-source-local-folder:clean: cache hit, replaying output dab121926a1eaa84
2
- @jpmorganchase/mosaic-source-local-folder:clean: $ rm -fr dist
@@ -1,31 +0,0 @@
1
- import { PathLike, watch, WatchOptions } from 'fs';
2
- import { Observable } from 'rxjs';
3
-
4
- export default function fromFsWatch(
5
- filename: PathLike,
6
- options?:
7
- | WatchOptions
8
- | BufferEncoding
9
- | string
10
- | null
11
- | (WatchOptions & { encoding: 'buffer' })
12
- | 'buffer'
13
- ) {
14
- return new Observable(subscriber => {
15
- const watcher = watch(filename, options as any, (_eventType, filename) => {
16
- subscriber.next(filename);
17
- });
18
-
19
- watcher.once('error', (error: Error) => {
20
- subscriber.error(error);
21
- });
22
-
23
- watcher.once('close', () => {
24
- subscriber.complete();
25
- });
26
-
27
- return function unsubscribe() {
28
- watcher.close();
29
- };
30
- });
31
- }
package/src/index.ts DELETED
@@ -1,63 +0,0 @@
1
- import { concatMap, delay, merge, Observable, of, switchMap } from 'rxjs';
2
- import glob from 'fast-glob';
3
- import path from 'path';
4
- import fs from 'fs';
5
- import lodashMerge from 'lodash/merge';
6
-
7
- import type Source from '@jpmorganchase/mosaic-types/dist/Source';
8
- import type Page from '@jpmorganchase/mosaic-types/dist/Page';
9
-
10
- import fromFsWatch from './fromFsWatch';
11
-
12
- export interface LocalFolderSourceOptions {
13
- extensions: string[];
14
- prefixDir?: string;
15
- rootDir: string;
16
- }
17
-
18
- const LocalFolderSource: Source<LocalFolderSourceOptions> = {
19
- create(options, { serialiser }): Observable<Page<{}>[]> {
20
- return merge(of(null), fromFsWatch(options.rootDir, { recursive: true })).pipe(
21
- delay(1000),
22
- switchMap(() =>
23
- glob(createFileGlob('**', options.extensions), {
24
- cwd: options.rootDir,
25
- onlyFiles: true
26
- })
27
- ),
28
- concatMap(
29
- async (filepaths: string[]) =>
30
- await Promise.all(
31
- filepaths.map(async (filepath: string) => {
32
- const fullPath = path.join(options.rootDir, filepath);
33
- return lodashMerge(
34
- {},
35
- await serialiser.deserialise(fullPath, await fs.promises.readFile(fullPath)),
36
- {
37
- lastModified: new Date(await getLastModifiedDate(fullPath)).getTime(),
38
- fullPath: `/${
39
- options.prefixDir ? path.join(options.prefixDir, filepath) : filepath
40
- }`.replace(/^\/{2,}/, '/')
41
- }
42
- );
43
- })
44
- )
45
- )
46
- );
47
- }
48
- };
49
-
50
- async function getLastModifiedDate(fullPath: string) {
51
- const resolvedRoute = await fs.promises.realpath(fullPath);
52
- const stats = await fs.promises.stat(resolvedRoute);
53
- return stats?.mtimeMs ? stats.mtimeMs : 0;
54
- }
55
-
56
- function createFileGlob(url: string, pageExtensions: string[]) {
57
- if (pageExtensions.length === 1) {
58
- return `${url}${pageExtensions[0]}`;
59
- }
60
- return `${url}{${pageExtensions.join(',')}}`;
61
- }
62
-
63
- export default LocalFolderSource;
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist"
6
- },
7
- "include": ["src"],
8
- "exclude": ["src/**/__tests__/**/*", "src/__tests__/**/*"]
9
- }