@zokugun/artifact 0.6.1 → 0.6.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.
@@ -70,7 +70,6 @@ async function readInstallConfig(targetPath) {
70
70
  }
71
71
  function normalizeConfig(data, configStats) {
72
72
  const artifacts = {};
73
- let constants = {};
74
73
  const install = {};
75
74
  let update = {};
76
75
  let variables = {};
@@ -78,7 +77,6 @@ function normalizeConfig(data, configStats) {
78
77
  return (0, xtry_1.ok)({
79
78
  config: {
80
79
  artifacts,
81
- constants,
82
80
  install,
83
81
  update,
84
82
  variables,
@@ -128,9 +126,6 @@ function normalizeConfig(data, configStats) {
128
126
  }
129
127
  }
130
128
  }
131
- if ((0, is_it_type_1.isRecord)(data.constants, (_key, value) => (0, is_it_type_1.isString)(value))) {
132
- constants = data.constants;
133
- }
134
129
  if (data.update === false) {
135
130
  update = false;
136
131
  }
@@ -143,13 +138,12 @@ function normalizeConfig(data, configStats) {
143
138
  update[key] = normalized.value;
144
139
  }
145
140
  }
146
- if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isString)(value))) {
141
+ if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isPrimitive)(value))) {
147
142
  variables = data.variables;
148
143
  }
