@zokugun/artifact 0.4.1 → 0.4.3
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/cli.js +2 -0
- package/lib/commands/add.js +2 -1
- package/lib/commands/update.js +2 -1
- package/lib/configs/install/write-install-config.js +4 -2
- package/lib/steps/configure-branches.js +9 -1
- package/lib/steps/copy-binary-files.js +4 -2
- package/lib/steps/index.js +3 -2
- package/lib/steps/remove-files.js +4 -2
- package/lib/steps/write-text-files.js +16 -7
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -13,12 +13,14 @@ program
|
|
|
13
13
|
program
|
|
14
14
|
.command('add')
|
|
15
15
|
.description('add an artifact to the current project')
|
|
16
|
+
.option('-d, --dry-run', 'fake install')
|
|
16
17
|
.option('-v, --verbose', 'output more details')
|
|
17
18
|
.argument('<artifacts...>')
|
|
18
19
|
.action(commands_1.add);
|
|
19
20
|
program
|
|
20
21
|
.command('update')
|
|
21
22
|
.description('update the current project using the installed artifacts')
|
|
23
|
+
.option('-d, --dry-run', 'fake update')
|
|
22
24
|
.option('-v, --verbose', 'output more details')
|
|
23
25
|
.alias('up')
|
|
24
26
|
.action(commands_1.update);
|
package/lib/commands/add.js
CHANGED
|
@@ -44,7 +44,7 @@ const { mainFlow } = (0, steps_1.composeSteps)([
|
|
|
44
44
|
]);
|
|
45
45
|
function add(specs, inputOptions) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
var _a, _b, _c;
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
48
|
yield npm_1.default.load();
|
|
49
49
|
const registry = npm_1.default.config.get('registry');
|
|
50
50
|
const targetPath = process_1.default.env.INIT_CWD;
|
|
@@ -52,6 +52,7 @@ function add(specs, inputOptions) {
|
|
|
52
52
|
force: (_a = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.force) !== null && _a !== void 0 ? _a : false,
|
|
53
53
|
skip: (_b = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.skip) !== null && _b !== void 0 ? _b : false,
|
|
54
54
|
verbose: (_c = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.verbose) !== null && _c !== void 0 ? _c : false,
|
|
55
|
+
dryRun: (_d = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.dryRun) !== null && _d !== void 0 ? _d : false,
|
|
55
56
|
};
|
|
56
57
|
const { config, configStats } = yield (0, configs_1.readInstallConfig)(targetPath);
|
|
57
58
|
for (const spec of specs) {
|
package/lib/commands/update.js
CHANGED
|
@@ -45,7 +45,7 @@ const { mainFlow } = (0, steps_1.composeSteps)([
|
|
|
45
45
|
]);
|
|
46
46
|
function update(inputOptions) {
|
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
var _a, _b;
|
|
48
|
+
var _a, _b, _c;
|
|
49
49
|
// @ts-expect-error log property isn't exposed
|
|
50
50
|
npm_1.default.log.stream = (0, dev_null_1.createDevNull)();
|
|
51
51
|
yield npm_1.default.load();
|
|
@@ -55,6 +55,7 @@ function update(inputOptions) {
|
|
|
55
55
|
force: (_a = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.force) !== null && _a !== void 0 ? _a : false,
|
|
56
56
|
skip: false,
|
|
57
57
|
verbose: (_b = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.verbose) !== null && _b !== void 0 ? _b : false,
|
|
58
|
+
dryRun: (_c = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.dryRun) !== null && _c !== void 0 ? _c : false,
|
|
58
59
|
};
|
|
59
60
|
const { config, configStats } = yield (0, configs_1.readInstallConfig)(targetPath);
|
|
60
61
|
for (const [name, artifact] of Object.entries(config.artifacts)) {
|
|
@@ -34,8 +34,10 @@ function writeInstallConfig(config_1, _a, formats_1, targetPath_1, options_1) {
|
|
|
34
34
|
};
|
|
35
35
|
yield (0, insert_final_new_line_1.insertFinalNewLine)({ mergedTextFiles: [file] });
|
|
36
36
|
yield (0, apply_formatting_1.applyFormatting)({ mergedTextFiles: [file], formats });
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (!options.dryRun) {
|
|
38
|
+
const filePath = path_1.default.join(targetPath, name);
|
|
39
|
+
yield fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
|
|
40
|
+
}
|
|
39
41
|
if (options.verbose) {
|
|
40
42
|
console.log(`${name} has been written`);
|
|
41
43
|
}
|
|
@@ -29,7 +29,7 @@ function configureBranches(context) {
|
|
|
29
29
|
const match = /^\[(@[\w-]+:[\w-]+|[\w-]+)(?::([\w-]+))?]$/.exec(directory);
|
|
30
30
|
if (match) {
|
|
31
31
|
const [branch, name, variant] = match;
|
|
32
|
-
const packageName = name.replace(
|
|
32
|
+
const packageName = name.replace(/:(artifact-)?/g, '/artifact-');
|
|
33
33
|
const artifact = context.config.artifacts[packageName];
|
|
34
34
|
let found = false;
|
|
35
35
|
if (artifact) {
|
|
@@ -53,6 +53,9 @@ function configureBranches(context) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
if (found) {
|
|
56
|
+
if (context.options.verbose) {
|
|
57
|
+
console.log(`- branch: ${name}${variant ? `:${variant}` : ''} has been matched`);
|
|
58
|
+
}
|
|
56
59
|
bucket.push({
|
|
57
60
|
name: context.incomingName,
|
|
58
61
|
version: context.incomingVersion,
|
|
@@ -61,6 +64,11 @@ function configureBranches(context) {
|
|
|
61
64
|
incomingPath: node_path_1.default.join(cwd, directory),
|
|
62
65
|
});
|
|
63
66
|
}
|
|
67
|
+
else {
|
|
68
|
+
if (context.options.verbose) {
|
|
69
|
+
console.log(`- branch: ${name}${variant ? `:${variant}` : ''} hasn't been matched (${artifact ? 'variant' : 'artifact'} not found)`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
context.blocks.unshift(...bucket);
|
|
@@ -40,8 +40,10 @@ function copyBinaryFiles(_a) {
|
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (!options.dryRun) {
|
|
44
|
+
yield fs_extra_1.default.ensureFile(target);
|
|
45
|
+
yield fs_extra_1.default.copyFile(source, target);
|
|
46
|
+
}
|
|
45
47
|
if (options.verbose) {
|
|
46
48
|
console.log(`${file.target} has been written as a binary file`);
|
|
47
49
|
}
|
package/lib/steps/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.steps = void 0;
|
|
13
13
|
exports.composeSteps = composeSteps;
|
|
14
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
14
15
|
const apply_formatting_1 = require("./apply-formatting");
|
|
15
16
|
const configure_branches_1 = require("./configure-branches");
|
|
16
17
|
const configure_install_file_actions_1 = require("./configure-install-file-actions");
|
|
@@ -82,14 +83,14 @@ function composeSteps(validations, processes) {
|
|
|
82
83
|
});
|
|
83
84
|
const commonFlow = (name, version, variant, branch, incomingPath, mainContext) => __awaiter(this, void 0, void 0, function* () {
|
|
84
85
|
if (mainContext.options.verbose) {
|
|
85
|
-
let message =
|
|
86
|
+
let message = `${name} version=${version}`;
|
|
86
87
|
if (variant) {
|
|
87
88
|
message += ` variant=${variant}`;
|
|
88
89
|
}
|
|
89
90
|
if (branch) {
|
|
90
91
|
message += ` branch=${branch}`;
|
|
91
92
|
}
|
|
92
|
-
console.log(message);
|
|
93
|
+
console.log((0, ansi_colors_1.bgBlue)(`\n=== ${message} ===\n`));
|
|
93
94
|
}
|
|
94
95
|
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: [] });
|
|
95
96
|
let skipped = false;
|
|
@@ -29,8 +29,10 @@ function removeFiles(_a) {
|
|
|
29
29
|
});
|
|
30
30
|
for (const file of files) {
|
|
31
31
|
if ((0, micromatch_1.isMatch)(file, removedPatterns)) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (!options.dryRun) {
|
|
33
|
+
const filePath = path_1.default.join(cwd, file);
|
|
34
|
+
yield fs_extra_1.default.unlink(filePath);
|
|
35
|
+
}
|
|
34
36
|
if (options.verbose) {
|
|
35
37
|
console.log(`${file} has been removed`);
|
|
36
38
|
}
|
|
@@ -17,14 +17,23 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
17
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
18
|
function writeTextFiles(_a) {
|
|
19
19
|
return __awaiter(this, arguments, void 0, function* ({ mergedTextFiles, targetPath, options }) {
|
|
20
|
-
|
|
21
|
-
const filePath = path_1.default.join(targetPath, file.name);
|
|
22
|
-
yield fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
|
|
23
|
-
if (file.mode) {
|
|
24
|
-
yield fs_extra_1.default.chmod(filePath, file.mode);
|
|
25
|
-
}
|
|
20
|
+
if (options.dryRun) {
|
|
26
21
|
if (options.verbose) {
|
|
27
|
-
|
|
22
|
+
for (const file of mergedTextFiles) {
|
|
23
|
+
console.log(`${file.name} has been written as a text file`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
for (const file of mergedTextFiles) {
|
|
29
|
+
const filePath = path_1.default.join(targetPath, file.name);
|
|
30
|
+
yield fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
|
|
31
|
+
if (file.mode) {
|
|
32
|
+
yield fs_extra_1.default.chmod(filePath, file.mode);
|
|
33
|
+
}
|
|
34
|
+
if (options.verbose) {
|
|
35
|
+
console.log(`${file.name} has been written as a text file`);
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
});
|