1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const AbstractScriptedFlushable_1 = require("../../internal/common/AbstractScriptedFlushable");
|
12 | const logger_1 = require("../../util/logger");
|
13 | const fileGlobs_1 = require("../fileGlobs");
|
14 |
|
15 |
|
16 |
|
17 | class AbstractProject extends AbstractScriptedFlushable_1.AbstractScriptedFlushable {
|
18 | constructor(id) {
|
19 | super();
|
20 | this.id = id;
|
21 | }
|
22 | get name() {
|
23 | return !!this.id ? this.id.repo : undefined;
|
24 | }
|
25 | hasFile(path) {
|
26 | return __awaiter(this, void 0, void 0, function* () {
|
27 | return !!(yield this.getFile(path));
|
28 | });
|
29 | }
|
30 | streamFiles(...globPatterns) {
|
31 | const globsToUse = globPatterns.length > 0 ? globPatterns.concat(fileGlobs_1.DefaultExcludes) : fileGlobs_1.DefaultFiles;
|
32 | return this.streamFilesRaw(globsToUse, {});
|
33 | }
|
34 | totalFileCount() {
|
35 | return new Promise((resolve, reject) => {
|
36 | let count = 0;
|
37 | this.streamFiles()
|
38 | .on("data", f => count++)
|
39 | .on("error", reject)
|
40 | .on("end", _ => resolve(count));
|
41 | });
|
42 | }
|
43 | trackFile(f) {
|
44 | logger_1.logger.debug(`Project is tracking '${f.path}'`);
|
45 | return this.recordAction(p => {
|
46 | return f.flush().then(_ => p);
|
47 | });
|
48 | }
|
49 | moveFile(oldPath, newPath) {
|
50 | return this.findFile(oldPath)
|
51 | .then(f => f.setPath(newPath).then(() => this))
|
52 |
|
53 | .catch(err => this);
|
54 | }
|
55 | recordAddFile(path, content) {
|
56 | return this.recordAction(p => p.addFile(path, content));
|
57 | }
|
58 | recordDeleteFile(path) {
|
59 | return this.recordAction(p => p.deleteFile(path));
|
60 | }
|
61 |
|
62 | add(f) {
|
63 | return f.getContent()
|
64 | .then(content => this.addFile(f.path, content));
|
65 | }
|
66 | }
|
67 | exports.AbstractProject = AbstractProject;
|
68 |
|
\ | No newline at end of file |