@zokugun/artifact 0.4.4 → 0.5.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/commands/add.js +32 -44
- package/lib/commands/list.js +15 -27
- package/lib/commands/update.js +34 -46
- package/lib/compositors/compose.js +4 -5
- package/lib/compositors/fork.js +2 -2
- package/lib/compositors/json.js +1 -1
- package/lib/compositors/rc.js +1 -2
- package/lib/configs/install/read-install-config.js +74 -82
- package/lib/configs/install/write-install-config.js +21 -32
- package/lib/configs/package/read-package-config.js +33 -44
- package/lib/parsers/jsonc/stringify.js +11 -14
- package/lib/routes/command.js +2 -3
- package/lib/routes/lines-concat.js +1 -1
- package/lib/routes/list-concat.js +1 -1
- package/lib/routes/list-sort-concat.js +1 -1
- package/lib/routes/map-concat.js +2 -2
- package/lib/routes/overwrite.js +1 -1
- package/lib/routes/primitive.js +1 -1
- package/lib/steps/apply-formatting.js +7 -18
- package/lib/steps/configure-branches.js +43 -54
- package/lib/steps/configure-install-file-actions.js +52 -63
- package/lib/steps/configure-update-file-actions.js +63 -74
- package/lib/steps/copy-binary-files.js +29 -40
- package/lib/steps/execute-first-block.js +61 -75
- package/lib/steps/execute-next-block.js +6 -17
- package/lib/steps/index.js +23 -16
- package/lib/steps/insert-final-new-line.js +7 -18
- package/lib/steps/merge-text-files.js +70 -79
- package/lib/steps/read-editor-config.js +35 -46
- package/lib/steps/read-files.js +37 -48
- package/lib/steps/read-incoming-config.js +7 -18
- package/lib/steps/read-incoming-package.js +7 -18
- package/lib/steps/remove-files.js +18 -29
- package/lib/steps/replace-templates.js +15 -20
- package/lib/steps/validate-newer-package.js +8 -19
- package/lib/steps/validate-not-present-package.js +15 -26
- package/lib/steps/write-text-files.js +16 -27
- package/lib/utils/read-buffer.js +13 -24
- package/lib/utils/template.js +63 -31
- package/lib/utils/try-json.js +1 -1
- package/package.json +3 -3
package/lib/commands/add.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -42,44 +33,41 @@ const { mainFlow } = (0, steps_1.composeSteps)([
|
|
|
42
33
|
steps_1.steps.removeFiles,
|
|
43
34
|
steps_1.steps.executeNextBlock,
|
|
44
35
|
]);
|
|
45
|
-
function add(specs, inputOptions) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (options.
|
|
65
|
-
|
|
66
|
-
if (options.verbose) {
|
|
67
|
-
console.log(`The artifact '${spec}' couldn't be found, skipping...`);
|
|
68
|
-
}
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new Error(pkgResult.from);
|
|
36
|
+
async function add(specs, inputOptions) {
|
|
37
|
+
await npm_1.default.load();
|
|
38
|
+
const registry = npm_1.default.config.get('registry');
|
|
39
|
+
const targetPath = process_1.default.env.INIT_CWD;
|
|
40
|
+
const options = {
|
|
41
|
+
force: inputOptions?.force ?? false,
|
|
42
|
+
skip: inputOptions?.skip ?? false,
|
|
43
|
+
verbose: inputOptions?.verbose ?? false,
|
|
44
|
+
dryRun: inputOptions?.dryRun ?? false,
|
|
45
|
+
};
|
|
46
|
+
const { config, configStats } = await (0, configs_1.readInstallConfig)(targetPath);
|
|
47
|
+
for (const spec of specs) {
|
|
48
|
+
const request = (0, resolve_request_1.resolveRequest)(spec);
|
|
49
|
+
const spinner = (0, ora_1.default)(`${ansi_colors_1.cyan.bold(request.name)}`).start();
|
|
50
|
+
const dir = tempy_1.default.directory();
|
|
51
|
+
const pkgResult = await pacote_1.default.extract(request.name, dir, { registry });
|
|
52
|
+
if (!pkgResult.resolved) {
|
|
53
|
+
if (options.force || options.skip) {
|
|
54
|
+
spinner.fail();
|
|
55
|
+
if (options.verbose) {
|
|
56
|
+
console.log(`The artifact '${spec}' couldn't be found, skipping...`);
|
|
73
57
|
}
|
|
74
|
-
}
|
|
75
|
-
const flowResult = yield mainFlow(targetPath, dir, request, config, options);
|
|
76
|
-
if (!flowResult || !flowResult.result) {
|
|
77
|
-
spinner.succeed();
|
|
78
58
|
continue;
|
|
79
59
|
}
|
|
80
|
-
|
|
81
|
-
|
|
60
|
+
else {
|
|
61
|
+
throw new Error(pkgResult.from);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const flowResult = await mainFlow(targetPath, dir, request, config, options);
|
|
65
|
+
if (!flowResult || !flowResult.result) {
|
|
82
66
|
spinner.succeed();
|
|
67
|
+
continue;
|
|
83
68
|
}
|
|
84
|
-
|
|
69
|
+
(0, configs_1.updateInstallConfig)(config, flowResult.result);
|
|
70
|
+
await (0, configs_1.writeInstallConfig)(config, configStats, flowResult.formats, targetPath, options);
|
|
71
|
+
spinner.succeed();
|
|
72
|
+
}
|
|
85
73
|
}
|
package/lib/commands/list.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -17,8 +8,7 @@ const process_1 = __importDefault(require("process"));
|
|
|
17
8
|
const lodash_1 = require("lodash");
|
|
18
9
|
const configs_1 = require("../configs");
|
|
19
10
|
function formatVariant(artifact) {
|
|
20
|
-
|
|
21
|
-
const variant = Array.isArray(artifact.requires) ? (_a = (0, lodash_1.last)(artifact.requires)) !== null && _a !== void 0 ? _a : '' : '';
|
|
11
|
+
const variant = Array.isArray(artifact.requires) ? (0, lodash_1.last)(artifact.requires) ?? '' : '';
|
|
22
12
|
if (variant.length > 0) {
|
|
23
13
|
return `:${variant}`;
|
|
24
14
|
}
|
|
@@ -26,21 +16,19 @@ function formatVariant(artifact) {
|
|
|
26
16
|
return '';
|
|
27
17
|
}
|
|
28
18
|
}
|
|
29
|
-
function list() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log(`- ${name}${version}${formatVariant(artifact)}`);
|
|
42
|
-
}
|
|
19
|
+
async function list() {
|
|
20
|
+
const targetPath = process_1.default.env.INIT_CWD;
|
|
21
|
+
const { config, configStats } = await (0, configs_1.readInstallConfig)(targetPath);
|
|
22
|
+
const artifacts = Object.entries(config.artifacts);
|
|
23
|
+
if (artifacts.length === 0) {
|
|
24
|
+
console.log('No artifacts have been installed.');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
console.log(`List of installed artifacts (${configStats.name}):\n`);
|
|
28
|
+
for (const [name, artifact] of artifacts) {
|
|
29
|
+
const version = artifact.version ? `@${artifact.version}` : '';
|
|
30
|
+
console.log(`- ${name}${version}${formatVariant(artifact)}`);
|
|
43
31
|
}
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
}
|
|
33
|
+
console.log();
|
|
46
34
|
}
|
package/lib/commands/update.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -43,46 +34,43 @@ const { mainFlow } = (0, steps_1.composeSteps)([
|
|
|
43
34
|
steps_1.steps.removeFiles,
|
|
44
35
|
steps_1.steps.executeNextBlock,
|
|
45
36
|
]);
|
|
46
|
-
function update(inputOptions) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (options.
|
|
67
|
-
|
|
68
|
-
if (options.verbose) {
|
|
69
|
-
console.log(`The artifact '${name}' couldn't be found, skipping...`);
|
|
70
|
-
}
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new Error(pkgResult.from);
|
|
37
|
+
async function update(inputOptions) {
|
|
38
|
+
// @ts-expect-error log property isn't exposed
|
|
39
|
+
npm_1.default.log.stream = (0, dev_null_1.createDevNull)();
|
|
40
|
+
await npm_1.default.load();
|
|
41
|
+
const registry = npm_1.default.config.get('registry');
|
|
42
|
+
const targetPath = process_1.default.env.INIT_CWD;
|
|
43
|
+
const options = {
|
|
44
|
+
force: inputOptions?.force ?? false,
|
|
45
|
+
skip: false,
|
|
46
|
+
verbose: inputOptions?.verbose ?? false,
|
|
47
|
+
dryRun: inputOptions?.dryRun ?? false,
|
|
48
|
+
};
|
|
49
|
+
const { config, configStats } = await (0, configs_1.readInstallConfig)(targetPath);
|
|
50
|
+
for (const [name, artifact] of Object.entries(config.artifacts)) {
|
|
51
|
+
const spinner = (0, ora_1.default)(`${ansi_colors_1.cyan.bold(name)}`).start();
|
|
52
|
+
const dir = tempy_1.default.directory();
|
|
53
|
+
const pkgResult = await pacote_1.default.extract(name, dir, { registry });
|
|
54
|
+
if (!pkgResult.resolved) {
|
|
55
|
+
if (options.force) {
|
|
56
|
+
spinner.fail();
|
|
57
|
+
if (options.verbose) {
|
|
58
|
+
console.log(`The artifact '${name}' couldn't be found, skipping...`);
|
|
75
59
|
}
|
|
76
|
-
}
|
|
77
|
-
const request = artifact.requires ? { name, variant: (0, lodash_1.last)(artifact.requires) } : { name };
|
|
78
|
-
const flowResult = yield mainFlow(targetPath, dir, request, config, options);
|
|
79
|
-
if (!flowResult || !flowResult.result) {
|
|
80
|
-
spinner.succeed();
|
|
81
60
|
continue;
|
|
82
61
|
}
|
|
83
|
-
|
|
84
|
-
|
|
62
|
+
else {
|
|
63
|
+
throw new Error(pkgResult.from);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const request = artifact.requires ? { name, variant: (0, lodash_1.last)(artifact.requires) } : { name };
|
|
67
|
+
const flowResult = await mainFlow(targetPath, dir, request, config, options);
|
|
68
|
+
if (!flowResult || !flowResult.result) {
|
|
85
69
|
spinner.succeed();
|
|
70
|
+
continue;
|
|
86
71
|
}
|
|
87
|
-
|
|
72
|
+
(0, configs_1.updateInstallConfig)(config, flowResult.result);
|
|
73
|
+
await (0, configs_1.writeInstallConfig)(config, configStats, flowResult.formats, targetPath, options);
|
|
74
|
+
spinner.succeed();
|
|
75
|
+
}
|
|
88
76
|
}
|
|
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.compose = compose;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
function apply(map, keys, current, incoming, result) {
|
|
6
|
-
var _a, _b;
|
|
7
6
|
if (keys.length === 0) {
|
|
8
7
|
return;
|
|
9
8
|
}
|
|
10
|
-
const ignores =
|
|
9
|
+
const ignores = map.$$ignore ?? [];
|
|
11
10
|
for (const key of keys) {
|
|
12
11
|
const currentValue = current[key];
|
|
13
|
-
const transform =
|
|
12
|
+
const transform = map[key] ?? map.$$default;
|
|
14
13
|
if (!transform || !(0, lodash_1.has)(incoming, key) || ignores.includes(key)) {
|
|
15
14
|
if (!(0, lodash_1.isNil)(currentValue)) {
|
|
16
15
|
result[key] = currentValue;
|
|
@@ -28,7 +27,7 @@ function apply(map, keys, current, incoming, result) {
|
|
|
28
27
|
function compose(map) {
|
|
29
28
|
return ({ current, incoming, filters }) => {
|
|
30
29
|
if ((0, lodash_1.isNil)(incoming)) {
|
|
31
|
-
return current
|
|
30
|
+
return current ?? {};
|
|
32
31
|
}
|
|
33
32
|
if ((0, lodash_1.isNil)(current) || typeof current !== typeof incoming) {
|
|
34
33
|
return incoming;
|
|
@@ -37,7 +36,7 @@ function compose(map) {
|
|
|
37
36
|
const incomingKeys = Object.keys(incoming);
|
|
38
37
|
const newKeys = (0, lodash_1.without)(incomingKeys, ...currentKeys);
|
|
39
38
|
if (filters) {
|
|
40
|
-
const result =
|
|
39
|
+
const result = { ...current };
|
|
41
40
|
apply(map, filters, current, incoming, result);
|
|
42
41
|
apply(map, newKeys, current, incoming, result);
|
|
43
42
|
return result;
|
package/lib/compositors/fork.js
CHANGED
|
@@ -8,11 +8,11 @@ function fork(...cases) {
|
|
|
8
8
|
return c;
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
return c[0](current
|
|
11
|
+
return c[0](current ?? incoming);
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
if (!targetCase) {
|
|
15
|
-
return current
|
|
15
|
+
return current ?? incoming;
|
|
16
16
|
}
|
|
17
17
|
const targetMerge = Array.isArray(targetCase) ? targetCase[1] : targetCase;
|
|
18
18
|
return targetMerge({ current, incoming });
|
package/lib/compositors/json.js
CHANGED
package/lib/compositors/rc.js
CHANGED
|
@@ -40,8 +40,7 @@ const YAML = __importStar(require("../parsers/yaml"));
|
|
|
40
40
|
const try_json_1 = require("../utils/try-json");
|
|
41
41
|
function rc(...routes) {
|
|
42
42
|
return ({ current, incoming, filters, ignores }) => {
|
|
43
|
-
|
|
44
|
-
const currentData = current && ((_a = (0, try_json_1.tryJson)(current)) !== null && _a !== void 0 ? _a : YAML.parse(current));
|
|
43
|
+
const currentData = current && ((0, try_json_1.tryJson)(current) ?? YAML.parse(current));
|
|
45
44
|
const incomingData = incoming && (0, try_json_1.tryJson)(incoming);
|
|
46
45
|
if (incomingData) {
|
|
47
46
|
return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -33,87 +24,88 @@ const places = [
|
|
|
33
24
|
name: '.artifactrc',
|
|
34
25
|
},
|
|
35
26
|
];
|
|
36
|
-
function readInstallConfig(targetPath) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
catch (_a) {
|
|
49
|
-
}
|
|
27
|
+
async function readInstallConfig(targetPath) {
|
|
28
|
+
let content;
|
|
29
|
+
let name;
|
|
30
|
+
let type;
|
|
31
|
+
for (const place of places) {
|
|
32
|
+
try {
|
|
33
|
+
content = await fs_extra_1.default.readFile(path_1.default.join(targetPath, place.name), 'utf-8');
|
|
34
|
+
name = place.name;
|
|
35
|
+
type = place.type;
|
|
36
|
+
break;
|
|
50
37
|
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
config: {
|
|
54
|
-
artifacts: {},
|
|
55
|
-
install: {},
|
|
56
|
-
update: {},
|
|
57
|
-
},
|
|
58
|
-
configStats: {
|
|
59
|
-
name: '.artifactrc.yml',
|
|
60
|
-
type: 'yaml',
|
|
61
|
-
finalNewLine: true,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
38
|
+
catch {
|
|
64
39
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
40
|
+
}
|
|
41
|
+
if (!content) {
|
|
42
|
+
return {
|
|
43
|
+
config: {
|
|
44
|
+
artifacts: {},
|
|
45
|
+
install: {},
|
|
46
|
+
update: {},
|
|
47
|
+
},
|
|
48
|
+
configStats: {
|
|
49
|
+
name: '.artifactrc.yml',
|
|
50
|
+
type: 'yaml',
|
|
51
|
+
finalNewLine: true,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const finalNewLine = content.endsWith('\n');
|
|
56
|
+
let data;
|
|
57
|
+
if (type === 'json') {
|
|
58
|
+
data = JSON.parse(content);
|
|
59
|
+
}
|
|
60
|
+
else if (type === 'yaml') {
|
|
61
|
+
data = yaml_1.default.parse(content);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
try {
|
|
68
65
|
data = JSON.parse(content);
|
|
66
|
+
type = 'json';
|
|
69
67
|
}
|
|
70
|
-
|
|
68
|
+
catch {
|
|
71
69
|
data = yaml_1.default.parse(content);
|
|
70
|
+
type = 'yaml';
|
|
72
71
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
data.update
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
install: data.install,
|
|
90
|
-
update: data.update,
|
|
91
|
-
};
|
|
92
|
-
for (const { name, version } of data.artifacts) {
|
|
93
|
-
config.artifacts[name] = {
|
|
94
|
-
version,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
config,
|
|
99
|
-
configStats: {
|
|
100
|
-
name: name,
|
|
101
|
-
type,
|
|
102
|
-
finalNewLine,
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
return {
|
|
108
|
-
config: data,
|
|
109
|
-
configStats: {
|
|
110
|
-
name: name,
|
|
111
|
-
type,
|
|
112
|
-
finalNewLine,
|
|
113
|
-
},
|
|
72
|
+
}
|
|
73
|
+
if (typeof data.artifacts === 'undefined') {
|
|
74
|
+
data.artifacts = {};
|
|
75
|
+
}
|
|
76
|
+
if (typeof data.update === 'undefined') {
|
|
77
|
+
data.update = {};
|
|
78
|
+
}
|
|
79
|
+
if (isOldInstallConfig(data)) {
|
|
80
|
+
const config = {
|
|
81
|
+
artifacts: {},
|
|
82
|
+
install: data.install,
|
|
83
|
+
update: data.update,
|
|
84
|
+
};
|
|
85
|
+
for (const { name, version } of data.artifacts) {
|
|
86
|
+
config.artifacts[name] = {
|
|
87
|
+
version,
|
|
114
88
|
};
|
|
115
89
|
}
|
|
116
|
-
|
|
90
|
+
return {
|
|
91
|
+
config,
|
|
92
|
+
configStats: {
|
|
93
|
+
name: name,
|
|
94
|
+
type,
|
|
95
|
+
finalNewLine,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return {
|
|
101
|
+
config: data,
|
|
102
|
+
configStats: {
|
|
103
|
+
name: name,
|
|
104
|
+
type,
|
|
105
|
+
finalNewLine,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
117
109
|
}
|
|
118
110
|
function isOldInstallConfig(config) {
|
|
119
111
|
return Array.isArray(config.artifacts);
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -19,27 +10,25 @@ const lodash_1 = require("lodash");
|
|
|
19
10
|
const yaml_1 = __importDefault(require("yaml"));
|
|
20
11
|
const apply_formatting_1 = require("../../steps/apply-formatting");
|
|
21
12
|
const insert_final_new_line_1 = require("../../steps/insert-final-new-line");
|
|
22
|
-
function writeInstallConfig(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
});
|
|
13
|
+
async function writeInstallConfig(config, { name, finalNewLine, type }, formats, targetPath, options) {
|
|
14
|
+
const exported = {
|
|
15
|
+
artifacts: config.artifacts,
|
|
16
|
+
};
|
|
17
|
+
if (!(0, lodash_1.isPlainObject)(config.update) || !(0, lodash_1.isEmpty)(config.update)) {
|
|
18
|
+
exported.update = config.update;
|
|
19
|
+
}
|
|
20
|
+
const file = {
|
|
21
|
+
name,
|
|
22
|
+
data: type === 'yaml' ? yaml_1.default.stringify(exported) : JSON.stringify(exported, null, '\t'),
|
|
23
|
+
finalNewLine,
|
|
24
|
+
};
|
|
25
|
+
await (0, insert_final_new_line_1.insertFinalNewLine)({ mergedTextFiles: [file] });
|
|
26
|
+
await (0, apply_formatting_1.applyFormatting)({ mergedTextFiles: [file], formats });
|
|
27
|
+
if (!options.dryRun) {
|
|
28
|
+
const filePath = path_1.default.join(targetPath, name);
|
|
29
|
+
await fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
|
|
30
|
+
}
|
|
31
|
+
if (options.verbose) {
|
|
32
|
+
console.log(`${name} has been written`);
|
|
33
|
+
}
|
|
45
34
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -33,45 +24,43 @@ const places = [
|
|
|
33
24
|
name: '.artifactrc',
|
|
34
25
|
},
|
|
35
26
|
];
|
|
36
|
-
function readPackageConfig(targetPath) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
catch (_a) {
|
|
47
|
-
}
|
|
27
|
+
async function readPackageConfig(targetPath) {
|
|
28
|
+
let content;
|
|
29
|
+
let type;
|
|
30
|
+
for (const place of places) {
|
|
31
|
+
try {
|
|
32
|
+
content = await fs_extra_1.default.readFile(path_1.default.join(targetPath, place.name), 'utf-8');
|
|
33
|
+
type = place.type;
|
|
34
|
+
break;
|
|
48
35
|
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
install: {},
|
|
52
|
-
update: {},
|
|
53
|
-
};
|
|
36
|
+
catch {
|
|
54
37
|
}
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
}
|
|
39
|
+
if (!content) {
|
|
40
|
+
return {
|
|
41
|
+
install: {},
|
|
42
|
+
update: {},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
let config;
|
|
46
|
+
if (type === 'json') {
|
|
47
|
+
config = JSON.parse(content);
|
|
48
|
+
}
|
|
49
|
+
else if (type === 'yaml') {
|
|
50
|
+
config = yaml_1.default.parse(content);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
try {
|
|
57
54
|
config = JSON.parse(content);
|
|
55
|
+
type = 'json';
|
|
58
56
|
}
|
|
59
|
-
|
|
57
|
+
catch {
|
|
60
58
|
config = yaml_1.default.parse(content);
|
|
59
|
+
type = 'yaml';
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
catch (_b) {
|
|
68
|
-
config = yaml_1.default.parse(content);
|
|
69
|
-
type = 'yaml';
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (typeof config.update === 'undefined') {
|
|
73
|
-
config.update = {};
|
|
74
|
-
}
|
|
75
|
-
return config;
|
|
76
|
-
});
|
|
61
|
+
}
|
|
62
|
+
if (typeof config.update === 'undefined') {
|
|
63
|
+
config.update = {};
|
|
64
|
+
}
|
|
65
|
+
return config;
|
|
77
66
|
}
|