@datatruck/cli 0.11.2 → 0.11.5
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/Repository/GitRepository.js +1 -1
- package/Repository/LocalRepository.js +1 -1
- package/Repository/ResticRepository.js +16 -2
- package/cli.js +2 -3
- package/package.json +1 -1
- package/util/datatruck/config-util.js +1 -1
- package/util/fs-util.d.ts +4 -0
- package/util/fs-util.js +10 -1
- package/util/string-util.d.ts +1 -0
- package/util/string-util.js +16 -2
|
@@ -124,7 +124,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
124
124
|
return result;
|
|
125
125
|
if (pkgPatterns && !(0, micromatch_1.isMatch)(parsedTag.package, pkgPatterns))
|
|
126
126
|
return result;
|
|
127
|
-
if (pkgTaskPatterns && !(0,
|
|
127
|
+
if (pkgTaskPatterns && !(0, string_util_1.checkMatch)(parsedTag.task, pkgTaskPatterns))
|
|
128
128
|
return result;
|
|
129
129
|
if (data.options.tags &&
|
|
130
130
|
!parsedTag.tags.some((value) => data.options.tags?.includes(value)))
|
|
@@ -138,7 +138,7 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
138
138
|
continue;
|
|
139
139
|
const metaPath = (0, path_1.join)(this.config.outPath, snapshotName);
|
|
140
140
|
const meta = await LocalRepository.parseMetaData(metaPath);
|
|
141
|
-
if (taskPatterns && !(0,
|
|
141
|
+
if (taskPatterns && !(0, string_util_1.checkMatch)(meta.task, taskPatterns))
|
|
142
142
|
continue;
|
|
143
143
|
if (data.options.ids &&
|
|
144
144
|
!data.options.ids.some((id) => meta.id.startsWith(id)))
|
|
@@ -13,6 +13,7 @@ const string_util_1 = require("../util/string-util");
|
|
|
13
13
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
14
14
|
const assert_1 = require("assert");
|
|
15
15
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
16
|
+
const promises_1 = require("fs/promises");
|
|
16
17
|
const micromatch_1 = require("micromatch");
|
|
17
18
|
const path_1 = require("path");
|
|
18
19
|
exports.resticRepositoryName = "restic";
|
|
@@ -139,7 +140,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
139
140
|
return items;
|
|
140
141
|
if (packagePatterns && !(0, micromatch_1.isMatch)(tag.package, packagePatterns))
|
|
141
142
|
return items;
|
|
142
|
-
if (taskNamePatterns && !(0,
|
|
143
|
+
if (taskNamePatterns && !(0, string_util_1.checkMatch)(tag.task, taskNamePatterns))
|
|
143
144
|
return items;
|
|
144
145
|
const itemTags = tag.tags ?? [];
|
|
145
146
|
if (data.options.tags && !itemTags.some((t) => itemTags.includes(t)))
|
|
@@ -174,7 +175,20 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
174
175
|
const sourcePath = data.targetPath ?? data.package.path;
|
|
175
176
|
(0, assert_1.ok)(sourcePath);
|
|
176
177
|
let gitignorePath;
|
|
177
|
-
if (pkg.include
|
|
178
|
+
if (!pkg.include && pkg.exclude) {
|
|
179
|
+
const exclude = await (0, paths_util_1.parsePaths)(pkg.exclude, {
|
|
180
|
+
cwd: sourcePath,
|
|
181
|
+
verbose: data.options.verbose,
|
|
182
|
+
});
|
|
183
|
+
await data.onProgress({
|
|
184
|
+
step: "Writing excluded paths list...",
|
|
185
|
+
});
|
|
186
|
+
const tmpDir = await (0, fs_util_1.mkTmpDir)("restic-exclude");
|
|
187
|
+
const ignoredContents = (0, fs_util_1.fastglobToGitIgnore)(exclude).join("\n");
|
|
188
|
+
gitignorePath = (0, path_1.join)(tmpDir, "ignored.txt");
|
|
189
|
+
await (0, promises_1.writeFile)(gitignorePath, ignoredContents);
|
|
190
|
+
}
|
|
191
|
+
else if (pkg.include || pkg.exclude) {
|
|
178
192
|
const include = await (0, paths_util_1.parsePaths)(pkg.include ?? ["**"], {
|
|
179
193
|
cwd: sourcePath,
|
|
180
194
|
verbose: data.options.verbose,
|
package/cli.js
CHANGED
|
@@ -72,10 +72,9 @@ function makeCommandAction(command) {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
const program = new commander_1.Command();
|
|
75
|
-
const {
|
|
76
|
-
const [, subname] = name.split("/");
|
|
75
|
+
const { version, description } = (0, fs_util_1.parsePackageFile)();
|
|
77
76
|
const cwd = process.cwd();
|
|
78
|
-
program.name(
|
|
77
|
+
program.name("datatruck");
|
|
79
78
|
program.version(version);
|
|
80
79
|
program.description(description);
|
|
81
80
|
program.usage("dtt");
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@ function filterPackages(config, options) {
|
|
|
38
38
|
return pkg;
|
|
39
39
|
})
|
|
40
40
|
.filter((pkg) => {
|
|
41
|
-
if (taskNamePatterns && !(0,
|
|
41
|
+
if (taskNamePatterns && !(0, string_util_1.checkMatch)(pkg.task?.name, taskNamePatterns))
|
|
42
42
|
return false;
|
|
43
43
|
return ((typeof pkg.enabled !== "boolean" || pkg.enabled) &&
|
|
44
44
|
!!pkg.repositoryNames?.length &&
|
package/util/fs-util.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare function checkFile(path: string): Promise<boolean>;
|
|
|
29
29
|
export declare function checkDir(path: string): Promise<boolean>;
|
|
30
30
|
export declare function readDir(path: string): Promise<string[]>;
|
|
31
31
|
export declare function forEachFile(dirPath: string, cb: (path: string, dir: boolean) => void, includeDir?: boolean): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
export declare function fastglobToGitIgnore(patterns: string[]): string[];
|
|
32
36
|
export declare function writeGitIgnoreList(options: {
|
|
33
37
|
paths: NodeJS.ReadableStream | string[];
|
|
34
38
|
}): Promise<string>;
|
package/util/fs-util.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.cpy = exports.updateFileStats = exports.copyFileWithStreams = exports.writePathLists = exports.writeGitIgnoreList = exports.forEachFile = exports.readDir = exports.checkDir = exports.checkFile = exports.readPartialFile = exports.mkTmpDir = exports.tmpDir = exports.sessionTmpDir = exports.parentTmpDir = exports.existsFile = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.parseFileExtensions = exports.readdirIfExists = exports.writeJSONFile = exports.existsDir = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isDirEmpty = exports.isLocalDir = exports.isWSLSystem = void 0;
|
|
6
|
+
exports.cpy = exports.updateFileStats = exports.copyFileWithStreams = exports.writePathLists = exports.writeGitIgnoreList = exports.fastglobToGitIgnore = exports.forEachFile = exports.readDir = exports.checkDir = exports.checkFile = exports.readPartialFile = exports.mkTmpDir = exports.tmpDir = exports.sessionTmpDir = exports.parentTmpDir = exports.existsFile = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.parseFileExtensions = exports.readdirIfExists = exports.writeJSONFile = exports.existsDir = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isDirEmpty = exports.isLocalDir = exports.isWSLSystem = void 0;
|
|
7
7
|
const globalData_1 = __importDefault(require("../globalData"));
|
|
8
8
|
const path_util_1 = require("./path-util");
|
|
9
9
|
const async_1 = require("async");
|
|
@@ -213,6 +213,15 @@ async function forEachFile(dirPath, cb, includeDir) {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
exports.forEachFile = forEachFile;
|
|
216
|
+
/**
|
|
217
|
+
* @experimental
|
|
218
|
+
*/
|
|
219
|
+
function fastglobToGitIgnore(patterns) {
|
|
220
|
+
// https://github.com/mrmlnc/fast-glob#readme
|
|
221
|
+
// https://git-scm.com/docs/gitignore
|
|
222
|
+
return patterns.map((p) => (p.startsWith("/") ? p : `/${p}`));
|
|
223
|
+
}
|
|
224
|
+
exports.fastglobToGitIgnore = fastglobToGitIgnore;
|
|
216
225
|
async function writeGitIgnoreList(options) {
|
|
217
226
|
const tempDir = await mkTmpDir("gitignore-list");
|
|
218
227
|
const path = (0, path_1.join)(tempDir, `.gitignore`);
|
package/util/string-util.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export declare type UriType = {
|
|
|
15
15
|
export declare function formatUri(input: UriType, hidePassword?: boolean): string;
|
|
16
16
|
export declare function formatSeconds(seconds: number): string;
|
|
17
17
|
export declare function makePathPatterns(values: string[] | undefined): string[] | undefined;
|
|
18
|
+
export declare function checkMatch(subject: string | undefined, patterns: string[]): boolean;
|
|
18
19
|
export declare function formatDateTime(datetime: string): string;
|
package/util/string-util.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatDateTime = exports.makePathPatterns = exports.formatSeconds = exports.formatUri = exports.parseStringList = exports.render = exports.snakeCase = exports.lcfirst = exports.ucfirst = exports.serialize = void 0;
|
|
3
|
+
exports.formatDateTime = exports.checkMatch = exports.makePathPatterns = exports.formatSeconds = exports.formatUri = exports.parseStringList = exports.render = exports.snakeCase = exports.lcfirst = exports.ucfirst = exports.serialize = void 0;
|
|
4
4
|
const AppError_1 = require("../Error/AppError");
|
|
5
|
+
const micromatch_1 = require("micromatch");
|
|
5
6
|
function serialize(message, data) {
|
|
6
7
|
if (data)
|
|
7
8
|
return `${message} (${JSON.stringify(data, null, 2)})`;
|
|
@@ -88,9 +89,22 @@ function formatSeconds(seconds) {
|
|
|
88
89
|
}
|
|
89
90
|
exports.formatSeconds = formatSeconds;
|
|
90
91
|
function makePathPatterns(values) {
|
|
91
|
-
return values?.flatMap((v) =>
|
|
92
|
+
return values?.flatMap((v) => {
|
|
93
|
+
if (v === "*" || v === "**" || v === "<empty>" || v === "!<empty>") {
|
|
94
|
+
return [v];
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return [v, `${v}/**`];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
92
100
|
}
|
|
93
101
|
exports.makePathPatterns = makePathPatterns;
|
|
102
|
+
function checkMatch(subject, patterns) {
|
|
103
|
+
if (!subject?.length)
|
|
104
|
+
subject = "<empty>";
|
|
105
|
+
return (0, micromatch_1.isMatch)(subject, patterns);
|
|
106
|
+
}
|
|
107
|
+
exports.checkMatch = checkMatch;
|
|
94
108
|
function formatDateTime(datetime) {
|
|
95
109
|
const date = new Date(datetime);
|
|
96
110
|
const [result] = new Date(date.getTime() - date.getTimezoneOffset() * 60000)
|