@zokugun/artifact 0.1.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.
Files changed (60) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +102 -0
  3. package/bin/artifact +3 -0
  4. package/lib/cli.js +17 -0
  5. package/lib/commands/add.js +57 -0
  6. package/lib/compositors/compose.js +49 -0
  7. package/lib/compositors/fork.js +21 -0
  8. package/lib/compositors/index.js +13 -0
  9. package/lib/compositors/json.js +56 -0
  10. package/lib/compositors/rc.js +47 -0
  11. package/lib/compositors/yaml.js +34 -0
  12. package/lib/install.js +32 -0
  13. package/lib/journeys/commitlint/index.js +19 -0
  14. package/lib/journeys/default/index.js +17 -0
  15. package/lib/journeys/gitignore/index.js +7 -0
  16. package/lib/journeys/ignore/index.js +7 -0
  17. package/lib/journeys/index.js +34 -0
  18. package/lib/journeys/npmignore/index.js +7 -0
  19. package/lib/journeys/package/index.js +48 -0
  20. package/lib/journeys/rc/index.js +15 -0
  21. package/lib/parsers/json.js +11 -0
  22. package/lib/parsers/jsonc/index.js +7 -0
  23. package/lib/parsers/jsonc/parse.js +194 -0
  24. package/lib/parsers/jsonc/stringify.js +100 -0
  25. package/lib/parsers/jsonc/transform.js +2 -0
  26. package/lib/parsers/yaml.js +15 -0
  27. package/lib/routes/command.js +21 -0
  28. package/lib/routes/hash.js +13 -0
  29. package/lib/routes/index.js +15 -0
  30. package/lib/routes/lines-concat.js +22 -0
  31. package/lib/routes/list-concat.js +18 -0
  32. package/lib/routes/overwrite.js +12 -0
  33. package/lib/routes/primitive.js +18 -0
  34. package/lib/steps/apply-formatting.js +78 -0
  35. package/lib/steps/copy-binary-files.js +31 -0
  36. package/lib/steps/index.js +42 -0
  37. package/lib/steps/insert-final-new-line.js +25 -0
  38. package/lib/steps/merge-text-files.js +57 -0
  39. package/lib/steps/read-editor-config.js +97 -0
  40. package/lib/steps/read-files.js +66 -0
  41. package/lib/steps/read-incoming-package.js +24 -0
  42. package/lib/steps/read-target-config.js +78 -0
  43. package/lib/steps/update-target-config.js +50 -0
  44. package/lib/steps/write-text-files.js +32 -0
  45. package/lib/types/config.js +2 -0
  46. package/lib/types/context.js +2 -0
  47. package/lib/types/format.js +8 -0
  48. package/lib/types/step.js +2 -0
  49. package/lib/types/text-file.js +2 -0
  50. package/lib/types/travel.js +2 -0
  51. package/lib/utils/build-journey-plan.js +18 -0
  52. package/lib/utils/build-travel-plan.js +20 -0
  53. package/lib/utils/command/command.js +2 -0
  54. package/lib/utils/command/index.js +7 -0
  55. package/lib/utils/command/join-command.js +27 -0
  56. package/lib/utils/command/split-command.js +30 -0
  57. package/lib/utils/read-buffer.js +38 -0
  58. package/lib/utils/to-lines.js +7 -0
  59. package/lib/utils/trim-final-newline.js +8 -0
  60. package/package.json +93 -0
