@wireapp/copy-config 2.1.18 → 2.2.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/lib/CopyConfig.d.ts +3 -2
- package/lib/CopyConfig.d.ts.map +1 -1
- package/lib/CopyConfig.js +13 -13
- package/lib/CopyConfigOptions.d.ts +1 -0
- package/lib/CopyConfigOptions.d.ts.map +1 -1
- package/lib/cli.js +15 -10
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +1 -1
- package/package.json +2 -2
package/lib/CopyConfig.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import logdown from 'logdown';
|
|
1
2
|
import { CopyConfigOptions } from './CopyConfigOptions';
|
|
2
3
|
export declare class CopyConfig {
|
|
4
|
+
private readonly logger?;
|
|
3
5
|
private readonly options;
|
|
4
|
-
private readonly logger;
|
|
5
6
|
private readonly noClone;
|
|
6
7
|
private readonly noCleanup;
|
|
7
8
|
private readonly filterFiles;
|
|
8
|
-
constructor(options: CopyConfigOptions);
|
|
9
|
+
constructor(options: CopyConfigOptions | undefined, logger?: logdown.Logger | undefined);
|
|
9
10
|
private readEnvVars;
|
|
10
11
|
private getFilesFromString;
|
|
11
12
|
private resolveFiles;
|
package/lib/CopyConfig.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyConfig.d.ts","sourceRoot":"","sources":["../src/CopyConfig.ts"],"names":[],"mappings":"
|
|
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,4BAAgB;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;YA0CpE,KAAK;YAkCL,aAAa;IAKd,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CA0BvC"}
|
package/lib/CopyConfig.js
CHANGED
|
@@ -46,18 +46,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
47
|
exports.CopyConfig = void 0;
|
|
48
48
|
const fs = __importStar(require("fs-extra"));
|
|
49
|
-
const logdown_1 = __importDefault(require("logdown"));
|
|
50
49
|
const path_1 = __importDefault(require("path"));
|
|
51
50
|
const utils = __importStar(require("./utils"));
|
|
52
51
|
const defaultOptions = {
|
|
53
52
|
baseDir: 'config',
|
|
54
53
|
externalDir: '',
|
|
55
54
|
files: {},
|
|
55
|
+
logLevel: 'info',
|
|
56
56
|
forceDownload: false,
|
|
57
57
|
repositoryUrl: 'https://github.com/wireapp/wire-web-config-default#master',
|
|
58
58
|
};
|
|
59
59
|
class CopyConfig {
|
|
60
|
-
constructor(options) {
|
|
60
|
+
constructor(options, logger) {
|
|
61
|
+
this.logger = logger;
|
|
61
62
|
this.noClone = false;
|
|
62
63
|
this.noCleanup = false;
|
|
63
64
|
this.filterFiles = ['.DS_Store'];
|
|
@@ -72,10 +73,6 @@ class CopyConfig {
|
|
|
72
73
|
this.options.baseDir = this.options.externalDir;
|
|
73
74
|
}
|
|
74
75
|
this.options.baseDir = path_1.default.resolve(this.options.baseDir);
|
|
75
|
-
this.logger = (0, logdown_1.default)('@wireapp/copy-config/CopyConfig', {
|
|
76
|
-
markdown: false,
|
|
77
|
-
});
|
|
78
|
-
this.logger.state.isEnabled = true;
|
|
79
76
|
}
|
|
80
77
|
readEnvVars() {
|
|
81
78
|
const externalDir = process.env.WIRE_CONFIGURATION_EXTERNAL_DIR;
|
|
@@ -121,6 +118,7 @@ class CopyConfig {
|
|
|
121
118
|
});
|
|
122
119
|
}
|
|
123
120
|
async copyDirOrFile(source, destination) {
|
|
121
|
+
var _a, _b, _c;
|
|
124
122
|
const filter = (src) => {
|
|
125
123
|
for (const fileName in this.filterFiles) {
|
|
126
124
|
if (src.endsWith(fileName)) {
|
|
@@ -134,24 +132,25 @@ class CopyConfig {
|
|
|
134
132
|
throw new Error('Cannot copy a directory into a file.');
|
|
135
133
|
}
|
|
136
134
|
if (isGlob(source)) {
|
|
137
|
-
this.logger.info(`Resolving "${source}"`);
|
|
135
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`Resolving "${source}"`);
|
|
138
136
|
const copiedFiles = await utils.copyAsync(source, destination);
|
|
139
137
|
for (const copiedFile of copiedFiles) {
|
|
140
138
|
const [copiedFrom, copiedTo] = copiedFile.history;
|
|
141
|
-
this.logger.
|
|
139
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug(`Copying "${copiedFrom}" -> "${copiedTo}"`);
|
|
142
140
|
}
|
|
143
141
|
return copiedFiles.map(file => file.path);
|
|
144
142
|
}
|
|
145
143
|
if (utils.isFile(source) && !utils.isFile(destination)) {
|
|
146
144
|
destination = path_1.default.join(destination, path_1.default.basename(source));
|
|
147
145
|
}
|
|
148
|
-
this.logger.
|
|
146
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.debug(`Copying "${source}" -> "${destination}"`);
|
|
149
147
|
// Info: "fs.copy" creates all sub-folders which are needed along the way:
|
|
150
148
|
// see https://github.com/jprichardson/node-fs-extra/blob/7.0.1/lib/copy/copy.js#L43
|
|
151
149
|
await fs.copy(source, destination, { filter, overwrite: true, recursive: true });
|
|
152
150
|
return [destination];
|
|
153
151
|
}
|
|
154
152
|
async clone() {
|
|
153
|
+
var _a, _b, _c;
|
|
155
154
|
const repositoryData = this.options.repositoryUrl.split('#');
|
|
156
155
|
let bareUrl = repositoryData[0];
|
|
157
156
|
const branch = repositoryData[1] || 'master';
|
|
@@ -160,7 +159,7 @@ class CopyConfig {
|
|
|
160
159
|
await this.removeBasedir();
|
|
161
160
|
}
|
|
162
161
|
if (stderrVersion) {
|
|
163
|
-
this.logger.error(`No git installation found: (error: "${stderrVersion}"). Trying to download the zip file ...`);
|
|
162
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`No git installation found: (error: "${stderrVersion}"). Trying to download the zip file ...`);
|
|
164
163
|
}
|
|
165
164
|
if (stderrVersion || this.options.forceDownload) {
|
|
166
165
|
if (bareUrl.startsWith('git')) {
|
|
@@ -168,11 +167,11 @@ class CopyConfig {
|
|
|
168
167
|
bareUrl = bareUrl.replace(gitProtocolRegex, 'https://$1$2/$3');
|
|
169
168
|
}
|
|
170
169
|
const url = `${bareUrl}/archive/${branch}.zip`;
|
|
171
|
-
this.logger.info(`Downloading "${url}" ...`);
|
|
170
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`Downloading "${url}" ...`);
|
|
172
171
|
await utils.downloadFileAsync(url, this.options.baseDir);
|
|
173
172
|
}
|
|
174
173
|
else {
|
|
175
|
-
this.logger.info(`Cloning "${bareUrl}" (branch "${branch}") ...`);
|
|
174
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`Cloning "${bareUrl}" (branch "${branch}") ...`);
|
|
176
175
|
const command = `git clone --depth 1 -b ${branch} ${bareUrl} ${this.options.baseDir}`;
|
|
177
176
|
const { stderr: stderrClone } = await utils.execAsync(command);
|
|
178
177
|
if (stderrClone.includes('fatal')) {
|
|
@@ -181,7 +180,8 @@ class CopyConfig {
|
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
async removeBasedir() {
|
|
184
|
-
|
|
183
|
+
var _a;
|
|
184
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`Cleaning up "${this.options.baseDir}" ...`);
|
|
185
185
|
await utils.rimrafAsync(this.options.baseDir);
|
|
186
186
|
}
|
|
187
187
|
async copy() {
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
package/lib/cli.js
CHANGED
|
@@ -26,20 +26,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
27
27
|
const logdown_1 = __importDefault(require("logdown"));
|
|
28
28
|
const _1 = require("./");
|
|
29
|
-
const configExplorer = (0, cosmiconfig_1.cosmiconfig)('copyconfig');
|
|
30
|
-
const logger = (0, logdown_1.default)('@wireapp/copy-config/cli', {
|
|
31
|
-
markdown: false,
|
|
32
|
-
});
|
|
33
|
-
logger.state.isEnabled = true;
|
|
34
29
|
(async () => {
|
|
30
|
+
const configExplorer = (0, cosmiconfig_1.cosmiconfig)('copyconfig');
|
|
35
31
|
const configFile = await configExplorer.search();
|
|
36
|
-
if (configFile) {
|
|
37
|
-
logger.info(`Found configuration file "${configFile.filepath}".`);
|
|
38
|
-
}
|
|
39
32
|
const config = configFile ? configFile.config : undefined;
|
|
40
|
-
const
|
|
33
|
+
const logLevel = (config === null || config === void 0 ? void 0 : 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();
|
|
41
46
|
const copyMessage = copiedFiles.length ? `Copied ${copiedFiles.length}` : "Didn't copy any";
|
|
42
|
-
logger.info(`${copyMessage} file${copiedFiles.length === 1 ? '' : 's'}.`);
|
|
47
|
+
logger === null || logger === void 0 ? void 0 : logger.info(`${copyMessage} file${copiedFiles.length === 1 ? '' : 's'}.`);
|
|
43
48
|
})().catch(error => {
|
|
44
49
|
console.error(error);
|
|
45
50
|
process.exit(1);
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,iCAAoB,CAAC;AAC7C,eAAO,MAAM,SAAS,2BAAkB,CAAC"}
|
package/lib/utils.js
CHANGED
|
@@ -79,7 +79,7 @@ async function extractAsync(zipFile, destination) {
|
|
|
79
79
|
}));
|
|
80
80
|
}
|
|
81
81
|
exports.extractAsync = extractAsync;
|
|
82
|
-
const isFile = (path) =>
|
|
82
|
+
const isFile = (path) => /\w\.\w+$/.test(path);
|
|
83
83
|
exports.isFile = isFile;
|
|
84
84
|
exports.rimrafAsync = (0, util_1.promisify)(rimraf_1.default);
|
|
85
85
|
exports.execAsync = (0, util_1.promisify)(child_process_1.exec);
|
package/package.json
CHANGED