@notifiles/sdk 1.0.0
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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.modern.cjs +856 -0
- package/dist/index.modern.cjs.map +1 -0
- package/dist/index.modern.modern.js +690 -0
- package/dist/index.modern.modern.js.map +1 -0
- package/package.json +152 -0
- package/src/cloud/add/index.js +38 -0
- package/src/cloud/add/index.test.js +38 -0
- package/src/cloud/add/lib/validate.js +16 -0
- package/src/cloud/index.js +3 -0
- package/src/cloud/list/index.js +18 -0
- package/src/cloud/list/index.test.js +13 -0
- package/src/email/build copy/lib/perform/email.js +52 -0
- package/src/index.js +3 -0
- package/src/lib/adaptSettings.js +12 -0
- package/src/lib/cloudLibrary/bunny/index.js +2 -0
- package/src/lib/cloudLibrary/bunny/isValid.js +32 -0
- package/src/lib/cloudLibrary/bunny/upload.js +35 -0
- package/src/lib/cloudLibrary/index.js +20 -0
- package/src/lib/cloudLibrary/minio/index.js +4 -0
- package/src/lib/cloudLibrary/minio/isValid.js +33 -0
- package/src/lib/cloudLibrary/minio/remove.js +58 -0
- package/src/lib/cloudLibrary/minio/upload.js +61 -0
- package/src/lib/cloudLibrary/minio/uploadFolder.js +26 -0
- package/src/lib/entries/getAtPath.js +105 -0
- package/src/lib/entries/isPathEntry.js +29 -0
- package/src/lib/entries.js +144 -0
- package/src/lib/fs/checkFileExists.js +6 -0
- package/src/lib/fs/directoryFilesRecursive.js +83 -0
- package/src/lib/fs/ensureDirectoryExists.js +10 -0
- package/src/lib/fs/getFileCallerURL.js +12 -0
- package/src/lib/fs/importFileAsText.js +15 -0
- package/src/lib/fs/importJSONAsync.js +16 -0
- package/src/lib/fs/importYAMLAsync.js +14 -0
- package/src/lib/remark/hastToHtml.js +6 -0
- package/src/lib/remark/htmlToHast.js +6 -0
- package/src/lib/remark/htmlToMarkdown copy.js +12 -0
- package/src/lib/remark/htmlToMarkdown.js +23 -0
- package/src/lib/remark/htmlToMdast.js +13 -0
- package/src/lib/remark/htmlToMdast_.js +21 -0
- package/src/lib/remark/htmlToMdast_3.js +21 -0
- package/src/lib/remark/markdownToHTML.js +22 -0
- package/src/lib/remark/markdownToLexer.js +19 -0
- package/src/lib/remark/mdastToHTML.js +8 -0
- package/src/lib/remark/mdastToMarkdown.js +24 -0
- package/src/lib/remark/mdastToString.js +12 -0
- package/src/project/index.js +4 -0
- package/src/project/isProject/index.js +26 -0
- package/src/project/isProject/index.test.js +13 -0
- package/src/project/isProject/sync.js +18 -0
- package/src/project/lib/activity/createFileIfNeeded.js +33 -0
- package/src/project/lib/activity/defaultContent.json +5 -0
- package/src/project/lib/activity/updateToFile.js +32 -0
- package/src/project/lib/manifest/createFileIfNeeded.js +44 -0
- package/src/project/lib/manifest/read.js +21 -0
- package/src/project/lib/manifest/update.js +36 -0
- package/src/project/lib/manifest/updateToFile.js +22 -0
- package/src/project/new/index.js +2 -0
- package/src/project/new/plain.js +49 -0
- package/src/project/new/plain.test.js +38 -0
- package/src/template/build/entry.js +37 -0
- package/src/template/build/index.js +2 -0
- package/src/template/build/lib/email/index.js +100 -0
- package/src/template/build/lib/email/translate.js +16 -0
- package/src/template/build/lib/textmessage/index.js +44 -0
- package/src/template/build/lib/textmessage/translate.js +25 -0
- package/src/template/build/path.js +18 -0
- package/src/template/build/path.test.js +29 -0
- package/src/template/cloudify/entry.js +20 -0
- package/src/template/cloudify/index.js +2 -0
- package/src/template/cloudify/lib/email/attachments/addAttachment.js +24 -0
- package/src/template/cloudify/lib/email/attachments/index.js +137 -0
- package/src/template/cloudify/lib/email/attachments/treatLocalFile.js +13 -0
- package/src/template/cloudify/lib/email/attachments/treatRemoteFile.js +26 -0
- package/src/template/cloudify/lib/email/image/index.js +90 -0
- package/src/template/cloudify/lib/email/image/treatLocalFile.js +13 -0
- package/src/template/cloudify/lib/email/image/treatRemoteFile.js +26 -0
- package/src/template/cloudify/lib/email/index.js +77 -0
- package/src/template/cloudify/lib/remove.js +14 -0
- package/src/template/cloudify/lib/textMessage.js +9 -0
- package/src/template/cloudify/lib/upload.js +14 -0
- package/src/template/cloudify/path.js +20 -0
- package/src/template/cloudify/path.test.js +24 -0
- package/src/template/consolidate/entry.js +18 -0
- package/src/template/consolidate/index.js +2 -0
- package/src/template/consolidate/lib/email.js +63 -0
- package/src/template/consolidate/lib/image/index.js +35 -0
- package/src/template/consolidate/lib/image/treatLocalFile.js +14 -0
- package/src/template/consolidate/lib/image/treatRemoteFile.js +25 -0
- package/src/template/consolidate/lib/textMessage.js +5 -0
- package/src/template/consolidate/path.js +18 -0
- package/src/template/consolidate/path.test.js +14 -0
- package/src/template/format/entry.js +57 -0
- package/src/template/format/index.js +2 -0
- package/src/template/format/path.js +18 -0
- package/src/template/format/path.test.js +29 -0
- package/src/template/index.js +8 -0
- package/src/template/lib/activity/createFileIfNeeded.js +33 -0
- package/src/template/lib/activity/defaultContent.json +4 -0
- package/src/template/lib/activity/get.js +20 -0
- package/src/template/lib/activity/updateToFile.js +33 -0
- package/src/template/lib/manifest/createFileIfNeeded.js +41 -0
- package/src/template/lib/manifest/read.js +22 -0
- package/src/template/lib/manifest/update.js +18 -0
- package/src/template/lib/manifest/updateToFile.js +22 -0
- package/src/template/new/index.js +66 -0
- package/src/template/new/index.test.js +19 -0
- package/src/template/optimize/entry.js +18 -0
- package/src/template/optimize/index.js +2 -0
- package/src/template/optimize/lib/email.js +58 -0
- package/src/template/optimize/lib/image/index.js +40 -0
- package/src/template/optimize/lib/textMessage.js +8 -0
- package/src/template/optimize/path.js +18 -0
- package/src/template/optimize/path.test.js +16 -0
- package/src/template/sync/entry.js +18 -0
- package/src/template/sync/index.js +2 -0
- package/src/template/sync/lib/email.js +86 -0
- package/src/template/sync/lib/textMessage.js +80 -0
- package/src/template/sync/lib/upload.js +14 -0
- package/src/template/sync/path.js +18 -0
- package/src/template/sync/path.test.js +29 -0
- package/src/template/update/index.js +1 -0
- package/src/template/update/path.js +41 -0
- package/src/template/update/path.test.js +46 -0
- package/src/template/version/entry.js +10 -0
- package/src/template/version/index.js +2 -0
- package/src/template/version/lib/perform.js +74 -0
- package/src/template/version/lib/reset.js +16 -0
- package/src/template/version/lib/updatePost.js +16 -0
- package/src/template/version/path.js +20 -0
- package/src/template/version/path.test.js +16 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as Minio from 'minio'
|
|
2
|
+
|
|
3
|
+
export default async ({
|
|
4
|
+
sourceUrl,
|
|
5
|
+
filename,
|
|
6
|
+
auth,
|
|
7
|
+
// contentType = 'image/png'
|
|
8
|
+
}) => {
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const {
|
|
12
|
+
endPoint,
|
|
13
|
+
accessKey,
|
|
14
|
+
secretKey,
|
|
15
|
+
bucketName
|
|
16
|
+
} = auth
|
|
17
|
+
|
|
18
|
+
const minioClient = new Minio.Client({
|
|
19
|
+
endPoint,
|
|
20
|
+
// port,
|
|
21
|
+
// useSSL,
|
|
22
|
+
accessKey,
|
|
23
|
+
secretKey,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const destinationObject = filename
|
|
27
|
+
|
|
28
|
+
const exists = await minioClient.bucketExists(bucketName)
|
|
29
|
+
if (!exists) {
|
|
30
|
+
return null
|
|
31
|
+
// await minioClient.makeBucket(bucketName, 'us-east-1')
|
|
32
|
+
// console.log('Bucket ' + bucketName + ' created in "us-east-1".')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const metaData = {
|
|
36
|
+
// 'Content-Type': contentType,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const minioResult = await new Promise((resolve, reject) => {
|
|
40
|
+
minioClient.fPutObject(
|
|
41
|
+
bucketName,
|
|
42
|
+
destinationObject,
|
|
43
|
+
sourceUrl,
|
|
44
|
+
metaData,
|
|
45
|
+
(error, objInfo) => {
|
|
46
|
+
if (error) {
|
|
47
|
+
reject(error)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
resolve(objInfo)
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
const url = `https://${endPoint}/${bucketName}/${filename}`
|
|
55
|
+
return { url }
|
|
56
|
+
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error(e)
|
|
59
|
+
}
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FsTree } from 'fs-tree-tool'
|
|
2
|
+
import upload from './upload'
|
|
3
|
+
|
|
4
|
+
export default async (props) => {
|
|
5
|
+
const {
|
|
6
|
+
path
|
|
7
|
+
// contentType = 'image/png'
|
|
8
|
+
} = props
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const tree = await FsTree.getDirectoryTree(path)
|
|
12
|
+
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.error(e)
|
|
15
|
+
}
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const uploadFolder = (props) => {
|
|
21
|
+
const { path } = props
|
|
22
|
+
|
|
23
|
+
return upload({
|
|
24
|
+
...props,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import checkFileExists from '../fs/checkFileExists.js'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import fsPath from 'path'
|
|
4
|
+
import _ from 'underscore'
|
|
5
|
+
import isPathEntry from './isPathEntry.js'
|
|
6
|
+
import importJSONAsync from "../fs/importJSONAsync.js"
|
|
7
|
+
import slug from 'slug'
|
|
8
|
+
import createActivityIfNeeded from '../../template/lib/activity/createFileIfNeeded.js'
|
|
9
|
+
|
|
10
|
+
const perform = async (props) => {
|
|
11
|
+
const {
|
|
12
|
+
path,
|
|
13
|
+
} = props
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
if (!(await checkFileExists(path))) {
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const items = await fs.promises.readdir(path)
|
|
21
|
+
|
|
22
|
+
if (!items || !items.length) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let results = (await Promise.all(items.map(async item => {
|
|
27
|
+
|
|
28
|
+
const folderPath = fsPath.join(path, item)
|
|
29
|
+
|
|
30
|
+
const folderPathStat = await fs.promises.stat(folderPath)
|
|
31
|
+
if (!folderPathStat) {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isDir = folderPathStat.isDirectory()
|
|
36
|
+
if (!isDir) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!(await isPathEntry({ path: folderPath }))) {
|
|
41
|
+
return perform({
|
|
42
|
+
...props,
|
|
43
|
+
path: folderPath
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
let testMessagePath = fsPath.join(folderPath, 'textmessage.txt')
|
|
49
|
+
let pushPath = fsPath.join(folderPath, 'push.txt')
|
|
50
|
+
const i18nPath = fsPath.join(folderPath, 'i18n.json')
|
|
51
|
+
let manifest = await importJSONAsync(fsPath.join(folderPath, 'manifest.json'))
|
|
52
|
+
|
|
53
|
+
await createActivityIfNeeded({ path: folderPath })
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
let activity
|
|
57
|
+
const activityPath = fsPath.join(folderPath, '.activity.json')
|
|
58
|
+
if (await checkFileExists(activityPath)) {
|
|
59
|
+
activity = await importJSONAsync(activityPath)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// await createActivityIfNeeded({ path: folderPath })
|
|
63
|
+
|
|
64
|
+
// const module = await import(emailPath)
|
|
65
|
+
let textMessage = null
|
|
66
|
+
let push = null
|
|
67
|
+
let i18n = null
|
|
68
|
+
|
|
69
|
+
if (await checkFileExists(testMessagePath)) {
|
|
70
|
+
textMessage = await fs.promises.readFile(testMessagePath, 'utf8')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (await checkFileExists(pushPath)) {
|
|
74
|
+
push = await fs.promises.readFile(pushPath, 'utf8')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (await checkFileExists(i18nPath)) {
|
|
78
|
+
i18n = await importJSONAsync(i18nPath)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
return [{
|
|
83
|
+
name: item,
|
|
84
|
+
slug: slug(item),
|
|
85
|
+
path: folderPath,
|
|
86
|
+
// email: module,
|
|
87
|
+
textMessage,
|
|
88
|
+
push,
|
|
89
|
+
i18n: i18n ? i18n : {},
|
|
90
|
+
manifest,
|
|
91
|
+
activity
|
|
92
|
+
}]
|
|
93
|
+
|
|
94
|
+
}))).filter(a => a)
|
|
95
|
+
|
|
96
|
+
results = _.flatten(results)
|
|
97
|
+
return results
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
console.error(e)
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default perform
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import checkFileExists from '../fs/checkFileExists.js'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import fsPath from 'path'
|
|
4
|
+
|
|
5
|
+
export default async (props) => {
|
|
6
|
+
const {
|
|
7
|
+
path,
|
|
8
|
+
} = props
|
|
9
|
+
|
|
10
|
+
if (!(await checkFileExists(path))) {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const pathStat = await fs.promises.stat(path)
|
|
15
|
+
if (!pathStat) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isDir = pathStat.isDirectory()
|
|
20
|
+
if (!isDir) {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const postPath = fsPath.join(path, 'email.js')
|
|
25
|
+
const postPath2 = fsPath.join(path, 'email.tsx')
|
|
26
|
+
|
|
27
|
+
return ((await checkFileExists(postPath))
|
|
28
|
+
|| (await checkFileExists(postPath2)))
|
|
29
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import checkFileExists from './fs/checkFileExists.js'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import fsPath from 'path'
|
|
4
|
+
import _ from 'underscore'
|
|
5
|
+
import importJSONAsync from "./fs/importJSONAsync.js"
|
|
6
|
+
import importYAMLAsync from "./fs/importYAMLAsync.js"
|
|
7
|
+
import markdownToLexer from './remark/markdownToLexer.js'
|
|
8
|
+
import createStatusIfNeeded from '../post/lib/activity/createFileIfNeeded.js'
|
|
9
|
+
|
|
10
|
+
const perform = async (props) => {
|
|
11
|
+
const {
|
|
12
|
+
path,
|
|
13
|
+
} = props
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
if (!(await checkFileExists(path))) {
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const items = await fs.promises.readdir(path)
|
|
21
|
+
|
|
22
|
+
if (!items || !items.length) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let results = (await Promise.all(items.map(async item => {
|
|
27
|
+
|
|
28
|
+
const folderPath = fsPath.join(path, item)
|
|
29
|
+
|
|
30
|
+
const folderPathStat = await fs.promises.stat(folderPath)
|
|
31
|
+
if (!folderPathStat) {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isDir = folderPathStat.isDirectory()
|
|
36
|
+
if (!isDir) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await createStatusIfNeeded({ path: folderPath })
|
|
41
|
+
|
|
42
|
+
const postPath = fsPath.join(folderPath, 'post.md')
|
|
43
|
+
const excerptPath = fsPath.join(folderPath, 'excerpt.md')
|
|
44
|
+
const postConsolidatedPath = fsPath.join(folderPath, '.post.consolidated.md')
|
|
45
|
+
const postBuiltPath = fsPath.join(folderPath, '.post.built.md')
|
|
46
|
+
const postOptimizedPath = fsPath.join(folderPath, '.post.optimized.md')
|
|
47
|
+
const postCloudPath = fsPath.join(folderPath, '.post.cloud.md')
|
|
48
|
+
const manifestPath = fsPath.join(folderPath, 'manifest.yaml')
|
|
49
|
+
const statusPath = fsPath.join(folderPath, '.activity.json')
|
|
50
|
+
|
|
51
|
+
if (!(await checkFileExists(postPath))
|
|
52
|
+
|| !(await checkFileExists(manifestPath))
|
|
53
|
+
) {
|
|
54
|
+
return perform({
|
|
55
|
+
...props,
|
|
56
|
+
path: folderPath
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const post = await fs.promises.readFile(postPath, 'utf8')
|
|
61
|
+
const postMdast = markdownToLexer({
|
|
62
|
+
data: post
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const manifest = await importYAMLAsync(manifestPath)
|
|
66
|
+
if (manifest.skip) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let postConsolidated = null
|
|
71
|
+
let postConsolidatedMdast = null
|
|
72
|
+
let postBuilt = null
|
|
73
|
+
let postOptimized = null
|
|
74
|
+
let postCloud = null
|
|
75
|
+
let postBuiltMdast = null
|
|
76
|
+
let excerpt = null
|
|
77
|
+
let status = null
|
|
78
|
+
|
|
79
|
+
if (await checkFileExists(postConsolidatedPath)) {
|
|
80
|
+
postConsolidated = await fs.promises.readFile(postConsolidatedPath, 'utf8')
|
|
81
|
+
postConsolidatedMdast = markdownToLexer({
|
|
82
|
+
data: postConsolidated
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (await checkFileExists(postBuiltPath)) {
|
|
87
|
+
postBuilt = await fs.promises.readFile(postBuiltPath, 'utf8')
|
|
88
|
+
postBuiltMdast = markdownToLexer({
|
|
89
|
+
data: postBuilt
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (await checkFileExists(excerptPath)) {
|
|
94
|
+
excerpt = await fs.promises.readFile(excerptPath, 'utf8')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (await checkFileExists(postOptimizedPath)) {
|
|
98
|
+
postOptimized = await fs.promises.readFile(postOptimizedPath, 'utf8')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (await checkFileExists(postCloudPath)) {
|
|
102
|
+
postCloud = await fs.promises.readFile(postCloudPath, 'utf8')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (await checkFileExists(statusPath)) {
|
|
106
|
+
status = await importJSONAsync(statusPath, 'utf8')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return [{
|
|
110
|
+
path: folderPath,
|
|
111
|
+
excerpt,
|
|
112
|
+
post,
|
|
113
|
+
postMdast,
|
|
114
|
+
postBuilt,
|
|
115
|
+
postBuiltMdast,
|
|
116
|
+
postConsolidated,
|
|
117
|
+
postConsolidatedMdast,
|
|
118
|
+
postCloud,
|
|
119
|
+
postOptimized,
|
|
120
|
+
manifest,
|
|
121
|
+
status,
|
|
122
|
+
post: {
|
|
123
|
+
source: post,
|
|
124
|
+
mdast: postMdast,
|
|
125
|
+
built: postBuilt,
|
|
126
|
+
consolidated: postConsolidated,
|
|
127
|
+
consolidatedMdast: postConsolidatedMdast,
|
|
128
|
+
cloud: postCloud,
|
|
129
|
+
optimized: postOptimized
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
|
|
133
|
+
}))).filter(a => a)
|
|
134
|
+
|
|
135
|
+
results = _.flatten(results)
|
|
136
|
+
return results
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
console.error(e)
|
|
140
|
+
return null
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default perform
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import checkFileExists from './checkFileExists.js'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import fsPath from 'path'
|
|
4
|
+
import _ from 'underscore'
|
|
5
|
+
//https://www.npmjs.com/package/directory-import
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const perform = async ({ path,
|
|
9
|
+
includeMeta = false,
|
|
10
|
+
excludes = ['spec.js'],
|
|
11
|
+
includeExtensions = ['.js', '.ts', '.json']
|
|
12
|
+
}) => {
|
|
13
|
+
try {
|
|
14
|
+
if (!(await checkFileExists(path))) {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const items = await fs.promises.readdir(path)
|
|
19
|
+
|
|
20
|
+
if (!items || !items.length) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let results = (await Promise.all(items.map(async item => {
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const __path = fsPath.join(path, item)
|
|
28
|
+
|
|
29
|
+
const _stat = await fs.promises.stat(__path)
|
|
30
|
+
if (!_stat) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isDir = _stat.isDirectory()
|
|
35
|
+
if (isDir) {
|
|
36
|
+
return perform({ path: __path })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!(await checkFileExists(__path))) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (item.includes('spec.js')) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
const extension = getExtension(item)
|
|
47
|
+
if (!includeExtensions.includes(extension)) {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (includeMeta) {
|
|
52
|
+
const racine = getFileRaw(__path)
|
|
53
|
+
const _module = await import(__path)
|
|
54
|
+
const md = `${racine}.md`
|
|
55
|
+
let documentation = null
|
|
56
|
+
if ((await checkFileExists(md))) {
|
|
57
|
+
documentation = await fs.promises.readFile(md, 'utf8')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return [{
|
|
61
|
+
module: _module,
|
|
62
|
+
path: __path,
|
|
63
|
+
documentation
|
|
64
|
+
}]
|
|
65
|
+
} else {
|
|
66
|
+
return [(await import(__path))]
|
|
67
|
+
}
|
|
68
|
+
}))).filter(a => a)
|
|
69
|
+
|
|
70
|
+
results = _.flatten(results)
|
|
71
|
+
return results
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.error(e)
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const getExtension = str => str.slice(str.lastIndexOf("."))
|
|
80
|
+
const getFileRaw = str => str.split('.').slice(0, -1).join('.')
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export default perform
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default () => {
|
|
2
|
+
const error = new Error()
|
|
3
|
+
const stack = error.stack?.split('\n')
|
|
4
|
+
const data = stack[3]
|
|
5
|
+
const filePathPattern = new RegExp(`(file:[/]{2}.+[^:0-9]):{1}[0-9]+:{1}[0-9]+`)
|
|
6
|
+
const result = filePathPattern.exec(data)
|
|
7
|
+
let filePath = ''
|
|
8
|
+
if (result && (result.length > 1)) {
|
|
9
|
+
filePath = result[1]
|
|
10
|
+
}
|
|
11
|
+
return filePath
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import checkFileExists from "./checkFileExists.js"
|
|
3
|
+
|
|
4
|
+
export default async _url => {
|
|
5
|
+
try {
|
|
6
|
+
if (!(await checkFileExists(_url))) {
|
|
7
|
+
return null
|
|
8
|
+
}
|
|
9
|
+
const fileUrl = new URL(_url, import.meta.url)
|
|
10
|
+
return fs.promises.readFile(fileUrl, 'utf8')
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.log("[notifiles]", `importFileAsText → `, e)
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import checkFileExists from "./checkFileExists.js"
|
|
3
|
+
|
|
4
|
+
export default async _url => {
|
|
5
|
+
// try {
|
|
6
|
+
if (!(await checkFileExists(_url))) {
|
|
7
|
+
return null
|
|
8
|
+
}
|
|
9
|
+
const fileUrl = new URL(_url, import.meta.url)
|
|
10
|
+
const parsedPackageJSON = JSON.parse(await fs.promises.readFile(fileUrl, 'utf8'))
|
|
11
|
+
return parsedPackageJSON
|
|
12
|
+
// } catch (e) {
|
|
13
|
+
// console.log("[notifiles]", `importJSONAsync → `, e)
|
|
14
|
+
// return null
|
|
15
|
+
// }
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import checkFileExists from "./checkFileExists.js"
|
|
3
|
+
import YAML from 'yaml'
|
|
4
|
+
|
|
5
|
+
export default async _url => {
|
|
6
|
+
if (!(await checkFileExists(_url))) {
|
|
7
|
+
return null
|
|
8
|
+
}
|
|
9
|
+
const fileUrl = new URL(_url, import.meta.url)
|
|
10
|
+
const file = fs.readFileSync(fileUrl, 'utf8')
|
|
11
|
+
|
|
12
|
+
const parsed = YAML.parse(file)
|
|
13
|
+
return parsed
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { unified } from 'unified'
|
|
2
|
+
import stringify from 'remark-stringify'
|
|
3
|
+
import rehypeParse from 'rehype-parse'
|
|
4
|
+
import rehype2remark from 'rehype-remark'
|
|
5
|
+
|
|
6
|
+
export default async ({ data } = {}) => {
|
|
7
|
+
const processor = unified()
|
|
8
|
+
.use(rehypeParse)
|
|
9
|
+
.use(rehype2remark)
|
|
10
|
+
.use(stringify)
|
|
11
|
+
return processor.process(data)
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fromHtml } from 'hast-util-from-html'
|
|
2
|
+
import { toMdast } from 'hast-util-to-mdast'
|
|
3
|
+
import { toMarkdown } from 'mdast-util-to-markdown'
|
|
4
|
+
|
|
5
|
+
export default async ({ data } = {}) => {
|
|
6
|
+
const hast = fromHtml(data, { fragment: true })
|
|
7
|
+
const mdast = toMdast(hast)
|
|
8
|
+
const markdown = toMarkdown(mdast)
|
|
9
|
+
return markdown
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// import fs from 'node:fs/promises'
|
|
14
|
+
// import {fromHtml} from 'hast-util-from-html'
|
|
15
|
+
// import {toMdast} from 'hast-util-to-mdast'
|
|
16
|
+
// import {toMarkdown} from 'mdast-util-to-markdown'
|
|
17
|
+
|
|
18
|
+
// const html = String(await fs.readFile('example.html'))
|
|
19
|
+
// const hast = fromHtml(html, {fragment: true})
|
|
20
|
+
// const mdast = toMdast(hast)
|
|
21
|
+
// const markdown = toMarkdown(mdast)
|
|
22
|
+
|
|
23
|
+
// console.log(markdown)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import htmlToMarkdown from "./htmlToMarkdown.js"
|
|
2
|
+
import markdownToLexer from "./markdownToLexer.js"
|
|
3
|
+
|
|
4
|
+
export default async ({ data } = {}) => {
|
|
5
|
+
const file = await htmlToMarkdown({ data })
|
|
6
|
+
if (!file) {
|
|
7
|
+
return null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const md = String(file)
|
|
11
|
+
const lexer = markdownToLexer({ data: md })
|
|
12
|
+
return lexer
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { fromHtml, } from 'hast-util-from-html'
|
|
2
|
+
import { toMdast } from 'hast-util-to-mdast'
|
|
3
|
+
|
|
4
|
+
export default async ({ data } = {}) => {
|
|
5
|
+
const hast = fromHtml(data, { fragment: true })
|
|
6
|
+
const mdast = toMdast(hast)
|
|
7
|
+
return mdast
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// import fs from 'node:fs/promises'
|
|
12
|
+
// import {fromHtml} from 'hast-util-from-html'
|
|
13
|
+
// import {toMdast} from 'hast-util-to-mdast'
|
|
14
|
+
// import {toMarkdown} from 'mdast-util-to-markdown'
|
|
15
|
+
|
|
16
|
+
// const html = String(await fs.readFile('example.html'))
|
|
17
|
+
// const hast = fromHtml(html, {fragment: true})
|
|
18
|
+
// const mdast = toMdast(hast)
|
|
19
|
+
// const markdown = toMarkdown(mdast)
|
|
20
|
+
|
|
21
|
+
// console.log(markdown)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { fromHtml } from 'hast-util-from-html'
|
|
2
|
+
import { toMdast } from 'hast-util-to-mdast'
|
|
3
|
+
|
|
4
|
+
export default async ({ data } = {}) => {
|
|
5
|
+
const hast = fromHtml(data, { fragment: true })
|
|
6
|
+
const mdast = toMdast(hast)
|
|
7
|
+
return mdast
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// import fs from 'node:fs/promises'
|
|
12
|
+
// import {fromHtml} from 'hast-util-from-html'
|
|
13
|
+
// import {toMdast} from 'hast-util-to-mdast'
|
|
14
|
+
// import {toMarkdown} from 'mdast-util-to-markdown'
|
|
15
|
+
|
|
16
|
+
// const html = String(await fs.readFile('example.html'))
|
|
17
|
+
// const hast = fromHtml(html, {fragment: true})
|
|
18
|
+
// const mdast = toMdast(hast)
|
|
19
|
+
// const markdown = toMarkdown(mdast)
|
|
20
|
+
|
|
21
|
+
// console.log(markdown)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import rehypeStringify from 'rehype-stringify'
|
|
3
|
+
import remarkGfm from 'remark-gfm'
|
|
4
|
+
import remarkParse from 'remark-parse'
|
|
5
|
+
import remarkRehype from 'remark-rehype'
|
|
6
|
+
import { unified } from 'unified'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default async ({
|
|
10
|
+
data,
|
|
11
|
+
} = {}) => {
|
|
12
|
+
|
|
13
|
+
const file = await unified()
|
|
14
|
+
.use(remarkParse)
|
|
15
|
+
.use(remarkGfm)
|
|
16
|
+
.use(remarkRehype)
|
|
17
|
+
.use(rehypeStringify)
|
|
18
|
+
.process(data)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
return String(file)
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { unified } from 'unified'
|
|
2
|
+
import remarkParse from 'remark-parse'
|
|
3
|
+
|
|
4
|
+
export default ({ data } = {}) => {
|
|
5
|
+
const tokens = unified()
|
|
6
|
+
.use(remarkParse, { gfm: true })
|
|
7
|
+
.parse(data)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// const _tokens = unified()
|
|
12
|
+
// .use(remarkParse)
|
|
13
|
+
// .use(remarkGfm)
|
|
14
|
+
// .parse(data)
|
|
15
|
+
|
|
16
|
+
// const a = mdastToHTML({ mdast: _tokens })
|
|
17
|
+
|
|
18
|
+
return tokens
|
|
19
|
+
}
|