@zokugun/artifact 0.3.1 → 0.4.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/README.md +124 -37
- package/lib/cli.js +8 -2
- package/lib/commands/add.js +35 -41
- package/lib/commands/index.js +3 -1
- package/lib/commands/list.js +47 -0
- package/lib/commands/update.js +32 -17
- package/lib/compositors/compose.js +6 -10
- package/lib/configs/index.js +18 -0
- package/lib/configs/install/index.js +9 -0
- package/lib/configs/install/read-install-config.js +121 -0
- package/lib/configs/install/update-install-config.js +16 -0
- package/lib/{config/write-config.js → configs/install/write-install-config.js} +8 -8
- package/lib/configs/package/index.js +5 -0
- package/lib/{config/read-config.js → configs/package/read-package-config.js} +15 -32
- package/lib/journeys/config.ts/index.js +11 -0
- package/lib/journeys/index.js +2 -0
- package/lib/journeys/package/index.js +0 -1
- package/lib/parsers/jsonc/parse.js +1 -1
- package/lib/steps/apply-formatting.js +2 -2
- package/lib/steps/configure-branches.js +70 -0
- package/lib/steps/configure-install-file-actions.js +152 -0
- package/lib/steps/{validate-updatability.js → configure-update-file-actions.js} +10 -10
- package/lib/steps/copy-binary-files.js +19 -10
- package/lib/steps/execute-first-block.js +113 -0
- package/lib/steps/execute-next-block.js +23 -0
- package/lib/steps/index.js +45 -7
- package/lib/steps/merge-text-files.js +61 -31
- package/lib/steps/read-incoming-config.js +8 -3
- package/lib/steps/read-incoming-package.js +11 -2
- package/lib/steps/remove-files.js +41 -0
- package/lib/steps/validate-newer-package.js +1 -1
- package/lib/steps/validate-not-present-package.js +1 -1
- package/lib/utils/resolve-request.js +43 -0
- package/lib/utils/template.js +4 -3
- package/package.json +4 -3
- package/lib/config/index.js +0 -7
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.executeFirstBlock = void 0;
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
const lodash_1 = require("lodash");
|
|
18
|
+
const configs_1 = require("../configs");
|
|
19
|
+
function executeFirstBlock(context) {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const { name, version } = context.incomingPackage;
|
|
23
|
+
const root = String((_b = (_a = context.incomingConfig.variants) === null || _a === void 0 ? void 0 : _a.root) !== null && _b !== void 0 ? _b : '');
|
|
24
|
+
if (context.incomingVariant) {
|
|
25
|
+
let variant;
|
|
26
|
+
let alias;
|
|
27
|
+
if ((0, lodash_1.isNil)(context.incomingConfig.variants[context.incomingVariant])) {
|
|
28
|
+
variant = context.incomingVariant;
|
|
29
|
+
alias = false;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
variant = String(context.incomingConfig.variants[context.incomingVariant]);
|
|
33
|
+
alias = true;
|
|
34
|
+
}
|
|
35
|
+
const variantPath = node_path_1.default.join(context.packagePath, 'variants', variant);
|
|
36
|
+
const variantConfig = yield (0, configs_1.readPackageConfig)(variantPath);
|
|
37
|
+
if (variantConfig.orphan) {
|
|
38
|
+
pushToResult(name, version, variant, alias, context);
|
|
39
|
+
context.incomingConfig = variantConfig;
|
|
40
|
+
yield context.commonFlow(name, version, variant, undefined, variantPath, context);
|
|
41
|
+
}
|
|
42
|
+
else if (variantConfig.extends) {
|
|
43
|
+
context.blocks.unshift({
|
|
44
|
+
name,
|
|
45
|
+
version,
|
|
46
|
+
variant,
|
|
47
|
+
incomingPath: node_path_1.default.join(context.packagePath, 'variants', variant),
|
|
48
|
+
});
|
|
49
|
+
pushToResult(name, version, variant, alias, context);
|
|
50
|
+
const extend = String((_c = context.incomingConfig.variants[variantConfig.extends]) !== null && _c !== void 0 ? _c : variantConfig.extends);
|
|
51
|
+
context.incomingVariant = extend;
|
|
52
|
+
return executeFirstBlock(context);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (root.length === 0) {
|
|
56
|
+
throw new Error('No root variant has been defined');
|
|
57
|
+
}
|
|
58
|
+
if (root === variant) {
|
|
59
|
+
pushToResult(name, version, variant, alias, context);
|
|
60
|
+
context.incomingConfig = variantConfig;
|
|
61
|
+
yield context.commonFlow(name, version, variant, undefined, variantPath, context);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const variant = String((_d = context.incomingConfig.variants[context.request.variant]) !== null && _d !== void 0 ? _d : context.request.variant);
|
|
65
|
+
context.blocks.unshift({
|
|
66
|
+
name,
|
|
67
|
+
version,
|
|
68
|
+
variant,
|
|
69
|
+
incomingPath: node_path_1.default.join(context.packagePath, 'variants', variant),
|
|
70
|
+
});
|
|
71
|
+
pushToResult(name, version, variant, alias, context);
|
|
72
|
+
const incomingPath = node_path_1.default.join(context.packagePath, 'variants', root);
|
|
73
|
+
context.incomingConfig = undefined;
|
|
74
|
+
yield context.commonFlow(name, version, root, undefined, incomingPath, context);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (root.length > 0) {
|
|
79
|
+
context.result = {
|
|
80
|
+
name,
|
|
81
|
+
version,
|
|
82
|
+
provides: [root],
|
|
83
|
+
};
|
|
84
|
+
const incomingPath = node_path_1.default.join(context.packagePath, 'variants', root);
|
|
85
|
+
context.incomingConfig = undefined;
|
|
86
|
+
yield context.commonFlow(name, version, root, undefined, incomingPath, context);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
context.result = { name, version };
|
|
90
|
+
yield context.commonFlow(name, version, undefined, undefined, context.incomingPath, context);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.executeFirstBlock = executeFirstBlock;
|
|
95
|
+
function pushToResult(name, version, variant, alias, context) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
var _c;
|
|
98
|
+
(_a = context.result) !== null && _a !== void 0 ? _a : (context.result = {
|
|
99
|
+
name,
|
|
100
|
+
version,
|
|
101
|
+
requires: [context.request.variant],
|
|
102
|
+
});
|
|
103
|
+
const provider = context.incomingVariant !== context.request.variant;
|
|
104
|
+
if (provider || alias) {
|
|
105
|
+
(_b = (_c = context.result).provides) !== null && _b !== void 0 ? _b : (_c.provides = []);
|
|
106
|
+
if (provider) {
|
|
107
|
+
context.result.provides.unshift(context.incomingVariant);
|
|
108
|
+
}
|
|
109
|
+
if (alias) {
|
|
110
|
+
context.result.provides.unshift(variant);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.executeNextBlock = void 0;
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
function executeNextBlock(context) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const block = context.blocks.shift();
|
|
17
|
+
if (!(0, lodash_1.isNil)(block)) {
|
|
18
|
+
const { name, version, variant, branch, incomingPath } = block;
|
|
19
|
+
yield context.commonFlow(name, version, variant, branch, incomingPath, context);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.executeNextBlock = executeNextBlock;
|
package/lib/steps/index.js
CHANGED
|
@@ -11,51 +11,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.composeSteps = exports.steps = void 0;
|
|
13
13
|
const apply_formatting_1 = require("./apply-formatting");
|
|
14
|
+
const configure_branches_1 = require("./configure-branches");
|
|
15
|
+
const configure_install_file_actions_1 = require("./configure-install-file-actions");
|
|
16
|
+
const configure_update_file_actions_1 = require("./configure-update-file-actions");
|
|
14
17
|
const copy_binary_files_1 = require("./copy-binary-files");
|
|
18
|
+
const execute_first_block_1 = require("./execute-first-block");
|
|
19
|
+
const execute_next_block_1 = require("./execute-next-block");
|
|
15
20
|
const insert_final_new_line_1 = require("./insert-final-new-line");
|
|
16
21
|
const merge_text_files_1 = require("./merge-text-files");
|
|
17
22
|
const read_editor_config_1 = require("./read-editor-config");
|
|
18
23
|
const read_files_1 = require("./read-files");
|
|
19
24
|
const read_incoming_config_1 = require("./read-incoming-config");
|
|
20
25
|
const read_incoming_package_1 = require("./read-incoming-package");
|
|
26
|
+
const remove_files_1 = require("./remove-files");
|
|
21
27
|
const replace_templates_1 = require("./replace-templates");
|
|
22
28
|
const validate_newer_package_1 = require("./validate-newer-package");
|
|
23
29
|
const validate_not_present_package_1 = require("./validate-not-present-package");
|
|
24
|
-
const validate_updatability_1 = require("./validate-updatability");
|
|
25
30
|
const write_text_files_1 = require("./write-text-files");
|
|
26
31
|
exports.steps = {
|
|
27
32
|
applyFormatting: apply_formatting_1.applyFormatting,
|
|
33
|
+
configureBranches: configure_branches_1.configureBranches,
|
|
34
|
+
configureInstallFileActions: configure_install_file_actions_1.configureInstallFileActions,
|
|
35
|
+
configureUpdateFileActions: configure_update_file_actions_1.configureUpdateFileActions,
|
|
28
36
|
copyBinaryFiles: copy_binary_files_1.copyBinaryFiles,
|
|
37
|
+
executeFirstBlock: execute_first_block_1.executeFirstBlock,
|
|
38
|
+
executeNextBlock: execute_next_block_1.executeNextBlock,
|
|
29
39
|
insertFinalNewLine: insert_final_new_line_1.insertFinalNewLine,
|
|
30
40
|
mergeTextFiles: merge_text_files_1.mergeTextFiles,
|
|
31
41
|
readEditorConfig: read_editor_config_1.readEditorConfig,
|
|
32
42
|
readFiles: read_files_1.readFiles,
|
|
33
43
|
readIncomingConfig: read_incoming_config_1.readIncomingConfig,
|
|
34
44
|
readIncomingPackage: read_incoming_package_1.readIncomingPackage,
|
|
45
|
+
removeFiles: remove_files_1.removeFiles,
|
|
35
46
|
replaceTemplates: replace_templates_1.replaceTemplates,
|
|
36
47
|
validateNewerPackage: validate_newer_package_1.validateNewerPackage,
|
|
37
48
|
validateNotPresentPackage: validate_not_present_package_1.validateNotPresentPackage,
|
|
38
|
-
validateUpdatability: validate_updatability_1.validateUpdatability,
|
|
39
49
|
writeTextFiles: write_text_files_1.writeTextFiles,
|
|
40
50
|
};
|
|
41
|
-
function composeSteps(
|
|
42
|
-
|
|
51
|
+
function composeSteps(validations, processes) {
|
|
52
|
+
const mainFlow = (targetPath, incomingPath, request, config, options) => __awaiter(this, void 0, void 0, function* () {
|
|
43
53
|
const context = {
|
|
54
|
+
packagePath: incomingPath,
|
|
55
|
+
request,
|
|
44
56
|
targetPath,
|
|
45
57
|
incomingPath,
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
incomingVariant: request.variant,
|
|
59
|
+
onExisting: () => 'merge',
|
|
60
|
+
onMissing: () => 'continue',
|
|
48
61
|
filters: () => undefined,
|
|
49
62
|
routes: () => undefined,
|
|
50
63
|
binaryFiles: [],
|
|
51
64
|
textFiles: [],
|
|
52
65
|
mergedTextFiles: [],
|
|
66
|
+
removedPatterns: [],
|
|
53
67
|
formats: [],
|
|
54
68
|
config,
|
|
55
69
|
options,
|
|
70
|
+
commonFlow,
|
|
71
|
+
blocks: [],
|
|
56
72
|
};
|
|
57
73
|
let skipped = false;
|
|
58
|
-
for (const step of
|
|
74
|
+
for (const step of validations) {
|
|
59
75
|
if (yield step(context)) {
|
|
60
76
|
skipped = true;
|
|
61
77
|
break;
|
|
@@ -63,5 +79,27 @@ function composeSteps(...steps) {
|
|
|
63
79
|
}
|
|
64
80
|
return skipped ? undefined : context;
|
|
65
81
|
});
|
|
82
|
+
const commonFlow = (name, version, variant, branch, incomingPath, mainContext) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (mainContext.options.verbose) {
|
|
84
|
+
let message = `--> ${name}@${version}`;
|
|
85
|
+
if (variant) {
|
|
86
|
+
message += `:${variant}`;
|
|
87
|
+
}
|
|
88
|
+
if (branch) {
|
|
89
|
+
message += `(${branch})`;
|
|
90
|
+
}
|
|
91
|
+
console.log(message);
|
|
92
|
+
}
|
|
93
|
+
const context = Object.assign(Object.assign({}, mainContext), { incomingPath, incomingName: name, incomingVersion: version, incomingVariant: variant, incomingBranch: branch, incomingConfig: undefined, onExisting: () => 'merge', onMissing: () => 'continue', filters: () => undefined, routes: () => undefined, binaryFiles: [], textFiles: [], mergedTextFiles: [], formats: [] });
|
|
94
|
+
let skipped = false;
|
|
95
|
+
for (const step of processes) {
|
|
96
|
+
if (yield step(context)) {
|
|
97
|
+
skipped = true;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return skipped ? undefined : context;
|
|
102
|
+
});
|
|
103
|
+
return { mainFlow, commonFlow };
|
|
66
104
|
}
|
|
67
105
|
exports.composeSteps = composeSteps;
|
|
@@ -16,7 +16,7 @@ exports.mergeTextFiles = void 0;
|
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
18
|
const journeys_1 = require("../journeys");
|
|
19
|
-
function mergeTextFiles({ targetPath, textFiles, mergedTextFiles,
|
|
19
|
+
function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onExisting, onMissing, filters, routes, options }) {
|
|
20
20
|
var _a;
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
for (const file of textFiles) {
|
|
@@ -28,50 +28,80 @@ function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, onMissing, onU
|
|
|
28
28
|
if (options.verbose) {
|
|
29
29
|
console.log(`${file.name}, no merger has been found`);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const filePath = path_1.default.join(targetPath, file.name);
|
|
32
|
+
const exists = yield fs_extra_1.default.pathExists(filePath);
|
|
33
|
+
if (exists) {
|
|
34
|
+
switch (onExisting(file.name)) {
|
|
35
|
+
case 'merge':
|
|
36
|
+
break;
|
|
37
|
+
case 'overwrite':
|
|
38
|
+
break;
|
|
39
|
+
case 'skip':
|
|
40
|
+
continue;
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
continue
|
|
43
|
+
else {
|
|
44
|
+
switch (onMissing(file.name)) {
|
|
45
|
+
case 'continue':
|
|
46
|
+
break;
|
|
47
|
+
case 'skip':
|
|
48
|
+
continue;
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
mergedTextFiles.push(file);
|
|
52
|
+
if (options.verbose) {
|
|
53
|
+
console.log(`${file.name} has been copied`);
|
|
54
|
+
}
|
|
43
55
|
continue;
|
|
44
56
|
}
|
|
45
57
|
if (options.verbose) {
|
|
46
58
|
console.log(`${file.name}, a merger has been found`);
|
|
47
59
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
const fileName = journey.alias ? path_1.default.join(path_1.default.dirname(file.name), journey.alias) : file.name;
|
|
61
|
+
const filePath = path_1.default.join(targetPath, fileName);
|
|
62
|
+
const exists = yield fs_extra_1.default.pathExists(filePath);
|
|
63
|
+
if (exists) {
|
|
64
|
+
switch (onExisting(file.name)) {
|
|
65
|
+
case 'merge': {
|
|
66
|
+
const currentData = yield fs_extra_1.default.readFile(filePath, 'utf-8');
|
|
67
|
+
const data = journey.travel({
|
|
68
|
+
current: currentData,
|
|
69
|
+
incoming: file.data,
|
|
70
|
+
filters: filters(file.name),
|
|
71
|
+
});
|
|
72
|
+
mergedTextFiles.push({
|
|
73
|
+
name: fileName,
|
|
74
|
+
data,
|
|
75
|
+
finalNewLine: file.finalNewLine,
|
|
76
|
+
mode: file.mode,
|
|
77
|
+
});
|
|
78
|
+
if (options.verbose) {
|
|
79
|
+
console.log(`${file.name} has been merged`);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'overwrite':
|
|
84
|
+
mergedTextFiles.push(file);
|
|
85
|
+
if (options.verbose) {
|
|
86
|
+
console.log(`${file.name} has been overwritten`);
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
case 'skip':
|
|
90
|
+
continue;
|
|
54
91
|
}
|
|
55
92
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
continue
|
|
93
|
+
else {
|
|
94
|
+
switch (onMissing(file.name)) {
|
|
95
|
+
case 'continue':
|
|
96
|
+
mergedTextFiles.push(Object.assign(Object.assign({}, file), { name: fileName }));
|
|
97
|
+
if (options.verbose) {
|
|
98
|
+
console.log(`${file.name} has been copied`);
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
case 'skip':
|
|
102
|
+
continue;
|
|
59
103
|
}
|
|
60
104
|
}
|
|
61
|
-
const data = journey.travel({
|
|
62
|
-
current: currentData,
|
|
63
|
-
incoming: file.data,
|
|
64
|
-
filters: filters(file.name),
|
|
65
|
-
});
|
|
66
|
-
mergedTextFiles.push({
|
|
67
|
-
name,
|
|
68
|
-
data,
|
|
69
|
-
finalNewLine: file.finalNewLine,
|
|
70
|
-
mode: file.mode,
|
|
71
|
-
});
|
|
72
|
-
if (options.verbose) {
|
|
73
|
-
console.log(`${file.name} has been merged`);
|
|
74
|
-
}
|
|
75
105
|
}
|
|
76
106
|
});
|
|
77
107
|
}
|
|
@@ -10,11 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.readIncomingConfig = void 0;
|
|
13
|
-
const
|
|
13
|
+
const configs_1 = require("../configs");
|
|
14
14
|
function readIncomingConfig(context) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (!context.incomingConfig) {
|
|
17
|
+
const config = yield (0, configs_1.readPackageConfig)(context.incomingPath);
|
|
18
|
+
if (!config) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
context.incomingConfig = config;
|
|
22
|
+
}
|
|
18
23
|
});
|
|
19
24
|
}
|
|
20
25
|
exports.readIncomingConfig = readIncomingConfig;
|
|
@@ -15,13 +15,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.readIncomingPackage = void 0;
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
18
19
|
function readIncomingPackage(context) {
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
21
|
const filePath = path_1.default.resolve(context.incomingPath, './package.json');
|
|
21
|
-
|
|
22
|
-
if (!
|
|
22
|
+
const incomingPackage = yield fs_extra_1.default.readJSON(filePath);
|
|
23
|
+
if (!isPackageManifest(incomingPackage)) {
|
|
23
24
|
throw new Error('The package of the incoming artifact can\'t be found.');
|
|
24
25
|
}
|
|
26
|
+
context.incomingPackage = incomingPackage;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
exports.readIncomingPackage = readIncomingPackage;
|
|
30
|
+
function isPackageManifest(value) {
|
|
31
|
+
if ((0, lodash_1.isNil)(value) || !(0, lodash_1.isPlainObject)(value)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const manifest = value;
|
|
35
|
+
return typeof manifest.name === 'string' && typeof manifest.version === 'string';
|
|
36
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.removeFiles = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const globby_1 = __importDefault(require("globby"));
|
|
19
|
+
const micromatch_1 = require("micromatch");
|
|
20
|
+
function removeFiles({ removedPatterns, targetPath, options }) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (removedPatterns.length === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const cwd = path_1.default.join(targetPath);
|
|
26
|
+
const files = yield (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*', '!.git'], {
|
|
27
|
+
cwd,
|
|
28
|
+
dot: true,
|
|
29
|
+
});
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
if ((0, micromatch_1.isMatch)(file, removedPatterns)) {
|
|
32
|
+
const filePath = path_1.default.join(cwd, file);
|
|
33
|
+
yield fs_extra_1.default.unlink(filePath);
|
|
34
|
+
if (options.verbose) {
|
|
35
|
+
console.log(`${file} has been removed`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.removeFiles = removeFiles;
|
|
@@ -16,7 +16,7 @@ function validateNewerPackage({ incomingPackage, config, options }) {
|
|
|
16
16
|
if (options.force) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
const artifact = config.artifacts
|
|
19
|
+
const artifact = config.artifacts[incomingPackage.name];
|
|
20
20
|
if (artifact) {
|
|
21
21
|
return !(0, semver_1.gt)(incomingPackage.version, artifact.version);
|
|
22
22
|
}
|
|
@@ -16,7 +16,7 @@ function validateNotPresentPackage({ incomingPackage, config, options }) {
|
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
const { name } = incomingPackage;
|
|
19
|
-
const artifact = config.artifacts
|
|
19
|
+
const artifact = config.artifacts[name];
|
|
20
20
|
if (artifact) {
|
|
21
21
|
if (options.skip) {
|
|
22
22
|
if (options.verbose) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveRequest = void 0;
|
|
7
|
+
const untildify_1 = __importDefault(require("untildify"));
|
|
8
|
+
function resolveRequest(spec) {
|
|
9
|
+
if (spec.startsWith('~')) {
|
|
10
|
+
spec = (0, untildify_1.default)(spec);
|
|
11
|
+
}
|
|
12
|
+
else if (spec.startsWith('/')) {
|
|
13
|
+
// skip
|
|
14
|
+
}
|
|
15
|
+
else if (spec.includes('/')) {
|
|
16
|
+
const [scope, name] = spec.split('/');
|
|
17
|
+
if (name.startsWith('artifact-')) {
|
|
18
|
+
// skip
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
spec = `${scope}/artifact-${name}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (spec.startsWith('artifact-')) {
|
|
26
|
+
// skip
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
spec = `artifact-${spec}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (spec.includes(':')) {
|
|
33
|
+
const [name, variant] = spec.split(':');
|
|
34
|
+
if (variant.length === 0) {
|
|
35
|
+
throw new Error(`Missing variant in "${spec}"`);
|
|
36
|
+
}
|
|
37
|
+
return { name, variant };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return { name: spec };
|
|
41
|
+
}
|
|
42
|
+
} // }}}
|
|
43
|
+
exports.resolveRequest = resolveRequest;
|
package/lib/utils/template.js
CHANGED
|
@@ -31,6 +31,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
31
31
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
32
32
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
33
33
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
34
|
+
const lodash_1 = require("lodash");
|
|
34
35
|
const YAML = __importStar(require("../parsers/yaml"));
|
|
35
36
|
const try_json_1 = require("./try-json");
|
|
36
37
|
dayjs_1.default.extend(utc_1.default);
|
|
@@ -58,7 +59,7 @@ class TemplateEngine {
|
|
|
58
59
|
}
|
|
59
60
|
const fileContent = this.readConfigFile(name);
|
|
60
61
|
const value = this.getValueByPath(fileContent, propertyPath);
|
|
61
|
-
if (
|
|
62
|
+
if ((0, lodash_1.isNil)(value)) {
|
|
62
63
|
throw new TemplateError(placeholder);
|
|
63
64
|
}
|
|
64
65
|
return String(value);
|
|
@@ -68,12 +69,12 @@ class TemplateEngine {
|
|
|
68
69
|
const parts = propertyPath.split('.');
|
|
69
70
|
let current = values;
|
|
70
71
|
for (const part of parts) {
|
|
71
|
-
if (
|
|
72
|
+
if (!(0, lodash_1.isPlainObject)(current)) {
|
|
72
73
|
throw new TemplateError(`Property path not found: ${propertyPath}`);
|
|
73
74
|
}
|
|
74
75
|
current = current[part];
|
|
75
76
|
}
|
|
76
|
-
if (
|
|
77
|
+
if ((0, lodash_1.isNil)(current)) {
|
|
77
78
|
throw new TemplateError(`Property not found: ${propertyPath}`);
|
|
78
79
|
}
|
|
79
80
|
return current;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zokugun/artifact",
|
|
3
3
|
"description": "Boilerplate your project & keep your configurations up to date",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Baptiste Augrain",
|
|
7
7
|
"email": "daiyam@zokugun.org"
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"release": "release-it",
|
|
29
29
|
"test": "tsc -p test && mocha",
|
|
30
30
|
"test:dev": "mocha",
|
|
31
|
-
"test:watch": "tsc-watch -p test --onSuccess 'mocha'",
|
|
32
|
-
"watch": "tsc-watch -p src",
|
|
31
|
+
"test:watch": "tsc-watch -p src -p test --onSuccess 'mocha'",
|
|
33
32
|
"watch:src": "tsc-watch -p src",
|
|
34
33
|
"watch:test": "tsc-watch -p test"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
36
|
+
"@zokugun/configdotts-merge": "^0.1.0",
|
|
37
37
|
"ansi-colors": "^4.1.1",
|
|
38
38
|
"commander": "^9.0.0",
|
|
39
39
|
"dayjs": "^1.11.13",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"pacote": "^13.0.5",
|
|
51
51
|
"semver": "^7.3.5",
|
|
52
52
|
"tempy": "^1.0.1",
|
|
53
|
+
"untildify": "^4.0.0",
|
|
53
54
|
"yaml": "^1.10.2"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
package/lib/config/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeConfig = exports.readConfig = void 0;
|
|
4
|
-
var read_config_1 = require("./read-config");
|
|
5
|
-
Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return read_config_1.readConfig; } });
|
|
6
|
-
var write_config_1 = require("./write-config");
|
|
7
|
-
Object.defineProperty(exports, "writeConfig", { enumerable: true, get: function () { return write_config_1.writeConfig; } });
|