@wireapp/copy-config 2.3.4 → 2.3.9-beta.54.5ce5ca523

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/package.json CHANGED
@@ -34,6 +34,6 @@
34
34
  "test": "jest",
35
35
  "test:coverage": "jest --coverage"
36
36
  },
37
- "version": "2.3.4",
38
- "gitHead": "0d407542b36f5092749216ded20daf5a7ad18acd"
37
+ "version": "2.3.9-beta.54.5ce5ca523",
38
+ "gitHead": "5ce5ca523eecbb1d0bb2216f8542d8dcd1cec325"
39
39
  }
@@ -1,18 +0,0 @@
1
- import logdown from 'logdown';
2
- import { CopyConfigOptions } from './CopyConfigOptions';
3
- export declare class CopyConfig {
4
- private readonly logger?;
5
- private readonly options;
6
- private readonly noClone;
7
- private readonly noCleanup;
8
- private readonly filterFiles;
9
- constructor(options: CopyConfigOptions | undefined, logger?: logdown.Logger | undefined);
10
- private readEnvVars;
11
- private getFilesFromString;
12
- private resolveFiles;
13
- copyDirOrFile(source: string, destination: string): Promise<string[]>;
14
- private clone;
15
- private removeBasedir;
16
- copy(): Promise<string[]>;
17
- }
18
- //# sourceMappingURL=CopyConfig.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CopyConfig.d.ts","sourceRoot":"","sources":["../src/CopyConfig.ts"],"names":[],"mappings":"AAoBA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAYtD,qBAAa,UAAU;IAQnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAP1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2B;gBAGrD,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACrB,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,YAAA;IAiB1C,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,kBAAkB;IAkB1B,OAAO,CAAC,YAAY;IAmBP,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YA2CpE,KAAK;YAkCL,aAAa;IAKd,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CA0BvC"}
package/lib/CopyConfig.js DELETED
@@ -1,210 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2019 Wire Swiss GmbH
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see http://www.gnu.org/licenses/.
18
- *
19
- */
20
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- var desc = Object.getOwnPropertyDescriptor(m, k);
23
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
- desc = { enumerable: true, get: function() { return m[k]; } };
25
- }
26
- Object.defineProperty(o, k2, desc);
27
- }) : (function(o, m, k, k2) {
28
- if (k2 === undefined) k2 = k;
29
- o[k2] = m[k];
30
- }));
31
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
- Object.defineProperty(o, "default", { enumerable: true, value: v });
33
- }) : function(o, v) {
34
- o["default"] = v;
35
- });
36
- var __importStar = (this && this.__importStar) || function (mod) {
37
- if (mod && mod.__esModule) return mod;
38
- var result = {};
39
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
40
- __setModuleDefault(result, mod);
41
- return result;
42
- };
43
- var __importDefault = (this && this.__importDefault) || function (mod) {
44
- return (mod && mod.__esModule) ? mod : { "default": mod };
45
- };
46
- Object.defineProperty(exports, "__esModule", { value: true });
47
- exports.CopyConfig = void 0;
48
- const fs = __importStar(require("fs-extra"));
49
- const path_1 = __importDefault(require("path"));
50
- const utils = __importStar(require("./utils"));
51
- const defaultOptions = {
52
- baseDir: 'config',
53
- externalDir: '',
54
- files: {},
55
- logLevel: 'info',
56
- forceDownload: false,
57
- repositoryUrl: 'https://github.com/wireapp/wire-web-config-default#master',
58
- };
59
- class CopyConfig {
60
- logger;
61
- options;
62
- noClone = false;
63
- noCleanup = false;
64
- filterFiles = ['.DS_Store'];
65
- constructor(options, logger) {
66
- this.logger = logger;
67
- this.options = { ...defaultOptions, ...options };
68
- this.readEnvVars();
69
- if (!this.options.repositoryUrl && !this.options.externalDir) {
70
- throw new Error('Option "repositoryUrl" or "externalDir" required');
71
- }
72
- if (this.options.externalDir) {
73
- this.noClone = true;
74
- this.noCleanup = true;
75
- this.options.baseDir = this.options.externalDir;
76
- }
77
- this.options.baseDir = path_1.default.resolve(this.options.baseDir);
78
- }
79
- readEnvVars() {
80
- const externalDir = process.env.WIRE_CONFIGURATION_EXTERNAL_DIR;
81
- const repositoryUrl = process.env.WIRE_CONFIGURATION_REPOSITORY;
82
- const configurationFiles = process.env.WIRE_CONFIGURATION_FILES;
83
- if (typeof externalDir !== 'undefined') {
84
- this.options.externalDir = String(externalDir);
85
- }
86
- if (typeof repositoryUrl !== 'undefined') {
87
- this.options.repositoryUrl = String(repositoryUrl);
88
- }
89
- if (typeof configurationFiles !== 'undefined') {
90
- const files = this.getFilesFromString(configurationFiles);
91
- Object.assign(this.options.files, files);
92
- }
93
- }
94
- getFilesFromString(files) {
95
- const resolvedPaths = {};
96
- const fileArrayRegex = /^\[(.*)\]$/;
97
- files
98
- .split(';')
99
- .map(fileTuple => String.raw `${fileTuple}`.split(/:(?!\\)/))
100
- .forEach(([source, dest]) => {
101
- let destination = dest;
102
- if (fileArrayRegex.test(destination)) {
103
- destination = dest.replace(fileArrayRegex, '$1').split(',');
104
- }
105
- resolvedPaths[source] = destination;
106
- });
107
- return resolvedPaths;
108
- }
109
- resolveFiles() {
110
- const filesArray = Object.keys(this.options.files);
111
- if (!filesArray.length) {
112
- throw new Error('No source files or directories specified.');
113
- }
114
- filesArray.forEach(source => {
115
- const destination = this.options.files[source];
116
- const joinedSource = path_1.default.join(this.options.baseDir, source);
117
- const resolvedDestination = destination instanceof Array ? destination.map(dest => path_1.default.resolve(dest)) : path_1.default.resolve(destination);
118
- delete this.options.files[source];
119
- this.options.files[joinedSource] = resolvedDestination;
120
- });
121
- }
122
- async copyDirOrFile(source, destination) {
123
- const filter = (src) => {
124
- for (const fileName in this.filterFiles) {
125
- if (src.endsWith(fileName)) {
126
- return false;
127
- }
128
- }
129
- return true;
130
- };
131
- const isGlob = (path) => /\*$/.test(path);
132
- if (utils.isFile(destination) && !utils.isFile(source)) {
133
- throw new Error('Cannot copy a directory into a file.');
134
- }
135
- if (isGlob(source)) {
136
- this.logger?.info(`Resolving "${source}"`);
137
- const copiedFiles = await utils.copyAsync(source, destination);
138
- for (const copiedFile of copiedFiles) {
139
- const [copiedFrom, copiedTo] = copiedFile.history;
140
- this.logger?.debug(`Copying "${copiedFrom}" -> "${copiedTo}"`);
141
- }
142
- return copiedFiles.map(file => file.path);
143
- }
144
- if (utils.isFile(source) && !utils.isFile(destination)) {
145
- destination = path_1.default.join(destination, path_1.default.basename(source));
146
- }
147
- this.logger?.debug(`Copying "${source}" -> "${destination}"`);
148
- // Info: "fs.copy" creates all sub-folders which are needed along the way:
149
- // see https://github.com/jprichardson/node-fs-extra/blob/7.0.1/lib/copy/copy.js#L43
150
- // by default, fs.copy() copies folders recursively
151
- await fs.copy(source, destination, { filter, overwrite: true });
152
- return [destination];
153
- }
154
- async clone() {
155
- const repositoryData = this.options.repositoryUrl.split('#');
156
- let bareUrl = repositoryData[0];
157
- const branch = repositoryData[1] || 'master';
158
- const { stderr: stderrVersion } = await utils.execAsync('git --version');
159
- if (!this.noCleanup) {
160
- await this.removeBasedir();
161
- }
162
- if (stderrVersion) {
163
- this.logger?.error(`No git installation found: (error: "${stderrVersion}"). Trying to download the zip file ...`);
164
- }
165
- if (stderrVersion || this.options.forceDownload) {
166
- if (bareUrl.startsWith('git')) {
167
- const gitProtocolRegex = new RegExp('^git(?::\\/\\/([^@]+@)?|@)([^:]+):(.*)(?:\\.git)?');
168
- bareUrl = bareUrl.replace(gitProtocolRegex, 'https://$1$2/$3');
169
- }
170
- const url = `${bareUrl}/archive/${branch}.zip`;
171
- this.logger?.info(`Downloading "${url}" ...`);
172
- await utils.downloadFileAsync(url, this.options.baseDir);
173
- }
174
- else {
175
- this.logger?.info(`Cloning "${bareUrl}" (branch "${branch}") ...`);
176
- const command = `git clone --depth 1 -b ${branch} ${bareUrl} ${this.options.baseDir}`;
177
- const { stderr: stderrClone } = await utils.execAsync(command);
178
- if (stderrClone.includes('fatal')) {
179
- throw new Error(stderrClone);
180
- }
181
- }
182
- }
183
- async removeBasedir() {
184
- this.logger?.debug(`Cleaning up "${this.options.baseDir}" ...`);
185
- await utils.rimrafAsync(this.options.baseDir);
186
- }
187
- async copy() {
188
- let copiedFiles = [];
189
- if (!this.noClone) {
190
- await this.clone();
191
- }
192
- this.resolveFiles();
193
- for (const file in this.options.files) {
194
- const destination = this.options.files[file];
195
- if (destination instanceof Array) {
196
- const results = await Promise.all(destination.map(dest => this.copyDirOrFile(file, dest)));
197
- results.forEach(result => (copiedFiles = copiedFiles.concat(result)));
198
- }
199
- else {
200
- const result = await this.copyDirOrFile(file, destination);
201
- copiedFiles = copiedFiles.concat(result);
202
- }
203
- }
204
- if (!this.noCleanup) {
205
- await this.removeBasedir();
206
- }
207
- return copiedFiles.sort();
208
- }
209
- }
210
- exports.CopyConfig = CopyConfig;
@@ -1,38 +0,0 @@
1
- export interface CopyConfigOptions {
2
- /**
3
- * The directory to clone or download into.
4
- *
5
- * @example `./config`
6
- */
7
- baseDir?: string;
8
- /**
9
- * An external directory to copy from.
10
- * Disables cloning to and initial deletion of the source directory.
11
- *
12
- * @example `/home/user/externalDir`
13
- */
14
- externalDir?: string;
15
- /**
16
- * Which files to copy (`{source: destination}`)
17
- *
18
- * @example
19
- * {
20
- * '/path/to/source.txt': '/path/to/destination.txt',
21
- * '/path/to/source/': '/path/to/destination/',
22
- * '/path/to/anotherDir/*': [
23
- * '/path/to/thirdDir/', '/path/to/destinationDir/
24
- * ']
25
- * }
26
- */
27
- files?: Record<string, string | string[]>;
28
- /** Force using HTTPS download over `git clone` */
29
- forceDownload?: boolean;
30
- /**
31
- * From where to clone the configuration.
32
- *
33
- * @example `https://github.com/wireapp/wire-web-config-default#v0.7.1`
34
- */
35
- repositoryUrl: string;
36
- logLevel?: 'verbose' | 'info' | 'silent';
37
- }
38
- //# sourceMappingURL=CopyConfigOptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CopyConfigOptions.d.ts","sourceRoot":"","sources":["../src/CopyConfigOptions.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC1C,kDAAkD;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;CAC1C"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2019 Wire Swiss GmbH
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see http://www.gnu.org/licenses/.
18
- *
19
- */
20
- Object.defineProperty(exports, "__esModule", { value: true });
package/lib/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.ts.map
package/lib/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /*
4
- * Wire
5
- * Copyright (C) 2019 Wire Swiss GmbH
6
- *
7
- * This program is free software: you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation, either version 3 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program. If not, see http://www.gnu.org/licenses/.
19
- *
20
- */
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- /* eslint-disable header/header */
26
- const cosmiconfig_1 = require("cosmiconfig");
27
- const logdown_1 = __importDefault(require("logdown"));
28
- const _1 = require("./");
29
- (async () => {
30
- const configExplorer = (0, cosmiconfig_1.cosmiconfig)('copyconfig');
31
- const configFile = await configExplorer.search();
32
- const config = configFile ? configFile.config : undefined;
33
- const logLevel = config?.logLevel || 'info';
34
- const logger = logLevel !== 'silent' ? (0, logdown_1.default)('@wireapp/copy-config', { markdown: false }) : undefined;
35
- if (logger) {
36
- logger.state.isEnabled = true;
37
- if (configFile) {
38
- logger.info(`Found configuration file "${configFile.filepath}".`);
39
- }
40
- if (logLevel !== 'verbose') {
41
- // Disable debug logging when not in verbose mode
42
- logger.debug = () => { };
43
- }
44
- }
45
- const copiedFiles = await new _1.CopyConfig(config, logger).copy();
46
- const copyMessage = copiedFiles.length ? `Copied ${copiedFiles.length}` : "Didn't copy any";
47
- logger?.info(`${copyMessage} file${copiedFiles.length === 1 ? '' : 's'}.`);
48
- })().catch(error => {
49
- console.error(error);
50
- process.exit(1);
51
- });
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './CopyConfig';
2
- export * from './CopyConfigOptions';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
package/lib/index.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2019 Wire Swiss GmbH
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see http://www.gnu.org/licenses/.
18
- *
19
- */
20
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- var desc = Object.getOwnPropertyDescriptor(m, k);
23
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
- desc = { enumerable: true, get: function() { return m[k]; } };
25
- }
26
- Object.defineProperty(o, k2, desc);
27
- }) : (function(o, m, k, k2) {
28
- if (k2 === undefined) k2 = k;
29
- o[k2] = m[k];
30
- }));
31
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- __exportStar(require("./CopyConfig"), exports);
36
- __exportStar(require("./CopyConfigOptions"), exports);
package/lib/utils.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import File from 'vinyl';
2
- import { exec } from 'child_process';
3
- export declare function copyAsync(source: string, destination: string): Promise<File[]>;
4
- export declare function downloadFileAsync(url: string, baseDir: string): Promise<void>;
5
- export declare function extractAsync(zipFile: string, destination: string): Promise<void>;
6
- export declare const isFile: (path: string) => boolean;
7
- export declare const rimrafAsync: ((path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>) & {
8
- rimraf: (path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>;
9
- sync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
10
- rimrafSync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
11
- manual: ((path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>) & {
12
- sync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
13
- };
14
- manualSync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
15
- native: ((path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>) & {
16
- sync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
17
- };
18
- nativeSync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
19
- posix: ((path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>) & {
20
- sync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
21
- };
22
- posixSync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
23
- windows: ((path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>) & {
24
- sync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
25
- };
26
- windowsSync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
27
- moveRemove: ((path: string | string[], opt?: import("rimraf").RimrafAsyncOptions) => Promise<boolean>) & {
28
- sync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
29
- };
30
- moveRemoveSync: (path: string | string[], opt?: import("rimraf").RimrafSyncOptions) => boolean;
31
- };
32
- export declare const execAsync: typeof exec.__promisify__;
33
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAwBA,OAAO,IAAI,MAAM,OAAO,CAAC;AAEzB,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AAInC,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAUpF;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBnF;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBtF;AAED,eAAO,MAAM,MAAM,SAAU,MAAM,YAA0B,CAAC;AAC9D,eAAO,MAAM,WAAW;yCAzBtB,CAAC;uCAAkF,CAAC;6CAIzE,CAAA;0CACoC,CAAA;2CAGlB,CAAC;;6CAGvB,CAAC;0CAEO,CAAC;2CACC,CAAC;;6CAGI,CAAC;yCACiB,CAAC;2CAMc,CAAC;;4CAGxD,CAAC;2CAA4E,CAAC;2CAA0F,CAAC;;8CAAsF,CAAC;8CAA+E,CAAC;2CAA0F,CAAC;;iDAAyF,CAAC;CAFte,CAAC;AAClC,eAAO,MAAM,SAAS,2BAAkB,CAAC"}
package/lib/utils.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2019 Wire Swiss GmbH
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see http://www.gnu.org/licenses/.
18
- *
19
- */
20
- var __importDefault = (this && this.__importDefault) || function (mod) {
21
- return (mod && mod.__esModule) ? mod : { "default": mod };
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.execAsync = exports.rimrafAsync = exports.isFile = void 0;
25
- exports.copyAsync = copyAsync;
26
- exports.downloadFileAsync = downloadFileAsync;
27
- exports.extractAsync = extractAsync;
28
- const axios_1 = __importDefault(require("axios"));
29
- const copy_1 = __importDefault(require("copy"));
30
- const fs_extra_1 = require("fs-extra");
31
- const jszip_1 = __importDefault(require("jszip"));
32
- const rimraf_1 = require("rimraf");
33
- const child_process_1 = require("child_process");
34
- const path_1 = __importDefault(require("path"));
35
- const util_1 = require("util");
36
- async function copyAsync(source, destination) {
37
- if ((0, exports.isFile)(destination)) {
38
- await (0, fs_extra_1.ensureDir)(path_1.default.dirname(destination));
39
- }
40
- else {
41
- await (0, fs_extra_1.ensureDir)(destination);
42
- }
43
- return new Promise((resolve, reject) => (0, copy_1.default)(source, destination, (error, files = []) => (error ? reject(error) : resolve(files))));
44
- }
45
- async function downloadFileAsync(url, baseDir) {
46
- const zipFile = path_1.default.join(baseDir, 'archive.zip');
47
- await (0, fs_extra_1.ensureDir)(baseDir);
48
- await new Promise((resolve, reject) => {
49
- const writer = (0, fs_extra_1.createWriteStream)(zipFile).on('error', reject).on('finish', resolve);
50
- return axios_1.default
51
- .request({
52
- method: 'get',
53
- responseType: 'stream',
54
- url,
55
- })
56
- .then(response => {
57
- response.data.pipe(writer);
58
- });
59
- });
60
- await extractAsync(zipFile, baseDir);
61
- await (0, fs_extra_1.remove)(zipFile);
62
- }
63
- async function extractAsync(zipFile, destination) {
64
- const jszip = new jszip_1.default();
65
- await (0, fs_extra_1.ensureDir)(destination);
66
- const data = await (0, fs_extra_1.readFile)(zipFile);
67
- const entries = [];
68
- await jszip.loadAsync(data, { createFolders: true });
69
- jszip.forEach((filePath, entry) => entries.push([filePath, entry]));
70
- const stripEntry = entries[0][0];
71
- await Promise.all(entries.map(async ([filePath, entry]) => {
72
- const resolvedFilePath = path_1.default.join(destination, filePath.replace(stripEntry, ''));
73
- if (entry.dir) {
74
- await (0, fs_extra_1.ensureDir)(resolvedFilePath);
75
- }
76
- else {
77
- const content = await entry.async('nodebuffer');
78
- await (0, fs_extra_1.writeFile)(resolvedFilePath, content);
79
- }
80
- }));
81
- }
82
- const isFile = (path) => /\w\.\w+$/.test(path);
83
- exports.isFile = isFile;
84
- exports.rimrafAsync = rimraf_1.rimraf;
85
- exports.execAsync = (0, util_1.promisify)(child_process_1.exec);