@zokugun/artifact 0.1.0 → 0.2.2
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 +13 -6
- package/lib/cli.js +7 -2
- package/lib/commands/add.js +43 -9
- package/lib/commands/index.js +7 -0
- package/lib/commands/update.js +73 -0
- package/lib/compositors/compose.js +13 -5
- package/lib/compositors/index.js +3 -1
- package/lib/compositors/json.js +9 -5
- package/lib/compositors/map-sort.js +16 -0
- package/lib/compositors/rc.js +14 -4
- package/lib/compositors/yaml.js +8 -2
- package/lib/config/index.js +7 -0
- package/lib/{steps/read-target-config.js → config/read-config.js} +31 -14
- package/lib/config/write-config.js +44 -0
- package/lib/journeys/default/index.js +1 -1
- package/lib/journeys/fixpack/index.js +16 -0
- package/lib/journeys/index.js +7 -3
- package/lib/journeys/package/index.js +14 -14
- package/lib/journeys/rc/index.js +1 -1
- package/lib/journeys/tsconfig/index.js +20 -0
- package/lib/routes/command.js +30 -5
- package/lib/routes/index.js +5 -3
- package/lib/routes/lines-concat.js +1 -1
- package/lib/routes/list-sort-concat.js +42 -0
- package/lib/routes/{hash.js → map-concat.js} +3 -3
- package/lib/routes/overwrite.js +1 -1
- package/lib/routes/primitive.js +2 -2
- package/lib/steps/apply-formatting.js +1 -1
- package/lib/steps/copy-binary-files.js +12 -1
- package/lib/steps/index.js +29 -6
- package/lib/steps/merge-text-files.js +22 -7
- package/lib/steps/read-editor-config.js +6 -2
- package/lib/steps/read-files.js +10 -10
- package/lib/steps/read-incoming-config.js +20 -0
- package/lib/steps/read-incoming-package.js +3 -0
- package/lib/steps/validate-newer-package.js +25 -0
- package/lib/steps/validate-not-present-package.js +33 -0
- package/lib/steps/validate-updatability.js +160 -0
- package/lib/{utils/command → types}/command.js +0 -0
- package/lib/utils/command/join-command.js +6 -1
- package/lib/utils/dev-null.js +8 -0
- package/lib/utils/read-buffer.js +1 -1
- package/package.json +16 -8
- package/lib/install.js +0 -32
- package/lib/steps/update-target-config.js +0 -50
package/README.md
CHANGED
|
@@ -63,16 +63,23 @@ artifact-configs/base/
|
|
|
63
63
|
└── README.md
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
Update
|
|
67
67
|
------
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Update your configurations with the command:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
artifact update
|
|
73
|
+
```
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
----------
|
|
75
|
+
It is **recommended** to review the changes and manually revert any bad changes.
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
Furthermore, a configuration package can control how to apply an update via the file `.artifactrc`.
|
|
78
|
+
|
|
79
|
+
Yeoman
|
|
80
|
+
------
|
|
81
|
+
|
|
82
|
+
`artifact` can be used in a yeoman generator. Ex: [@daiyam/generator-new-project](https://github.com/daiyam/generator-new-project)
|
|
76
83
|
|
|
77
84
|
Donations
|
|
78
85
|
---------
|
package/lib/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
8
|
-
const
|
|
8
|
+
const commands_1 = require("./commands");
|
|
9
9
|
const program = new commander_1.Command();
|
|
10
10
|
program.version(package_json_1.default.version);
|
|
11
11
|
program
|
|
@@ -13,5 +13,10 @@ program
|
|
|
13
13
|
.description('add an artifact to the current project')
|
|
14
14
|
.option('-v, --verbose', 'output more details')
|
|
15
15
|
.argument('<artifacts...>')
|
|
16
|
-
.action(
|
|
16
|
+
.action(commands_1.add);
|
|
17
|
+
program
|
|
18
|
+
.command('update')
|
|
19
|
+
.description('update the current project using the installed artifact')
|
|
20
|
+
.option('-v, --verbose', 'output more details')
|
|
21
|
+
.action(commands_1.update);
|
|
17
22
|
program.parse();
|
package/lib/commands/add.js
CHANGED
|
@@ -14,10 +14,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.add = void 0;
|
|
16
16
|
const process_1 = __importDefault(require("process"));
|
|
17
|
+
const npm_1 = __importDefault(require("npm"));
|
|
17
18
|
const pacote_1 = __importDefault(require("pacote"));
|
|
18
19
|
const tempy_1 = __importDefault(require("tempy"));
|
|
19
|
-
const
|
|
20
|
-
const
|
|
20
|
+
const config_1 = require("../config");
|
|
21
|
+
const steps_1 = require("../steps");
|
|
22
|
+
const commonFlow = (0, steps_1.composeSteps)(steps_1.steps.readIncomingPackage, steps_1.steps.validateNotPresentPackage, steps_1.steps.readFiles, steps_1.steps.readEditorConfig, steps_1.steps.mergeTextFiles, steps_1.steps.insertFinalNewLine, steps_1.steps.applyFormatting, steps_1.steps.copyBinaryFiles, steps_1.steps.writeTextFiles);
|
|
21
23
|
function expandSpec(spec) {
|
|
22
24
|
if (spec.includes('/')) {
|
|
23
25
|
const [scope, name] = spec.split('/');
|
|
@@ -37,20 +39,52 @@ function expandSpec(spec) {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
} // }}}
|
|
40
|
-
function add(specs,
|
|
42
|
+
function add(specs, inputOptions) {
|
|
43
|
+
var _a, _b, _c;
|
|
41
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
45
|
yield npm_1.default.load();
|
|
43
46
|
const registry = npm_1.default.config.get('registry');
|
|
44
47
|
const targetPath = process_1.default.env.INIT_CWD;
|
|
48
|
+
const options = {
|
|
49
|
+
force: (_a = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.force) !== null && _a !== void 0 ? _a : false,
|
|
50
|
+
skip: (_b = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.skip) !== null && _b !== void 0 ? _b : false,
|
|
51
|
+
verbose: (_c = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.verbose) !== null && _c !== void 0 ? _c : false,
|
|
52
|
+
};
|
|
53
|
+
const [config, configStats] = yield (0, config_1.readConfig)(targetPath);
|
|
45
54
|
for (const spec of specs) {
|
|
46
55
|
const dir = tempy_1.default.directory();
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
49
|
-
|
|
56
|
+
const pkgResult = yield pacote_1.default.extract(expandSpec(spec), dir, { registry });
|
|
57
|
+
if (!pkgResult.resolved) {
|
|
58
|
+
if (options.force || options.skip) {
|
|
59
|
+
if (options.verbose) {
|
|
60
|
+
console.log(`The artifact '${spec}' couldn't be found, skipping...`);
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error(pkgResult.from);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const flowResult = yield commonFlow(targetPath, dir, config, options);
|
|
69
|
+
if (!flowResult) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const { name, version } = flowResult.incomingPackage;
|
|
73
|
+
let nf = true;
|
|
74
|
+
for (const artifact of config.artifacts) {
|
|
75
|
+
if (artifact.name === name) {
|
|
76
|
+
artifact.version = version;
|
|
77
|
+
nf = false;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (nf) {
|
|
82
|
+
config.artifacts.push({
|
|
83
|
+
name,
|
|
84
|
+
version,
|
|
85
|
+
});
|
|
50
86
|
}
|
|
51
|
-
yield (0,
|
|
52
|
-
verbose: options.verbose,
|
|
53
|
-
});
|
|
87
|
+
yield (0, config_1.writeConfig)(config, configStats, flowResult.formats, targetPath, options);
|
|
54
88
|
}
|
|
55
89
|
});
|
|
56
90
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.update = exports.add = void 0;
|
|
4
|
+
var add_1 = require("./add");
|
|
5
|
+
Object.defineProperty(exports, "add", { enumerable: true, get: function () { return add_1.add; } });
|
|
6
|
+
var update_1 = require("./update");
|
|
7
|
+
Object.defineProperty(exports, "update", { enumerable: true, get: function () { return update_1.update; } });
|
|
@@ -0,0 +1,73 @@
|
|
|
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.update = void 0;
|
|
16
|
+
const process_1 = __importDefault(require("process"));
|
|
17
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
18
|
+
const npm_1 = __importDefault(require("npm"));
|
|
19
|
+
const ora_1 = __importDefault(require("ora"));
|
|
20
|
+
const pacote_1 = __importDefault(require("pacote"));
|
|
21
|
+
const tempy_1 = __importDefault(require("tempy"));
|
|
22
|
+
const config_1 = require("../config");
|
|
23
|
+
const steps_1 = require("../steps");
|
|
24
|
+
const dev_null_1 = require("../utils/dev-null");
|
|
25
|
+
const commonFlow = (0, steps_1.composeSteps)(steps_1.steps.readIncomingPackage, steps_1.steps.validateNewerPackage, steps_1.steps.readIncomingConfig, steps_1.steps.validateUpdatability, steps_1.steps.readFiles, steps_1.steps.readEditorConfig, steps_1.steps.mergeTextFiles, steps_1.steps.insertFinalNewLine, steps_1.steps.applyFormatting, steps_1.steps.copyBinaryFiles, steps_1.steps.writeTextFiles);
|
|
26
|
+
function update(inputOptions) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
// @ts-expect-error log property isn't exposed
|
|
30
|
+
npm_1.default.log.stream = (0, dev_null_1.createDevNull)();
|
|
31
|
+
yield npm_1.default.load();
|
|
32
|
+
const registry = npm_1.default.config.get('registry');
|
|
33
|
+
const targetPath = process_1.default.env.INIT_CWD;
|
|
34
|
+
const options = {
|
|
35
|
+
force: (_a = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.force) !== null && _a !== void 0 ? _a : false,
|
|
36
|
+
skip: false,
|
|
37
|
+
verbose: (_b = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.verbose) !== null && _b !== void 0 ? _b : false,
|
|
38
|
+
};
|
|
39
|
+
const [config, configStats] = yield (0, config_1.readConfig)(targetPath);
|
|
40
|
+
for (const artifact of config.artifacts) {
|
|
41
|
+
const spinner = (0, ora_1.default)(`${ansi_colors_1.cyan.bold(artifact.name)}`).start();
|
|
42
|
+
const dir = tempy_1.default.directory();
|
|
43
|
+
const pkgResult = yield pacote_1.default.extract(artifact.name, dir, { registry });
|
|
44
|
+
if (!pkgResult.resolved) {
|
|
45
|
+
if (options.force) {
|
|
46
|
+
spinner.fail();
|
|
47
|
+
if (options.verbose) {
|
|
48
|
+
console.log(`The artifact '${artifact.name}' couldn't be found, skipping...`);
|
|
49
|
+
}
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(pkgResult.from);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const flowResult = yield commonFlow(targetPath, dir, config, options);
|
|
57
|
+
if (!flowResult) {
|
|
58
|
+
spinner.succeed();
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const { name, version } = flowResult.incomingPackage;
|
|
62
|
+
for (const artifact of config.artifacts) {
|
|
63
|
+
if (artifact.name === name) {
|
|
64
|
+
artifact.version = version;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
yield (0, config_1.writeConfig)(config, configStats, flowResult.formats, targetPath, options);
|
|
69
|
+
spinner.succeed();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.update = update;
|
|
@@ -30,20 +30,28 @@ function apply(map, keys, current, incoming, result) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
function compose(map) {
|
|
33
|
-
return ({ current, incoming }) => {
|
|
33
|
+
return ({ current, incoming, filters }) => {
|
|
34
34
|
if (incoming === undefined) {
|
|
35
35
|
return current !== null && current !== void 0 ? current : {};
|
|
36
36
|
}
|
|
37
37
|
if (current === undefined || typeof current !== typeof incoming) {
|
|
38
38
|
return incoming;
|
|
39
39
|
}
|
|
40
|
-
const result = {};
|
|
41
40
|
const currentKeys = Object.keys(current);
|
|
42
41
|
const incomingKeys = Object.keys(incoming);
|
|
43
42
|
const newKeys = (0, without_1.default)(incomingKeys, ...currentKeys);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (filters) {
|
|
44
|
+
const result = Object.assign({}, current);
|
|
45
|
+
apply(map, filters, current, incoming, result);
|
|
46
|
+
apply(map, newKeys, current, incoming, result);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const result = {};
|
|
51
|
+
apply(map, currentKeys, current, incoming, result);
|
|
52
|
+
apply(map, newKeys, current, incoming, result);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
47
55
|
};
|
|
48
56
|
}
|
|
49
57
|
exports.compose = compose;
|
package/lib/compositors/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.yaml = exports.rc = exports.json = exports.fork = exports.compose = void 0;
|
|
3
|
+
exports.yaml = exports.rc = exports.mapSort = exports.json = exports.fork = exports.compose = void 0;
|
|
4
4
|
var compose_1 = require("./compose");
|
|
5
5
|
Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.compose; } });
|
|
6
6
|
var fork_1 = require("./fork");
|
|
7
7
|
Object.defineProperty(exports, "fork", { enumerable: true, get: function () { return fork_1.fork; } });
|
|
8
8
|
var json_1 = require("./json");
|
|
9
9
|
Object.defineProperty(exports, "json", { enumerable: true, get: function () { return json_1.json; } });
|
|
10
|
+
var map_sort_1 = require("./map-sort");
|
|
11
|
+
Object.defineProperty(exports, "mapSort", { enumerable: true, get: function () { return map_sort_1.mapSort; } });
|
|
10
12
|
var rc_1 = require("./rc");
|
|
11
13
|
Object.defineProperty(exports, "rc", { enumerable: true, get: function () { return rc_1.rc; } });
|
|
12
14
|
var yaml_1 = require("./yaml");
|
package/lib/compositors/json.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -35,21 +39,21 @@ function tryJson(value) {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
const merge = (0, compose_1.compose)({
|
|
38
|
-
$$default: (0, fork_1.fork)([Array.isArray, routes_1.listConcat], [lodash_1.isPlainObject,
|
|
42
|
+
$$default: (0, fork_1.fork)([Array.isArray, routes_1.listConcat], [lodash_1.isPlainObject, (...args) => merge(...args)], routes_1.primitive),
|
|
39
43
|
});
|
|
40
44
|
function json(...routes) {
|
|
41
|
-
return ({ current, incoming, ignores }) => {
|
|
45
|
+
return ({ current, incoming, filters, ignores }) => {
|
|
42
46
|
const currentData = current && tryJson(current);
|
|
43
47
|
const incomingData = incoming && tryJson(incoming);
|
|
44
48
|
if ((!current || currentData) && (!incoming || incomingData)) {
|
|
45
|
-
return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, ignores });
|
|
49
|
+
return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
46
50
|
}
|
|
47
51
|
else {
|
|
48
52
|
const { data: currentData, transform: currentTransform } = JSONC.parse(current);
|
|
49
53
|
const { data: incomingData, transform: incomingTransform } = JSONC.parse(incoming);
|
|
50
54
|
const mergedTransform = merge({ current: currentTransform, incoming: incomingTransform });
|
|
51
55
|
const toJSON = (data) => JSONC.stringify(data, mergedTransform);
|
|
52
|
-
return (0, lodash_1.flow)(...routes, toJSON)({ current: currentData, incoming: incomingData, ignores });
|
|
56
|
+
return (0, lodash_1.flow)(...routes, toJSON)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
53
57
|
}
|
|
54
58
|
};
|
|
55
59
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapSort = void 0;
|
|
4
|
+
const { compare } = new Intl.Collator('en');
|
|
5
|
+
function mapSort(route) {
|
|
6
|
+
return (args) => {
|
|
7
|
+
const result = route(args);
|
|
8
|
+
const sorted = {};
|
|
9
|
+
const keys = Object.keys(result).sort((a, b) => compare(a, b));
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
sorted[key] = result[key];
|
|
12
|
+
}
|
|
13
|
+
return sorted;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.mapSort = mapSort;
|
package/lib/compositors/rc.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -32,15 +36,21 @@ function tryJson(value) {
|
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
function rc(...routes) {
|
|
35
|
-
return ({ current, incoming, ignores }) => {
|
|
39
|
+
return ({ current, incoming, filters, ignores }) => {
|
|
36
40
|
var _a;
|
|
37
41
|
const currentData = current && ((_a = tryJson(current)) !== null && _a !== void 0 ? _a : YAML.parse(current));
|
|
38
42
|
const incomingData = incoming && tryJson(incoming);
|
|
39
43
|
if (incomingData) {
|
|
40
|
-
return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, ignores });
|
|
44
|
+
return (0, lodash_1.flow)(...routes, JSON.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
41
45
|
}
|
|
42
46
|
else {
|
|
43
|
-
|
|
47
|
+
const incomingData = incoming && YAML.parse(incoming);
|
|
48
|
+
if ((0, lodash_1.isPlainObject)(incomingData) || Array.isArray(incomingData)) {
|
|
49
|
+
return (0, lodash_1.flow)(...routes, YAML.stringify)({ current: currentData, incoming: incomingData, filters, ignores });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return incoming;
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
};
|
|
46
56
|
}
|
package/lib/compositors/yaml.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,10 +26,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
26
|
exports.yaml = void 0;
|
|
23
27
|
const lodash_1 = require("lodash");
|
|
24
28
|
const YAML = __importStar(require("../parsers/yaml"));
|
|
25
|
-
function fromYaml({ current, incoming }) {
|
|
29
|
+
function fromYaml({ current, incoming, filters, ignores }) {
|
|
26
30
|
return {
|
|
27
31
|
current: typeof current === 'undefined' ? undefined : YAML.parse(current),
|
|
28
32
|
incoming: YAML.parse(incoming),
|
|
33
|
+
filters,
|
|
34
|
+
ignores,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
function yaml(...routes) {
|
|
@@ -0,0 +1,7 @@
|
|
|
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; } });
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.readConfig = void 0;
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
18
|
const yaml_1 = __importDefault(require("yaml"));
|
|
@@ -33,14 +33,14 @@ const places = [
|
|
|
33
33
|
name: '.artifactrc',
|
|
34
34
|
},
|
|
35
35
|
];
|
|
36
|
-
function
|
|
36
|
+
function readConfig(targetPath) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
let data;
|
|
39
39
|
let name;
|
|
40
40
|
let type;
|
|
41
41
|
for (const place of places) {
|
|
42
42
|
try {
|
|
43
|
-
data = yield fs_extra_1.default.readFile(path_1.default.join(
|
|
43
|
+
data = yield fs_extra_1.default.readFile(path_1.default.join(targetPath, place.name), 'utf-8');
|
|
44
44
|
name = place.name;
|
|
45
45
|
type = place.type;
|
|
46
46
|
break;
|
|
@@ -49,30 +49,47 @@ function readTargetConfig(context) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
if (!data) {
|
|
52
|
-
return
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
artifacts: [],
|
|
55
|
+
update: {},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: '.artifactrc.yml',
|
|
59
|
+
type: 'yaml',
|
|
60
|
+
finalNewLine: true,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
53
63
|
}
|
|
54
64
|
const finalNewLine = data.endsWith('\n');
|
|
65
|
+
let config;
|
|
55
66
|
if (type === 'json') {
|
|
56
|
-
|
|
67
|
+
config = JSON.parse(data);
|
|
57
68
|
}
|
|
58
69
|
else if (type === 'yaml') {
|
|
59
|
-
|
|
70
|
+
config = yaml_1.default.parse(data);
|
|
60
71
|
}
|
|
61
72
|
else {
|
|
62
73
|
try {
|
|
63
|
-
|
|
74
|
+
config = JSON.parse(data);
|
|
64
75
|
type = 'json';
|
|
65
76
|
}
|
|
66
77
|
catch (_b) {
|
|
67
|
-
|
|
78
|
+
config = yaml_1.default.parse(data);
|
|
68
79
|
type = 'yaml';
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
if (typeof config.update === 'undefined') {
|
|
83
|
+
config.update = {};
|
|
84
|
+
}
|
|
85
|
+
return [
|
|
86
|
+
config,
|
|
87
|
+
{
|
|
88
|
+
name: name,
|
|
89
|
+
type,
|
|
90
|
+
finalNewLine,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
76
93
|
});
|
|
77
94
|
}
|
|
78
|
-
exports.
|
|
95
|
+
exports.readConfig = readConfig;
|
|
@@ -0,0 +1,44 @@
|
|
|
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.writeConfig = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
19
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
20
|
+
const apply_formatting_1 = require("../steps/apply-formatting");
|
|
21
|
+
const insert_final_new_line_1 = require("../steps/insert-final-new-line");
|
|
22
|
+
function writeConfig({ artifacts, update }, { name, finalNewLine, type }, formats, targetPath, options) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const exported = {
|
|
25
|
+
artifacts: [...artifacts],
|
|
26
|
+
};
|
|
27
|
+
if (!(0, lodash_1.isPlainObject)(update) || !(0, lodash_1.isEmpty)(update)) {
|
|
28
|
+
exported.update = update;
|
|
29
|
+
}
|
|
30
|
+
const file = {
|
|
31
|
+
name,
|
|
32
|
+
data: type === 'yaml' ? yaml_1.default.stringify(exported) : JSON.stringify(exported, null, '\t'),
|
|
33
|
+
finalNewLine,
|
|
34
|
+
};
|
|
35
|
+
yield (0, insert_final_new_line_1.insertFinalNewLine)({ mergedTextFiles: [file] });
|
|
36
|
+
yield (0, apply_formatting_1.applyFormatting)({ mergedTextFiles: [file], formats });
|
|
37
|
+
const filePath = path_1.default.join(targetPath, name);
|
|
38
|
+
yield fs_extra_1.default.outputFile(filePath, file.data, 'utf-8');
|
|
39
|
+
if (options.verbose) {
|
|
40
|
+
console.log(`${name} has been written`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.writeConfig = writeConfig;
|
|
@@ -9,7 +9,7 @@ const routes_1 = require("../../routes");
|
|
|
9
9
|
const build_journey_plan_1 = require("../../utils/build-journey-plan");
|
|
10
10
|
const build_travel_plan_1 = require("../../utils/build-travel-plan");
|
|
11
11
|
const mainRoute = (0, compositors_1.compose)({
|
|
12
|
-
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [isPlainObject_1.default, routes_1.
|
|
12
|
+
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [isPlainObject_1.default, routes_1.mapConcat], routes_1.primitive),
|
|
13
13
|
});
|
|
14
14
|
const jsonRoute = (0, compositors_1.json)(mainRoute);
|
|
15
15
|
const yamlRoute = (0, compositors_1.yaml)(mainRoute);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
const compositors_1 = require("../../compositors");
|
|
5
|
+
const routes_1 = require("../../routes");
|
|
6
|
+
const build_journey_plan_1 = require("../../utils/build-journey-plan");
|
|
7
|
+
const build_travel_plan_1 = require("../../utils/build-travel-plan");
|
|
8
|
+
const mainRoute = (0, compositors_1.compose)({
|
|
9
|
+
sortToTop: routes_1.listSortConcat,
|
|
10
|
+
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [lodash_1.isPlainObject, routes_1.mapConcat], routes_1.primitive),
|
|
11
|
+
});
|
|
12
|
+
const jsonRoute = (0, compositors_1.json)(mainRoute);
|
|
13
|
+
const yamlRoute = (0, compositors_1.yaml)(mainRoute);
|
|
14
|
+
const rcRoute = (0, compositors_1.rc)(mainRoute);
|
|
15
|
+
const travelPlan = (0, build_travel_plan_1.buildTravelPlan)([/^\.fixpackrc\.json$/, jsonRoute], [/^\.fixpackrc\.ya?ml$/, yamlRoute], [/^\.fixpackrc$/, rcRoute]);
|
|
16
|
+
exports.default = (0, build_journey_plan_1.buildJourneyPlan)(travelPlan);
|
package/lib/journeys/index.js
CHANGED
|
@@ -7,17 +7,21 @@ exports.getJourney = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const commitlint_1 = __importDefault(require("./commitlint"));
|
|
9
9
|
const default_1 = __importDefault(require("./default"));
|
|
10
|
+
const fixpack_1 = __importDefault(require("./fixpack"));
|
|
10
11
|
const gitignore_1 = __importDefault(require("./gitignore"));
|
|
11
12
|
const ignore_1 = __importDefault(require("./ignore"));
|
|
12
13
|
const npmignore_1 = __importDefault(require("./npmignore"));
|
|
13
14
|
const package_1 = __importDefault(require("./package"));
|
|
14
15
|
const rc_1 = __importDefault(require("./rc"));
|
|
16
|
+
const tsconfig_1 = __importDefault(require("./tsconfig"));
|
|
15
17
|
const plans = [
|
|
16
|
-
|
|
18
|
+
commitlint_1.default,
|
|
19
|
+
fixpack_1.default,
|
|
17
20
|
gitignore_1.default,
|
|
18
|
-
npmignore_1.default,
|
|
19
21
|
ignore_1.default,
|
|
20
|
-
|
|
22
|
+
npmignore_1.default,
|
|
23
|
+
package_1.default,
|
|
24
|
+
tsconfig_1.default,
|
|
21
25
|
rc_1.default,
|
|
22
26
|
default_1.default,
|
|
23
27
|
];
|
|
@@ -12,21 +12,21 @@ const mainRoute = (0, compositors_1.compose)({
|
|
|
12
12
|
// default fields
|
|
13
13
|
keywords: routes_1.listConcat,
|
|
14
14
|
homepage: routes_1.primitive,
|
|
15
|
-
bugs: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.
|
|
16
|
-
license: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.
|
|
15
|
+
bugs: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.mapConcat], routes_1.primitive),
|
|
16
|
+
license: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.mapConcat], routes_1.primitive),
|
|
17
17
|
licenses: routes_1.listConcat,
|
|
18
|
-
author: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.
|
|
19
|
-
repository: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.
|
|
20
|
-
scripts: (0, compositors_1.compose)({
|
|
18
|
+
author: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.mapConcat], routes_1.primitive),
|
|
19
|
+
repository: (0, compositors_1.fork)([isPlainObject_1.default, routes_1.mapConcat], routes_1.primitive),
|
|
20
|
+
scripts: (0, compositors_1.mapSort)((0, compositors_1.compose)({
|
|
21
21
|
$$default: routes_1.command,
|
|
22
|
-
}),
|
|
23
|
-
config: routes_1.
|
|
24
|
-
engines: routes_1.
|
|
25
|
-
dependencies: routes_1.
|
|
26
|
-
devDependencies: routes_1.
|
|
27
|
-
peerDependencies: routes_1.
|
|
28
|
-
optionalDependencies: routes_1.
|
|
29
|
-
bundledDependencies: routes_1.
|
|
22
|
+
})),
|
|
23
|
+
config: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
24
|
+
engines: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
25
|
+
dependencies: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
26
|
+
devDependencies: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
27
|
+
peerDependencies: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
28
|
+
optionalDependencies: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
29
|
+
bundledDependencies: (0, compositors_1.mapSort)(routes_1.mapConcat),
|
|
30
30
|
// tools fields
|
|
31
31
|
browserslist: routes_1.listConcat,
|
|
32
32
|
// other fields
|
|
@@ -41,7 +41,7 @@ const mainRoute = (0, compositors_1.compose)({
|
|
|
41
41
|
'preferGlobal',
|
|
42
42
|
'private',
|
|
43
43
|
],
|
|
44
|
-
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [isPlainObject_1.default, routes_1.
|
|
44
|
+
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [isPlainObject_1.default, routes_1.mapConcat], routes_1.primitive),
|
|
45
45
|
});
|
|
46
46
|
const jsonRoute = (0, compositors_1.json)(mainRoute);
|
|
47
47
|
const travelPlan = (0, build_travel_plan_1.buildTravelPlan)(['package.json', jsonRoute]);
|
package/lib/journeys/rc/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const routes_1 = require("../../routes");
|
|
|
6
6
|
const build_journey_plan_1 = require("../../utils/build-journey-plan");
|
|
7
7
|
const build_travel_plan_1 = require("../../utils/build-travel-plan");
|
|
8
8
|
const mainRoute = (0, compositors_1.compose)({
|
|
9
|
-
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [lodash_1.isPlainObject, routes_1.
|
|
9
|
+
$$default: (0, compositors_1.fork)([Array.isArray, routes_1.listConcat], [lodash_1.isPlainObject, routes_1.mapConcat], routes_1.primitive),
|
|
10
10
|
});
|
|
11
11
|
const jsonRoute = (0, compositors_1.json)(mainRoute);
|
|
12
12
|
const yamlRoute = (0, compositors_1.yaml)(mainRoute);
|