@tachybase/plugin-block-charts 0.23.8
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/.turbo/turbo-build.log +9 -0
- package/README.md +88 -0
- package/client.d.ts +3 -0
- package/client.js +65 -0
- package/dist/client/block/ChartBlock.d.ts +2 -0
- package/dist/client/block/ChartBlockDesigner.d.ts +2 -0
- package/dist/client/block/ChartBlockInitializer.d.ts +4 -0
- package/dist/client/block/ChartDataProvider.d.ts +16 -0
- package/dist/client/block/formatters.d.ts +15 -0
- package/dist/client/block/index.d.ts +3 -0
- package/dist/client/block/transformers.d.ts +10 -0
- package/dist/client/chart/antd/GroupedTable.d.ts +6 -0
- package/dist/client/chart/antd/antd.d.ts +7 -0
- package/dist/client/chart/antd/index.d.ts +5 -0
- package/dist/client/chart/antd/statistic.d.ts +7 -0
- package/dist/client/chart/antd/table.d.ts +6 -0
- package/dist/client/chart/chart.d.ts +77 -0
- package/dist/client/chart/configs.d.ts +79 -0
- package/dist/client/chart/g2plot/AntChart.d.ts +2 -0
- package/dist/client/chart/g2plot/bar.d.ts +6 -0
- package/dist/client/chart/g2plot/configs.d.ts +40 -0
- package/dist/client/chart/g2plot/dualAxes.d.ts +7 -0
- package/dist/client/chart/g2plot/g2plot.d.ts +10 -0
- package/dist/client/chart/g2plot/index.d.ts +3 -0
- package/dist/client/chart/g2plot/pie.d.ts +7 -0
- package/dist/client/chart/group.d.ts +32 -0
- package/dist/client/configure/ChartConfigProvider.d.ts +18 -0
- package/dist/client/configure/ChartConfigure.d.ts +18 -0
- package/dist/client/configure/FilterDynamicComponent.d.ts +2 -0
- package/dist/client/configure/index.d.ts +2 -0
- package/dist/client/configure/schemas/configure.d.ts +4 -0
- package/dist/client/filter/CollectionFieldInitializer.d.ts +2 -0
- package/dist/client/filter/FilterActionInitializers.d.ts +15 -0
- package/dist/client/filter/FilterBlockDesigner.d.ts +2 -0
- package/dist/client/filter/FilterBlockInitializer.d.ts +3 -0
- package/dist/client/filter/FilterBlockProvider.d.ts +2 -0
- package/dist/client/filter/FilterCheckbox.d.ts +2 -0
- package/dist/client/filter/FilterForm.d.ts +2 -0
- package/dist/client/filter/FilterItemDesigner.d.ts +2 -0
- package/dist/client/filter/FilterItemInitializers.d.ts +7 -0
- package/dist/client/filter/FilterProvider.d.ts +30 -0
- package/dist/client/filter/FilterVariableInput.d.ts +2 -0
- package/dist/client/filter/index.d.ts +6 -0
- package/dist/client/filter/utils.d.ts +59 -0
- package/dist/client/hooks/filter.d.ts +225 -0
- package/dist/client/hooks/index.d.ts +4 -0
- package/dist/client/hooks/query.d.ts +52 -0
- package/dist/client/hooks/transformer.d.ts +12 -0
- package/dist/client/hooks/useDateVariable.d.ts +14 -0
- package/dist/client/hooks/useUserVariable.d.ts +8 -0
- package/dist/client/hooks/useVariableOptions.d.ts +10 -0
- package/dist/client/index.d.ts +13 -0
- package/dist/client/index.js +234 -0
- package/dist/client/locale/index.d.ts +3 -0
- package/dist/client/renderer/ChartRenderer.d.ts +4 -0
- package/dist/client/renderer/ChartRendererProvider.d.ts +49 -0
- package/dist/client/renderer/index.d.ts +2 -0
- package/dist/client/utils.d.ts +44 -0
- package/dist/externalVersion.js +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +89 -0
- package/dist/locale/ko_KR.json +85 -0
- package/dist/locale/zh-CN.json +90 -0
- package/dist/node_modules/fs-extra/LICENSE +15 -0
- package/dist/node_modules/fs-extra/lib/copy/copy-sync.js +161 -0
- package/dist/node_modules/fs-extra/lib/copy/copy.js +177 -0
- package/dist/node_modules/fs-extra/lib/copy/index.js +7 -0
- package/dist/node_modules/fs-extra/lib/empty/index.js +39 -0
- package/dist/node_modules/fs-extra/lib/ensure/file.js +66 -0
- package/dist/node_modules/fs-extra/lib/ensure/index.js +23 -0
- package/dist/node_modules/fs-extra/lib/ensure/link.js +64 -0
- package/dist/node_modules/fs-extra/lib/ensure/symlink-paths.js +101 -0
- package/dist/node_modules/fs-extra/lib/ensure/symlink-type.js +34 -0
- package/dist/node_modules/fs-extra/lib/ensure/symlink.js +67 -0
- package/dist/node_modules/fs-extra/lib/fs/index.js +140 -0
- package/dist/node_modules/fs-extra/lib/index.js +1 -0
- package/dist/node_modules/fs-extra/lib/json/index.js +16 -0
- package/dist/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
- package/dist/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
- package/dist/node_modules/fs-extra/lib/json/output-json.js +12 -0
- package/dist/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
- package/dist/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
- package/dist/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
- package/dist/node_modules/fs-extra/lib/move/index.js +7 -0
- package/dist/node_modules/fs-extra/lib/move/move-sync.js +55 -0
- package/dist/node_modules/fs-extra/lib/move/move.js +59 -0
- package/dist/node_modules/fs-extra/lib/output-file/index.js +31 -0
- package/dist/node_modules/fs-extra/lib/path-exists/index.js +12 -0
- package/dist/node_modules/fs-extra/lib/remove/index.js +17 -0
- package/dist/node_modules/fs-extra/lib/util/stat.js +158 -0
- package/dist/node_modules/fs-extra/lib/util/utimes.js +36 -0
- package/dist/node_modules/fs-extra/package.json +1 -0
- package/dist/node_modules/koa-compose/index.js +1 -0
- package/dist/node_modules/koa-compose/package.json +1 -0
- package/dist/server/actions/formatter.d.ts +4 -0
- package/dist/server/actions/formatter.js +67 -0
- package/dist/server/actions/query.d.ts +8 -0
- package/dist/server/actions/query.js +320 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/migrations/20230926211750-rename-charttype.d.ts +5 -0
- package/dist/server/migrations/20230926211750-rename-charttype.js +51 -0
- package/dist/server/plugin.d.ts +13 -0
- package/dist/server/plugin.js +83 -0
- package/dist/server/services/sql-loader.d.ts +10 -0
- package/dist/server/services/sql-loader.js +134 -0
- package/dist/server/sqls/view_load_function.sql +17 -0
- package/dist/server/utils/multiprocess.d.ts +2 -0
- package/dist/server/utils/multiprocess.js +38 -0
- package/dist/swagger/index.d.ts +8 -0
- package/dist/swagger/index.js +29 -0
- package/package.json +44 -0
- package/server.d.ts +3 -0
- package/server.js +65 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('../fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const { mkdirs } = require('../mkdirs')
|
|
6
|
+
const { pathExists } = require('../path-exists')
|
|
7
|
+
const { utimesMillis } = require('../util/utimes')
|
|
8
|
+
const stat = require('../util/stat')
|
|
9
|
+
|
|
10
|
+
async function copy (src, dest, opts = {}) {
|
|
11
|
+
if (typeof opts === 'function') {
|
|
12
|
+
opts = { filter: opts }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
|
|
16
|
+
opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
|
|
17
|
+
|
|
18
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
19
|
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
|
20
|
+
process.emitWarning(
|
|
21
|
+
'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
|
|
22
|
+
'\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
|
|
23
|
+
'Warning', 'fs-extra-WARN0001'
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { srcStat, destStat } = await stat.checkPaths(src, dest, 'copy', opts)
|
|
28
|
+
|
|
29
|
+
await stat.checkParentPaths(src, srcStat, dest, 'copy')
|
|
30
|
+
|
|
31
|
+
const include = await runFilter(src, dest, opts)
|
|
32
|
+
|
|
33
|
+
if (!include) return
|
|
34
|
+
|
|
35
|
+
// check if the parent of dest exists, and create it if it doesn't exist
|
|
36
|
+
const destParent = path.dirname(dest)
|
|
37
|
+
const dirExists = await pathExists(destParent)
|
|
38
|
+
if (!dirExists) {
|
|
39
|
+
await mkdirs(destParent)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await getStatsAndPerformCopy(destStat, src, dest, opts)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function runFilter (src, dest, opts) {
|
|
46
|
+
if (!opts.filter) return true
|
|
47
|
+
return opts.filter(src, dest)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function getStatsAndPerformCopy (destStat, src, dest, opts) {
|
|
51
|
+
const statFn = opts.dereference ? fs.stat : fs.lstat
|
|
52
|
+
const srcStat = await statFn(src)
|
|
53
|
+
|
|
54
|
+
if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
srcStat.isFile() ||
|
|
58
|
+
srcStat.isCharacterDevice() ||
|
|
59
|
+
srcStat.isBlockDevice()
|
|
60
|
+
) return onFile(srcStat, destStat, src, dest, opts)
|
|
61
|
+
|
|
62
|
+
if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
|
|
63
|
+
if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
|
|
64
|
+
if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
|
|
65
|
+
throw new Error(`Unknown file: ${src}`)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function onFile (srcStat, destStat, src, dest, opts) {
|
|
69
|
+
if (!destStat) return copyFile(srcStat, src, dest, opts)
|
|
70
|
+
|
|
71
|
+
if (opts.overwrite) {
|
|
72
|
+
await fs.unlink(dest)
|
|
73
|
+
return copyFile(srcStat, src, dest, opts)
|
|
74
|
+
}
|
|
75
|
+
if (opts.errorOnExist) {
|
|
76
|
+
throw new Error(`'${dest}' already exists`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function copyFile (srcStat, src, dest, opts) {
|
|
81
|
+
await fs.copyFile(src, dest)
|
|
82
|
+
if (opts.preserveTimestamps) {
|
|
83
|
+
// Make sure the file is writable before setting the timestamp
|
|
84
|
+
// otherwise open fails with EPERM when invoked with 'r+'
|
|
85
|
+
// (through utimes call)
|
|
86
|
+
if (fileIsNotWritable(srcStat.mode)) {
|
|
87
|
+
await makeFileWritable(dest, srcStat.mode)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Set timestamps and mode correspondingly
|
|
91
|
+
|
|
92
|
+
// Note that The initial srcStat.atime cannot be trusted
|
|
93
|
+
// because it is modified by the read(2) system call
|
|
94
|
+
// (See https://nodejs.org/api/fs.html#fs_stat_time_values)
|
|
95
|
+
const updatedSrcStat = await fs.stat(src)
|
|
96
|
+
await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return fs.chmod(dest, srcStat.mode)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function fileIsNotWritable (srcMode) {
|
|
103
|
+
return (srcMode & 0o200) === 0
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function makeFileWritable (dest, srcMode) {
|
|
107
|
+
return fs.chmod(dest, srcMode | 0o200)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function onDir (srcStat, destStat, src, dest, opts) {
|
|
111
|
+
// the dest directory might not exist, create it
|
|
112
|
+
if (!destStat) {
|
|
113
|
+
await fs.mkdir(dest)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const items = await fs.readdir(src)
|
|
117
|
+
|
|
118
|
+
// loop through the files in the current directory to copy everything
|
|
119
|
+
await Promise.all(items.map(async item => {
|
|
120
|
+
const srcItem = path.join(src, item)
|
|
121
|
+
const destItem = path.join(dest, item)
|
|
122
|
+
|
|
123
|
+
// skip the item if it is matches by the filter function
|
|
124
|
+
const include = await runFilter(srcItem, destItem, opts)
|
|
125
|
+
if (!include) return
|
|
126
|
+
|
|
127
|
+
const { destStat } = await stat.checkPaths(srcItem, destItem, 'copy', opts)
|
|
128
|
+
|
|
129
|
+
// If the item is a copyable file, `getStatsAndPerformCopy` will copy it
|
|
130
|
+
// If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
|
|
131
|
+
return getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
|
|
132
|
+
}))
|
|
133
|
+
|
|
134
|
+
if (!destStat) {
|
|
135
|
+
await fs.chmod(dest, srcStat.mode)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function onLink (destStat, src, dest, opts) {
|
|
140
|
+
let resolvedSrc = await fs.readlink(src)
|
|
141
|
+
if (opts.dereference) {
|
|
142
|
+
resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
|
|
143
|
+
}
|
|
144
|
+
if (!destStat) {
|
|
145
|
+
return fs.symlink(resolvedSrc, dest)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let resolvedDest = null
|
|
149
|
+
try {
|
|
150
|
+
resolvedDest = await fs.readlink(dest)
|
|
151
|
+
} catch (e) {
|
|
152
|
+
// dest exists and is a regular file or directory,
|
|
153
|
+
// Windows may throw UNKNOWN error. If dest already exists,
|
|
154
|
+
// fs throws error anyway, so no need to guard against it here.
|
|
155
|
+
if (e.code === 'EINVAL' || e.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest)
|
|
156
|
+
throw e
|
|
157
|
+
}
|
|
158
|
+
if (opts.dereference) {
|
|
159
|
+
resolvedDest = path.resolve(process.cwd(), resolvedDest)
|
|
160
|
+
}
|
|
161
|
+
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
162
|
+
throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// do not copy if src is a subdir of dest since unlinking
|
|
166
|
+
// dest in this case would result in removing src contents
|
|
167
|
+
// and therefore a broken symlink would be created.
|
|
168
|
+
if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
169
|
+
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// copy the link
|
|
173
|
+
await fs.unlink(dest)
|
|
174
|
+
return fs.symlink(resolvedSrc, dest)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
module.exports = copy
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromPromise
|
|
4
|
+
const fs = require('../fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const mkdir = require('../mkdirs')
|
|
7
|
+
const remove = require('../remove')
|
|
8
|
+
|
|
9
|
+
const emptyDir = u(async function emptyDir (dir) {
|
|
10
|
+
let items
|
|
11
|
+
try {
|
|
12
|
+
items = await fs.readdir(dir)
|
|
13
|
+
} catch {
|
|
14
|
+
return mkdir.mkdirs(dir)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Promise.all(items.map(item => remove.remove(path.join(dir, item))))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
function emptyDirSync (dir) {
|
|
21
|
+
let items
|
|
22
|
+
try {
|
|
23
|
+
items = fs.readdirSync(dir)
|
|
24
|
+
} catch {
|
|
25
|
+
return mkdir.mkdirsSync(dir)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
items.forEach(item => {
|
|
29
|
+
item = path.join(dir, item)
|
|
30
|
+
remove.removeSync(item)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
emptyDirSync,
|
|
36
|
+
emptydirSync: emptyDirSync,
|
|
37
|
+
emptyDir,
|
|
38
|
+
emptydir: emptyDir
|
|
39
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromPromise
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('../fs')
|
|
6
|
+
const mkdir = require('../mkdirs')
|
|
7
|
+
|
|
8
|
+
async function createFile (file) {
|
|
9
|
+
let stats
|
|
10
|
+
try {
|
|
11
|
+
stats = await fs.stat(file)
|
|
12
|
+
} catch { }
|
|
13
|
+
if (stats && stats.isFile()) return
|
|
14
|
+
|
|
15
|
+
const dir = path.dirname(file)
|
|
16
|
+
|
|
17
|
+
let dirStats = null
|
|
18
|
+
try {
|
|
19
|
+
dirStats = await fs.stat(dir)
|
|
20
|
+
} catch (err) {
|
|
21
|
+
// if the directory doesn't exist, make it
|
|
22
|
+
if (err.code === 'ENOENT') {
|
|
23
|
+
await mkdir.mkdirs(dir)
|
|
24
|
+
await fs.writeFile(file, '')
|
|
25
|
+
return
|
|
26
|
+
} else {
|
|
27
|
+
throw err
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (dirStats.isDirectory()) {
|
|
32
|
+
await fs.writeFile(file, '')
|
|
33
|
+
} else {
|
|
34
|
+
// parent is not a directory
|
|
35
|
+
// This is just to cause an internal ENOTDIR error to be thrown
|
|
36
|
+
await fs.readdir(dir)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createFileSync (file) {
|
|
41
|
+
let stats
|
|
42
|
+
try {
|
|
43
|
+
stats = fs.statSync(file)
|
|
44
|
+
} catch { }
|
|
45
|
+
if (stats && stats.isFile()) return
|
|
46
|
+
|
|
47
|
+
const dir = path.dirname(file)
|
|
48
|
+
try {
|
|
49
|
+
if (!fs.statSync(dir).isDirectory()) {
|
|
50
|
+
// parent is not a directory
|
|
51
|
+
// This is just to cause an internal ENOTDIR error to be thrown
|
|
52
|
+
fs.readdirSync(dir)
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// If the stat call above failed because the directory doesn't exist, create it
|
|
56
|
+
if (err && err.code === 'ENOENT') mkdir.mkdirsSync(dir)
|
|
57
|
+
else throw err
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fs.writeFileSync(file, '')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
createFile: u(createFile),
|
|
65
|
+
createFileSync
|
|
66
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { createFile, createFileSync } = require('./file')
|
|
4
|
+
const { createLink, createLinkSync } = require('./link')
|
|
5
|
+
const { createSymlink, createSymlinkSync } = require('./symlink')
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
// file
|
|
9
|
+
createFile,
|
|
10
|
+
createFileSync,
|
|
11
|
+
ensureFile: createFile,
|
|
12
|
+
ensureFileSync: createFileSync,
|
|
13
|
+
// link
|
|
14
|
+
createLink,
|
|
15
|
+
createLinkSync,
|
|
16
|
+
ensureLink: createLink,
|
|
17
|
+
ensureLinkSync: createLinkSync,
|
|
18
|
+
// symlink
|
|
19
|
+
createSymlink,
|
|
20
|
+
createSymlinkSync,
|
|
21
|
+
ensureSymlink: createSymlink,
|
|
22
|
+
ensureSymlinkSync: createSymlinkSync
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromPromise
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('../fs')
|
|
6
|
+
const mkdir = require('../mkdirs')
|
|
7
|
+
const { pathExists } = require('../path-exists')
|
|
8
|
+
const { areIdentical } = require('../util/stat')
|
|
9
|
+
|
|
10
|
+
async function createLink (srcpath, dstpath) {
|
|
11
|
+
let dstStat
|
|
12
|
+
try {
|
|
13
|
+
dstStat = await fs.lstat(dstpath)
|
|
14
|
+
} catch {
|
|
15
|
+
// ignore error
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let srcStat
|
|
19
|
+
try {
|
|
20
|
+
srcStat = await fs.lstat(srcpath)
|
|
21
|
+
} catch (err) {
|
|
22
|
+
err.message = err.message.replace('lstat', 'ensureLink')
|
|
23
|
+
throw err
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (dstStat && areIdentical(srcStat, dstStat)) return
|
|
27
|
+
|
|
28
|
+
const dir = path.dirname(dstpath)
|
|
29
|
+
|
|
30
|
+
const dirExists = await pathExists(dir)
|
|
31
|
+
|
|
32
|
+
if (!dirExists) {
|
|
33
|
+
await mkdir.mkdirs(dir)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await fs.link(srcpath, dstpath)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createLinkSync (srcpath, dstpath) {
|
|
40
|
+
let dstStat
|
|
41
|
+
try {
|
|
42
|
+
dstStat = fs.lstatSync(dstpath)
|
|
43
|
+
} catch {}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const srcStat = fs.lstatSync(srcpath)
|
|
47
|
+
if (dstStat && areIdentical(srcStat, dstStat)) return
|
|
48
|
+
} catch (err) {
|
|
49
|
+
err.message = err.message.replace('lstat', 'ensureLink')
|
|
50
|
+
throw err
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const dir = path.dirname(dstpath)
|
|
54
|
+
const dirExists = fs.existsSync(dir)
|
|
55
|
+
if (dirExists) return fs.linkSync(srcpath, dstpath)
|
|
56
|
+
mkdir.mkdirsSync(dir)
|
|
57
|
+
|
|
58
|
+
return fs.linkSync(srcpath, dstpath)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
createLink: u(createLink),
|
|
63
|
+
createLinkSync
|
|
64
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const fs = require('../fs')
|
|
5
|
+
const { pathExists } = require('../path-exists')
|
|
6
|
+
|
|
7
|
+
const u = require('universalify').fromPromise
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Function that returns two types of paths, one relative to symlink, and one
|
|
11
|
+
* relative to the current working directory. Checks if path is absolute or
|
|
12
|
+
* relative. If the path is relative, this function checks if the path is
|
|
13
|
+
* relative to symlink or relative to current working directory. This is an
|
|
14
|
+
* initiative to find a smarter `srcpath` to supply when building symlinks.
|
|
15
|
+
* This allows you to determine which path to use out of one of three possible
|
|
16
|
+
* types of source paths. The first is an absolute path. This is detected by
|
|
17
|
+
* `path.isAbsolute()`. When an absolute path is provided, it is checked to
|
|
18
|
+
* see if it exists. If it does it's used, if not an error is returned
|
|
19
|
+
* (callback)/ thrown (sync). The other two options for `srcpath` are a
|
|
20
|
+
* relative url. By default Node's `fs.symlink` works by creating a symlink
|
|
21
|
+
* using `dstpath` and expects the `srcpath` to be relative to the newly
|
|
22
|
+
* created symlink. If you provide a `srcpath` that does not exist on the file
|
|
23
|
+
* system it results in a broken symlink. To minimize this, the function
|
|
24
|
+
* checks to see if the 'relative to symlink' source file exists, and if it
|
|
25
|
+
* does it will use it. If it does not, it checks if there's a file that
|
|
26
|
+
* exists that is relative to the current working directory, if does its used.
|
|
27
|
+
* This preserves the expectations of the original fs.symlink spec and adds
|
|
28
|
+
* the ability to pass in `relative to current working direcotry` paths.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
async function symlinkPaths (srcpath, dstpath) {
|
|
32
|
+
if (path.isAbsolute(srcpath)) {
|
|
33
|
+
try {
|
|
34
|
+
await fs.lstat(srcpath)
|
|
35
|
+
} catch (err) {
|
|
36
|
+
err.message = err.message.replace('lstat', 'ensureSymlink')
|
|
37
|
+
throw err
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
toCwd: srcpath,
|
|
42
|
+
toDst: srcpath
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const dstdir = path.dirname(dstpath)
|
|
47
|
+
const relativeToDst = path.join(dstdir, srcpath)
|
|
48
|
+
|
|
49
|
+
const exists = await pathExists(relativeToDst)
|
|
50
|
+
if (exists) {
|
|
51
|
+
return {
|
|
52
|
+
toCwd: relativeToDst,
|
|
53
|
+
toDst: srcpath
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await fs.lstat(srcpath)
|
|
59
|
+
} catch (err) {
|
|
60
|
+
err.message = err.message.replace('lstat', 'ensureSymlink')
|
|
61
|
+
throw err
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
toCwd: srcpath,
|
|
66
|
+
toDst: path.relative(dstdir, srcpath)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function symlinkPathsSync (srcpath, dstpath) {
|
|
71
|
+
if (path.isAbsolute(srcpath)) {
|
|
72
|
+
const exists = fs.existsSync(srcpath)
|
|
73
|
+
if (!exists) throw new Error('absolute srcpath does not exist')
|
|
74
|
+
return {
|
|
75
|
+
toCwd: srcpath,
|
|
76
|
+
toDst: srcpath
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const dstdir = path.dirname(dstpath)
|
|
81
|
+
const relativeToDst = path.join(dstdir, srcpath)
|
|
82
|
+
const exists = fs.existsSync(relativeToDst)
|
|
83
|
+
if (exists) {
|
|
84
|
+
return {
|
|
85
|
+
toCwd: relativeToDst,
|
|
86
|
+
toDst: srcpath
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const srcExists = fs.existsSync(srcpath)
|
|
91
|
+
if (!srcExists) throw new Error('relative srcpath does not exist')
|
|
92
|
+
return {
|
|
93
|
+
toCwd: srcpath,
|
|
94
|
+
toDst: path.relative(dstdir, srcpath)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
symlinkPaths: u(symlinkPaths),
|
|
100
|
+
symlinkPathsSync
|
|
101
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('../fs')
|
|
4
|
+
const u = require('universalify').fromPromise
|
|
5
|
+
|
|
6
|
+
async function symlinkType (srcpath, type) {
|
|
7
|
+
if (type) return type
|
|
8
|
+
|
|
9
|
+
let stats
|
|
10
|
+
try {
|
|
11
|
+
stats = await fs.lstat(srcpath)
|
|
12
|
+
} catch {
|
|
13
|
+
return 'file'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (stats && stats.isDirectory()) ? 'dir' : 'file'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function symlinkTypeSync (srcpath, type) {
|
|
20
|
+
if (type) return type
|
|
21
|
+
|
|
22
|
+
let stats
|
|
23
|
+
try {
|
|
24
|
+
stats = fs.lstatSync(srcpath)
|
|
25
|
+
} catch {
|
|
26
|
+
return 'file'
|
|
27
|
+
}
|
|
28
|
+
return (stats && stats.isDirectory()) ? 'dir' : 'file'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
symlinkType: u(symlinkType),
|
|
33
|
+
symlinkTypeSync
|
|
34
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const u = require('universalify').fromPromise
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('../fs')
|
|
6
|
+
|
|
7
|
+
const { mkdirs, mkdirsSync } = require('../mkdirs')
|
|
8
|
+
|
|
9
|
+
const { symlinkPaths, symlinkPathsSync } = require('./symlink-paths')
|
|
10
|
+
const { symlinkType, symlinkTypeSync } = require('./symlink-type')
|
|
11
|
+
|
|
12
|
+
const { pathExists } = require('../path-exists')
|
|
13
|
+
|
|
14
|
+
const { areIdentical } = require('../util/stat')
|
|
15
|
+
|
|
16
|
+
async function createSymlink (srcpath, dstpath, type) {
|
|
17
|
+
let stats
|
|
18
|
+
try {
|
|
19
|
+
stats = await fs.lstat(dstpath)
|
|
20
|
+
} catch { }
|
|
21
|
+
|
|
22
|
+
if (stats && stats.isSymbolicLink()) {
|
|
23
|
+
const [srcStat, dstStat] = await Promise.all([
|
|
24
|
+
fs.stat(srcpath),
|
|
25
|
+
fs.stat(dstpath)
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
if (areIdentical(srcStat, dstStat)) return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const relative = await symlinkPaths(srcpath, dstpath)
|
|
32
|
+
srcpath = relative.toDst
|
|
33
|
+
const toType = await symlinkType(relative.toCwd, type)
|
|
34
|
+
const dir = path.dirname(dstpath)
|
|
35
|
+
|
|
36
|
+
if (!(await pathExists(dir))) {
|
|
37
|
+
await mkdirs(dir)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return fs.symlink(srcpath, dstpath, toType)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createSymlinkSync (srcpath, dstpath, type) {
|
|
44
|
+
let stats
|
|
45
|
+
try {
|
|
46
|
+
stats = fs.lstatSync(dstpath)
|
|
47
|
+
} catch { }
|
|
48
|
+
if (stats && stats.isSymbolicLink()) {
|
|
49
|
+
const srcStat = fs.statSync(srcpath)
|
|
50
|
+
const dstStat = fs.statSync(dstpath)
|
|
51
|
+
if (areIdentical(srcStat, dstStat)) return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const relative = symlinkPathsSync(srcpath, dstpath)
|
|
55
|
+
srcpath = relative.toDst
|
|
56
|
+
type = symlinkTypeSync(relative.toCwd, type)
|
|
57
|
+
const dir = path.dirname(dstpath)
|
|
58
|
+
const exists = fs.existsSync(dir)
|
|
59
|
+
if (exists) return fs.symlinkSync(srcpath, dstpath, type)
|
|
60
|
+
mkdirsSync(dir)
|
|
61
|
+
return fs.symlinkSync(srcpath, dstpath, type)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
createSymlink: u(createSymlink),
|
|
66
|
+
createSymlinkSync
|
|
67
|
+
}
|