@@ -0,0 +1,57 @@
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.mergeTextFiles = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
18
+ const journeys_1 = require("../journeys");
19
+ function mergeTextFiles({ targetPath, textFiles, mergedTextFiles, options }) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ for (const file of textFiles) {
22
+ if (file.data.length === 0) {
23
+ mergedTextFiles.push(file);
24
+ continue;
25
+ }
26
+ const journey = (0, journeys_1.getJourney)(file.name);
27
+ if (!journey) {
28
+ if (options.verbose) {
29
+ console.log(`${file.name}, no merger found`);
30
+ }
31
+ mergedTextFiles.push(file);
32
+ continue;
33
+ }
34
+ const name = journey.alias ? path_1.default.join(path_1.default.dirname(file.name), journey.alias) : file.name;
35
+ let currentData;
36
+ try {
37
+ currentData = yield fs_extra_1.default.readFile(path_1.default.join(targetPath, name), 'utf-8');
38
+ }
39
+ catch (_a) {
40
+ }
41
+ const data = journey.travel({
42
+ current: currentData,
43
+ incoming: file.data,
44
+ });
45
+ mergedTextFiles.push({
46
+ name,
47
+ data,
48
+ finalNewLine: file.finalNewLine,
49
+ mode: file.mode,
50
+ });
51
+ if (options.verbose) {
52
+ console.log(`${file.name} has been merged`);
53
+ }
54
+ }
55
+ });
56
+ }
57
+ exports.mergeTextFiles = mergeTextFiles;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.readEditorConfig = void 0;
35
+ const path_1 = __importDefault(require("path"));
36
+ const fs_extra_1 = __importDefault(require("fs-extra"));
37
+ const editorconfig = __importStar(require("editorconfig"));
38
+ const format_1 = require("../types/format");
39
+ function buildFullGlob(glob) {
40
+ switch (glob.indexOf('/')) {
41
+ case -1:
42
+ glob = '**/' + glob;
43
+ break;
44
+ case 0:
45
+ glob = glob.slice(1);
46
+ break;
47
+ default:
48
+ break;
49
+ }
50
+ return glob.replace(/\*\*/g, '{*,**/**/**}');
51
+ } // }}}
52
+ function readEditorConfig({ incomingPath, targetPath, formats }) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ let data;
55
+ try {
56
+ const dir = path_1.default.join(incomingPath, 'configs');
57
+ const file = path_1.default.join(dir, '.editorconfig');
58
+ data = yield fs_extra_1.default.readFile(file, 'utf-8');
59
+ }
60
+ catch (_a) {
61
+ }
62
+ if (!data) {
63
+ try {
64
+ const file = path_1.default.join(targetPath, '.editorconfig');
65
+ data = yield fs_extra_1.default.readFile(file, 'utf-8');
66
+ }
67
+ catch (_b) {
68
+ }
69
+ }
70
+ if (!data) {
71
+ return;
72
+ }
73
+ const rules = editorconfig.parseString(data);
74
+ for (const [glob, rule] of rules) {
75
+ if (!glob) {
76
+ continue;
77
+ }
78
+ const indentStyle = (rule.indent_style || 'space');
79
+ const indentSize = (rule.indent_size && Number.parseInt(rule.indent_size, 10)) || 2;
80
+ const insertFinalNewline = typeof rule.insert_final_newline === 'undefined' ? true : rule.insert_final_newline === 'true';
81
+ formats.push({
82
+ glob: buildFullGlob(glob),
83
+ indentStyle,
84
+ indentSize,
85
+ insertFinalNewline,
86
+ });
87
+ }
88
+ formats.push({
89
+ glob: buildFullGlob('{*.yml,*.yaml}'),
90
+ indentStyle: format_1.IndentStyle.SPACE,
91
+ indentSize: 2,
92
+ insertFinalNewline: true,
93
+ });
94
+ formats.reverse();
95
+ });
96
+ }
97
+ exports.readEditorConfig = readEditorConfig;
@@ -0,0 +1,66 @@
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.readFiles = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const istextorbinary_1 = require("istextorbinary");
18
+ const globby_1 = __importDefault(require("globby"));
19
+ const fs_extra_1 = __importDefault(require("fs-extra"));
20
+ const read_buffer_1 = require("../utils/read-buffer");
21
+ function readFiles(context) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const cwd = path_1.default.join(context.incomingPath, 'configs');
24
+ const files = yield (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
25
+ cwd,
26
+ dot: true,
27
+ });
28
+ for (const file of files) {
29
+ const filePath = path_1.default.join(cwd, file);
30
+ if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(yield (0, read_buffer_1.readBuffer)(filePath, 24)) === 'utf8') {
31
+ const data = yield fs_extra_1.default.readFile(filePath, 'utf-8');
32
+ const finalNewLine = data.endsWith('\n');
33
+ if (data.startsWith('#!')) {
34
+ // the text file might be executable
35
+ const { mode } = yield fs_extra_1.default.stat(filePath);
36
+ context.textFiles.push({
37
+ name: file,
38
+ data,
39
+ mode,
40
+ finalNewLine,
41
+ });
42
+ if (context.options.verbose) {
43
+ console.log(`${file} is a shebang file`);
44
+ }
45
+ }
46
+ else {
47
+ context.textFiles.push({
48
+ name: file,
49
+ data,
50
+ finalNewLine,
51
+ });
52
+ if (context.options.verbose) {
53
+ console.log(`${file} is a text file`);
54
+ }
55
+ }
56
+ }
57
+ else {
58
+ context.binaryFiles.push(file);
59
+ if (context.options.verbose) {
60
+ console.log(`${file} is a binary file`);
61
+ }
62
+ }
63
+ }
64
+ });
65
+ }
66
+ exports.readFiles = readFiles;
@@ -0,0 +1,24 @@
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.readIncomingPackage = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
18
+ function readIncomingPackage(context) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const filePath = path_1.default.resolve(context.incomingPath, './package.json');
21
+ context.incomingPackage = (yield fs_extra_1.default.readJSON(filePath));
22
+ });
23
+ }
24
+ exports.readIncomingPackage = readIncomingPackage;
@@ -0,0 +1,78 @@
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.readTargetConfig = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
18
+ const yaml_1 = __importDefault(require("yaml"));
19
+ const places = [
20
+ {
21
+ name: '.artifactrc.yml',
22
+ type: 'yaml',
23
+ },
24
+ {
25
+ name: '.artifactrc.yaml',
26
+ type: 'yaml',
27
+ },
28
+ {
29
+ name: '.artifactrc.json',
30
+ type: 'json',
31
+ },
32
+ {
33
+ name: '.artifactrc',
34
+ },
35
+ ];
36
+ function readTargetConfig(context) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ let data;
39
+ let name;
40
+ let type;
41
+ for (const place of places) {
42
+ try {
43
+ data = yield fs_extra_1.default.readFile(path_1.default.join(context.targetPath, place.name), 'utf-8');
44
+ name = place.name;
45
+ type = place.type;
46
+ break;
47
+ }
48
+ catch (_a) {
49
+ }
50
+ }
51
+ if (!data) {
52
+ return;
53
+ }
54
+ const finalNewLine = data.endsWith('\n');
55
+ if (type === 'json') {
56
+ context.configs = JSON.parse(data);
57
+ }
58
+ else if (type === 'yaml') {
59
+ context.configs = yaml_1.default.parse(data);
60
+ }
61
+ else {
62
+ try {
63
+ context.configs = JSON.parse(data);
64
+ type = 'json';
65
+ }
66
+ catch (_b) {
67
+ context.configs = yaml_1.default.parse(data);
68
+ type = 'yaml';
69
+ }
70
+ }
71
+ context.configInfo = {
72
+ name: name,
73
+ type,
74
+ finalNewLine,
75
+ };
76
+ });
77
+ }
78
+ exports.readTargetConfig = readTargetConfig;
@@ -0,0 +1,50 @@
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.updateTargetConfig = void 0;
16
+ const yaml_1 = __importDefault(require("yaml"));
17
+ function updateTargetConfig({ configs, configInfo, incomingPackage, mergedTextFiles }) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const name = incomingPackage.name;
20
+ const version = incomingPackage.version;
21
+ let nf = true;
22
+ for (const config of configs) {
23
+ if (config.name === name) {
24
+ config.version = version;
25
+ nf = false;
26
+ break;
27
+ }
28
+ }
29
+ if (nf) {
30
+ configs.push({
31
+ name,
32
+ version,
33
+ });
34
+ }
35
+ if (!configInfo) {
36
+ configInfo = {
37
+ name: '.artifactrc.yml',
38
+ type: 'yaml',
39
+ finalNewLine: true,
40
+ };
41
+ }
42
+ const data = configInfo.type === 'yaml' ? yaml_1.default.stringify(configs) : JSON.stringify(configs, null, '\t');
43
+ mergedTextFiles.push({
44
+ name: configInfo.name,
45
+ data,
46
+ finalNewLine: configInfo.finalNewLine,
47
+ });
48
+ });
49
+ }
50
+ exports.updateTargetConfig = updateTargetConfig;
@@ -0,0 +1,32 @@
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.writeTextFiles = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
18
+ function writeTextFiles({ mergedTextFiles, targetPath, options }) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ for (const file of mergedTextFiles) {
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
+ }
26
+ if (options.verbose) {
27
+ console.log(`${file.name} has been written as a text file`);
28
+ }
29
+ }
30
+ });
31
+ }
32
+ exports.writeTextFiles = writeTextFiles;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IndentStyle = void 0;
4
+ var IndentStyle;
5
+ (function (IndentStyle) {
6
+ IndentStyle["SPACE"] = "space";
7
+ IndentStyle["TAB"] = "tab";
8
+ })(IndentStyle = exports.IndentStyle || (exports.IndentStyle = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildJourneyPlan = void 0;
4
+ function buildJourneyPlan(plan, alias) {
5
+ return (basename) => {
6
+ const travel = plan(basename);
7
+ if (travel) {
8
+ return {
9
+ travel,
10
+ alias,
11
+ };
12
+ }
13
+ else {
14
+ return undefined;
15
+ }
16
+ };
17
+ }
18
+ exports.buildJourneyPlan = buildJourneyPlan;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTravelPlan = void 0;
4
+ function buildTravelPlan(...mappers) {
5
+ return (basename) => {
6
+ const mapper = mappers.find((mapper) => {
7
+ if (mapper[0] instanceof RegExp) {
8
+ return mapper[0].test(basename);
9
+ }
10
+ return mapper[0] === basename;
11
+ });
12
+ if (mapper) {
13
+ return mapper[1];
14
+ }
15
+ else {
16
+ return undefined;
17
+ }
18
+ };
19
+ }
20
+ exports.buildTravelPlan = buildTravelPlan;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitCommand = exports.joinCommand = void 0;
4
+ var join_command_1 = require("./join-command");
5
+ Object.defineProperty(exports, "joinCommand", { enumerable: true, get: function () { return join_command_1.joinCommand; } });
6
+ var split_command_1 = require("./split-command");
7
+ Object.defineProperty(exports, "splitCommand", { enumerable: true, get: function () { return split_command_1.splitCommand; } });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinCommand = void 0;
4
+ function joinCommand(commands) {
5
+ const subcommands = [];
6
+ for (const [key, values] of Object.entries(commands)) {
7
+ if (values.length === 0) {
8
+ subcommands.push(key);
9
+ continue;
10
+ }
11
+ for (const value of values) {
12
+ let subcommand = key;
13
+ if (value.env.length > 0) {
14
+ subcommand = `${value.env.join(' ')} ${subcommand}`;
15
+ }
16
+ if (value.args.length > 0) {
17
+ subcommand = `${subcommand} ${value.args.join(' ')}`;
18
+ }
19
+ if (value.separator) {
20
+ subcommand = `${subcommand} ${value.separator}`;
21
+ }
22
+ subcommands.push(subcommand);
23
+ }
24
+ }
25
+ return subcommands.join(' ');
26
+ }
27
+ exports.joinCommand = joinCommand;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ function splitCommand(command) {
6
+ const result = {};
7
+ const splitted = command.split(/([&|]{1,2}|;)/).map(lodash_1.trim);
8
+ for (let i = 0; i < splitted.length; i++) {
9
+ const command = splitted[i];
10
+ const splittedSubcommand = command.split(/([\w-]+=\S+)\s/).filter(lodash_1.identity);
11
+ const subcommandWithArgs = (0, lodash_1.last)(splittedSubcommand).split(' ');
12
+ const subcommand = (0, lodash_1.head)(subcommandWithArgs).trim();
13
+ const args = subcommandWithArgs.slice(1);
14
+ const env = splittedSubcommand.slice(0, -1);
15
+ const parsedSubcommand = {
16
+ args: args.map(lodash_1.trim),
17
+ env: env.map(lodash_1.trim),
18
+ separator: splitted[i + 1],
19
+ };
20
+ if (result[subcommand]) {
21
+ result[subcommand].push(parsedSubcommand);
22
+ }
23
+ else {
24
+ result[subcommand] = [parsedSubcommand];
25
+ }
26
+ i++;
27
+ }
28
+ return result;
29
+ }
30
+ exports.splitCommand = splitCommand;
@@ -0,0 +1,38 @@
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.readBuffer = void 0;
16
+ const promises_1 = __importDefault(require("fs/promises"));
17
+ const buffer_1 = require("buffer");
18
+ function readBuffer(filepath, size, offset = 0) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const buffer = buffer_1.Buffer.alloc(size);
21
+ const file = yield promises_1.default.open(filepath, 'r');
22
+ try {
23
+ const { bytesRead } = yield file.read(buffer, offset, size, 0);
24
+ if (bytesRead < size) {
25
+ const smaller = buffer_1.Buffer.alloc(bytesRead);
26
+ buffer.copy(smaller, 0, 0, bytesRead);
27
+ return smaller;
28
+ }
29
+ else {
30
+ return buffer;
31
+ }
32
+ }
33
+ finally {
34
+ yield file.close();
35
+ }
36
+ });
37
+ }
38
+ exports.readBuffer = readBuffer;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toLines = void 0;
4
+ function toLines(value) {
5
+ return value.split(/\r?\n/g);
6
+ }
7
+ exports.toLines = toLines;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trimFinalNewLine = void 0;
4
+ const FINAL_NEWLINE_REGEX = /(\r?\n)*$/;
5
+ function trimFinalNewLine(value) {
6
+ return value.replace(FINAL_NEWLINE_REGEX, '');
7
+ }
8
+ exports.trimFinalNewLine = trimFinalNewLine;