149
144
  return (0, xtry_1.ok)({
150
145
  config: {
151
146
  artifacts,
152
- constants,
153
147
  install,
154
148
  update,
155
149
  variables,
@@ -21,9 +21,6 @@ async function writeInstallConfig(config, { name, finalNewLine, indent, type },
21
21
  if ((0, is_it_type_1.isNonEmptyRecord)(config.update)) {
22
22
  exported.update = config.update;
23
23
  }
24
- if ((0, is_it_type_1.isNonEmptyRecord)(config.constants)) {
25
- exported.constants = config.constants;
26
- }
27
24
  if ((0, is_it_type_1.isNonEmptyRecord)(config.variables)) {
28
25
  exported.variables = config.variables;
29
26
  }
@@ -44,7 +44,6 @@ async function readPackageConfig(targetPath) {
44
44
  }
45
45
  }
46
46
  function normalizeConfig(data, source) {
47
- let constants = {};
48
47
  let xtends;
49
48
  const install = [];
50
49
  let orphan = false;
@@ -54,7 +53,6 @@ function normalizeConfig(data, source) {
54
53
  let variants = {};
55
54
  if (!data) {
56
55
  return (0, xtry_1.ok)({
57
- constants,
58
56
  extends: xtends,
59
57
  install,
60
58
  orphan,
@@ -77,9 +75,6 @@ function normalizeConfig(data, source) {
77
75
  return (0, xtry_1.err)(`Don't support newer version (v${version}) in the package's "${source}".`);
78
76
  }
79
77
  }
80
- if ((0, is_it_type_1.isRecord)(data.constants, (_key, value) => (0, is_it_type_1.isString)(value))) {
81
- constants = data.constants;
82
- }
83
78
  if ((0, is_it_type_1.isString)(data.extends)) {
84
79
  xtends = data.extends;
85
80
  }
@@ -89,7 +84,7 @@ function normalizeConfig(data, source) {
89
84
  if (data.orphan === true) {
90
85
  orphan = true;
91
86
  }
92
- if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isString)(value))) {
87
+ if ((0, is_it_type_1.isRecord)(data.variables, (_key, value) => (0, is_it_type_1.isPrimitive)(value))) {
93
88
  variables = data.variables;
94
89
  }
95
90
  if ((0, is_it_type_1.isRecord)(data.variants, (_key, value) => (0, is_it_type_1.isString)(value) || (0, is_it_type_1.isNumber)(value))) {
@@ -174,7 +169,6 @@ function normalizeConfig(data, source) {
174
169
  }
175
170
  }
176
171
  return (0, xtry_1.ok)({
177
- constants,
178
172
  extends: xtends,
179
173
  install,
180
174
  orphan,
@@ -4,14 +4,14 @@ const index_js_1 = require("../../compositors/index.js");
4
4
  const index_js_2 = require("../../routes/index.js");
5
5
  const build_journey_plan_js_1 = require("../../utils/build-journey-plan.js");
6
6
  const build_travel_plan_js_1 = require("../../utils/build-travel-plan.js");
7
- const mainRoute = (0, index_js_1.compose)({
7
+ const mainRoute = (0, index_js_1.mapSort)((0, index_js_1.compose)({
8
8
  extends: index_js_2.listConcat,
9
9
  parserPreset: index_js_2.primitive,
10
- rules: (0, index_js_1.compose)({
10
+ rules: (0, index_js_1.mapSort)((0, index_js_1.compose)({
11
11
  $$default: index_js_2.overwrite,
12
- }),
12
+ })),
13
13
  $$default: index_js_2.primitive,
14
- });
14
+ }));
15
15
  const jsonRoute = (0, index_js_1.json)(mainRoute);
16
16
  const yamlRoute = (0, index_js_1.yaml)(mainRoute);
17
17
  const rcRoute = (0, index_js_1.rc)(mainRoute);
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const lodash_es_1 = require("lodash-es");
3
+ const is_it_type_1 = require("@zokugun/is-it-type");
4
4
  const index_js_1 = require("../../compositors/index.js");
5
5
  const index_js_2 = require("../../routes/index.js");
6
6
  const build_journey_plan_js_1 = require("../../utils/build-journey-plan.js");
7
7
  const build_travel_plan_js_1 = require("../../utils/build-travel-plan.js");
8
- const mainRoute = (0, index_js_1.compose)({
8
+ const mainRoute = (0, index_js_1.mapSort)((0, index_js_1.compose)({
9
9
  sortToTop: index_js_2.listSortConcat,
10
- $$default: (0, index_js_1.fork)([Array.isArray, index_js_2.listConcat], [lodash_es_1.isPlainObject, index_js_2.mapConcat], index_js_2.primitive),
11
- });
10
+ $$default: (0, index_js_1.fork)([is_it_type_1.isArray, index_js_2.listConcat], [is_it_type_1.isRecord, index_js_2.mapConcat], index_js_2.primitive),
11
+ }));
12
12
  const jsonRoute = (0, index_js_1.json)(mainRoute);
13
13
  const yamlRoute = (0, index_js_1.yaml)(mainRoute);
14
14
  const rcRoute = (0, index_js_1.rc)(mainRoute);
@@ -14,6 +14,7 @@ async function configureBranches(context) {
14
14
  if (await async_1.default.isExisting(cwd)) {
15
15
  const directories = await (0, globby_1.default)('*', {
16
16
  cwd,
17
+ deep: 1,
17
18
  onlyDirectories: true,
18
19
  });
19
20
  const bucket = [];
@@ -8,17 +8,14 @@ const path_1 = __importDefault(require("path"));
8
8
  const cli_utils_1 = require("@zokugun/cli-utils");
9
9
  const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
10
  const xtry_1 = require("@zokugun/xtry");
11
- const globby_1 = __importDefault(require("globby"));
12
11
  const istextorbinary_1 = require("istextorbinary");
13
12
  const detect_indent_js_1 = require("../utils/detect-indent.js");
14
13
  const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
14
+ const list_working_files_js_1 = require("../utils/list-working-files.js");
15
15
  const read_buffer_js_1 = require("../utils/read-buffer.js");
16
16
  async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
17
17
  const cwd = path_1.default.join(incomingPath, 'configs');
18
- const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
19
- cwd,
20
- dot: true,
21
- });
18
+ const files = await (0, list_working_files_js_1.listWorkingFiles)(cwd);
22
19
  for (const file of files) {
23
20
  const filePath = path_1.default.join(cwd, file);
24
21
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
@@ -8,17 +8,14 @@ const path_1 = __importDefault(require("path"));
8
8
  const cli_utils_1 = require("@zokugun/cli-utils");
9
9
  const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
10
  const xtry_1 = require("@zokugun/xtry");
11
- const globby_1 = __importDefault(require("globby"));
12
11
  const micromatch_1 = require("micromatch");
12
+ const list_working_files_js_1 = require("../utils/list-working-files.js");
13
13
  async function removeFiles({ removedPatterns, targetPath, options }) {
14
14
  if (removedPatterns.length === 0) {
15
15
  return xtry_1.OK;
16
16
  }
17
17
  const cwd = path_1.default.join(targetPath);
18
- const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*', '!.git'], {
19
- cwd,
20
- dot: true,
21
- });
18
+ const files = await (0, list_working_files_js_1.listWorkingFiles)(cwd);
22
19
  for (const file of files) {
23
20
  if ((0, micromatch_1.isMatch)(file, removedPatterns)) {
24
21
  if (!options.dryRun) {
@@ -7,8 +7,6 @@ async function replaceTemplates({ textFiles, binaryFiles, targetPath, config, in
7
7
  const variables = {
8
8
  ...incomingConfig?.variables,
9
9
  ...config?.variables,
10
- ...incomingConfig?.constants,
11
- ...config?.constants,
12
10
  };
13
11
  const engine = new template_js_1.TemplateEngine(targetPath, variables);
14
12
  for (const file of textFiles) {
@@ -9,19 +9,16 @@ const cli_utils_1 = require("@zokugun/cli-utils");
9
9
  const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
10
10
  const is_it_type_1 = require("@zokugun/is-it-type");
11
11
  const xtry_1 = require("@zokugun/xtry");
12
- const globby_1 = __importDefault(require("globby"));
13
12
  const index_js_1 = require("../journeys/index.js");
14
13
  const detect_indent_js_1 = require("../utils/detect-indent.js");
15
14
  const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
15
+ const list_working_files_js_1 = require("../utils/list-working-files.js");
16
16
  async function transformUntouchedFiles({ formats, options, routes, targetPath, textFiles, transformedFiles, transforms }) {
17
17
  if (transforms.length === 0) {
18
18
  return xtry_1.OK;
19
19
  }
20
20
  const cwd = path_1.default.join(targetPath);
21
- const files = await (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*'], {
22
- cwd,
23
- dot: true,
24
- });
21
+ const files = await (0, list_working_files_js_1.listWorkingFiles)(cwd);
25
22
  for (const file of files) {
26
23
  if (textFiles.some(({ name }) => name === file)) {
27
24
  continue;
@@ -1,3 +1,4 @@
1
+ import { type Primitive } from '@zokugun/is-it-type';
1
2
  import { type Indent } from './format.js';
2
3
  export type Request = {
3
4
  name: string;
@@ -8,13 +9,12 @@ export type PackageManifest = {
8
9
  version: string;
9
10
  };
10
11
  export type PackageConfig = {
11
- constants: Record<string, string>;
12
12
  extends?: string;
13
13
  install: InstallFileConfig[];
14
14
  orphan: boolean;
15
15
  uninstall: UninstallFileConfig[];
16
16
  update: false | UpdateFileConfig[];
17
- variables: Record<string, string>;
17
+ variables: Record<string, Primitive>;
18
18
  variants: Record<string, string>;
19
19
  };
20
20
  export type Artifact = {
@@ -27,10 +27,9 @@ export type ArtifactResult = Artifact & {
27
27
  };
28
28
  export type InstallConfig = {
29
29
  artifacts: Record<string, Artifact>;
30
- constants: Record<string, string>;
31
30
  install: Record<string, InstallFileConfig>;
32
31
  update: false | Record<string, UpdateFileConfig>;
33
- variables: Record<string, string>;
32
+ variables: Record<string, Primitive>;
34
33
  };
35
34
  export type FileConfig<E> = {
36
35
  ifExists: E;
@@ -0,0 +1 @@
1
+ export declare function listWorkingFiles(cwd: string): Promise<string[]>;
@@ -0,0 +1,14 @@
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.listWorkingFiles = listWorkingFiles;
7
+ const globby_1 = __importDefault(require("globby"));
8
+ async function listWorkingFiles(cwd) {
9
+ return (0, globby_1.default)(['**/*', '!**/*.lock', '!**/*-lock.*', '!.git', '!**/node_modules/**'], {
10
+ cwd,
11
+ dot: true,
12
+ followSymbolicLinks: false,
13
+ });
14
+ }
@@ -1,10 +1,11 @@
1
+ import { type Primitive } from '@zokugun/is-it-type';
1
2
  import { type DResult } from '@zokugun/xtry';
2
3
  export declare class TemplateEngine {
3
4
  private readonly basePath;
4
5
  private readonly fileCache;
5
6
  private readonly variables;
6
7
  private readonly variableCache;
7
- constructor(basePath: string, variables?: Record<string, string>);
8
+ constructor(basePath: string, variables?: Record<string, Primitive>);
8
9
  render(template: string): DResult<string>;
9
10
  private getValueByPath;
10
11
  private parseFile;
@@ -40,6 +40,7 @@ exports.TemplateEngine = void 0;
40
40
  exports.unescapeCode = unescapeCode;
41
41
  const path_1 = __importDefault(require("path"));
42
42
  const sync_1 = __importDefault(require("@zokugun/fs-extra-plus/sync"));
43
+ const is_it_type_1 = require("@zokugun/is-it-type");
43
44
  const xtry_1 = require("@zokugun/xtry");
44
45
  const dayjs_1 = __importDefault(require("dayjs"));
45
46
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
@@ -164,16 +165,27 @@ class TemplateEngine {
164
165
  if (this.variableCache.has(name)) {
165
166
  return (0, xtry_1.ok)(this.variableCache.get(name));
166
167
  }
167
- const expression = this.variables[name];
168
- if (typeof expression !== 'string' || expression.trim().length === 0) {
168
+ const value = this.variables[name];
169
+ if (!(0, is_it_type_1.isPrimitive)(value)) {
169
170
  return (0, xtry_1.err)(`Invalid variable: ${name}.`);
170
171
  }
171
- const result = this.resolveExpression(expression);
172
- if (result.fails) {
172
+ const expression = String(value).trim();
173
+ if (expression.length === 0) {
174
+ return (0, xtry_1.err)(`Invalid variable: ${name}.`);
175
+ }
176
+ if (expression.at(0) === '=') {
177
+ const result = this.resolveExpression(expression.slice(1));
178
+ if (result.fails) {
179
+ return result;
180
+ }
181
+ this.variableCache.set(name, result.value);
173
182
  return result;
174
183
  }
175
- this.variableCache.set(name, result.value);
176
- return result;
184
+ else {
185
+ const value = expression.at(0) === '\\' && expression.at(1) === '=' ? expression.slice(1) : expression;
186
+ this.variableCache.set(name, value);
187
+ return (0, xtry_1.ok)(value);
188
+ }
177
189
  } // }}}
178
190
  splitPlaceholder(placeholder) {
179
191
  const matches = PLACEHOLDER_REGEX.exec(placeholder);
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.6.1",
4
+ "version": "0.6.3",
5
5
  "author": {
6
6
  "name": "Baptiste Augrain",
7
7
  "email": "daiyam@zokugun.org"