@jakubmazanec/carson 0.1.0-bc209e5 → 0.1.0-dee6883

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 CHANGED
@@ -11,12 +11,26 @@ Tool for managing workspace and project configuration.
11
11
  ## Installation
12
12
 
13
13
  ```sh
14
- npm install @jakubmazanec/carson -g
14
+ npm install @jakubmazanec/carson
15
15
  ```
16
16
 
17
17
  ⚠️ This is an [ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) package!
18
18
  It cannot be required from a CommonJS module.
19
19
 
20
+ Usually you also need a package containing Carson templates. Until you
21
+ [create your own](#carson-templates), you can use mine:
22
+
23
+ ```sh
24
+ npm install @jakubmazanec/carson-templates
25
+ ```
26
+
27
+ ⚠️ If you want to create new workspaces, you need to install both Carson and your template package
28
+ globally:
29
+
30
+ ```sh
31
+ npm install @jakubmazanec/carson @jakubmazanec/carson-templates -g
32
+ ```
33
+
20
34
  #### Prerequisites
21
35
 
22
36
  - Node.js 16 or later
@@ -176,9 +190,9 @@ See [API reference](./docs) for auto-generated documentation.
176
190
 
177
191
  ### Configuration
178
192
 
179
- Carson configuration files are located in a directory named `.carson` directory. Files named
180
- `workspace.json` and `project.json` are used to configure the workspace and project respectively (in
181
- the case of single-project workspace they're both in the same `.carson` directory).
193
+ Carson configuration files are located in a directory named `.carson`. Files named `workspace.json`
194
+ and `project.json` are used to configure the workspace and project respectively (in the case of
195
+ single-project workspace they're both in the same `.carson` directory).
182
196
 
183
197
  You can add arbitrary data to these JSONs in addition to the options described below. Because
184
198
  workspace and project configurations are available as JavaScript variables during the rendering of
@@ -269,6 +283,8 @@ there are 3 templates (for simplicity, each contains only one `*.ejs` file and a
269
283
  The package can also export some JavaScript code (defined in the `package.json` as usual); all named
270
284
  export are available as global variables during the rendering of the template files.
271
285
 
286
+ > ⚠️ Do NOT use asynchronous functions in the template files. Templates are rendered synchronously.
287
+
272
288
  #### Template files
273
289
 
274
290
  All those `*.ejs` files are parsed and rendered via `@jakubmazanec/template` package; they are
@@ -315,14 +331,15 @@ should be written at all.
315
331
 
316
332
  | Strategy name | Example `strategy` value | Description |
317
333
  | ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
318
- | Create | `create` | The template render is written to the target file, but only when the Carson template is used to create a new workspace or project; when Carson performs an update, the template files with this strategy are not even rendered. |
319
- | Ensure | `ensure` | The template render is written to the target file, but only when the target file doesn't exist; if it does, it is left unchanged. |
320
- | Overwrite | `overwrite` | The template render is written to the target file, overwriting its existing content. |
321
- | Merge | `merge` | The template render is merged with the target file's existing content. Only simple objects, not arrays, are merged recursively. The only supported file formats are JSON and YAML. |
322
- | Check | `check` | Only the target file's existence is checked, the template render is discarded; when Carson doesn't perform an update, the template files with this strategy are not even rendered. |
323
- | Insert | `[insert, foobar]` | The template render is inserted between the first and last occurrence of an HTML comment containing configured string, e.g. `<!-- foobar -->`. The only supported file format is Markdown. |
334
+ | Create | `'create'` | The template render is written to the target file, but only when the Carson template is used to create a new workspace or project; when Carson performs an update, the template files with this strategy are not even rendered. |
335
+ | Ensure | `'ensure'` | The template render is written to the target file, but only when the target file doesn't exist; if it does, it is left unchanged. |
336
+ | Overwrite | `'overwrite'` | The template render is written to the target file, overwriting its existing content. |
337
+ | Merge | `'merge'` | The template render is merged with the target file's existing content. Only simple objects, not arrays, are merged recursively. The only supported file formats are JSON and YAML. |
338
+ | Check | `'check'` | Only the target file's existence is checked, the template render is discarded; when Carson doesn't perform an update, the template files with this strategy are not even rendered. |
339
+ | Insert | `['insert', <string>]` | The template render is inserted between the first and last occurrence of an HTML comment containing configured string, e.g. `<!-- foobar -->`. The only supported file format is Markdown. |
324
340
 
325
- The rest of the template file after the front matter is the actual EJS template.
341
+ The rest of the template file after the front matter is the actual EJS template. Please read
342
+ [`ejs` documentation](https://ejs.co/#docs) to find out in more detail how they work.
326
343
 
327
344
  > ⚠️ Because EJS templates can contain arbitrary JavaScript code which Carson will run, you
328
345
  > shouldn't use Carson templates from untrusted sources! Only use templates that you've written or
@@ -340,6 +357,43 @@ Global variables available during the rendering:
340
357
 
341
358
  Currently, the config isn't used for anything yet.
342
359
 
360
+ ### Carson philosophy
361
+
362
+ The fact that Carson templates are just JavaScript gives you a lot of freedom, but it may lead you
363
+ to use Carson just as a simple config generator. Because you can add arbitrary data to the workspace
364
+ and project configs, it is tempting to use them as a source of values for "parameters" of
365
+ configurations of various tools.
366
+
367
+ For example, you can add `"useSwc": true` or `"useSwc": false` to a project config and then use this
368
+ value in a template that generates build configuration for either SWC, or Babel. But this makes
369
+ updates little bit harder, because if you later remove Babel support, you have to remember to remove
370
+ now useless setting from the project config. It also makes the logic of the Carson template more
371
+ complex; it is better to have separate templates for projects that use Babel and for project that
372
+ use SWC.
373
+
374
+ Another approach that is not recommended is using project config to specify "overrides" for various
375
+ config files:
376
+
377
+ ```json
378
+ {
379
+ "template": "@jakubmazanec/carson-templates:projects/library",
380
+
381
+ "tsconfig": {
382
+ "compilerOptions": {
383
+ "strict": false
384
+ }
385
+ }
386
+ }
387
+ ```
388
+
389
+ The `tsconfig` object is then recursively merged with the defaults during the template rendering of
390
+ the resulting `tsconfig.json`, thus allowing you to change TypeScript configuration per project.
391
+ This is not ideal, because now the Carson template isn't the only thing that defines the project
392
+ configuration, which makes updates more unpredictable.
393
+
394
+ Generally, do not push the data onto the templates, let the templates pull the data they need. Since
395
+ you create your own templates, it should be easy to do.
396
+
343
397
  ## Contributing
344
398
 
345
399
  If you want to contribute, see [CONTRIBUTING](./CONTRIBUTING.md) for details.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * {@link Workspace.create | Workspace.create} options parameter.
2
+ * {@link Workspace.create} options parameter.
3
3
  */
4
4
  export type WorkspaceCreateOptions = {
5
5
  path: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * {@link Workspace.create | Workspace.create} options parameter.
2
+ * {@link Workspace.create} options parameter.
3
3
  */ export { };
4
4
 
5
5
  //# sourceMappingURL=WorkspaceCreateOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/workspace/WorkspaceCreateOptions.ts"],"sourcesContent":["/**\n * {@link Workspace.create | Workspace.create} options parameter.\n */\nexport type WorkspaceCreateOptions = {\n path: string;\n templateId: string;\n args: Record<string, unknown>;\n};\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAIE"}
1
+ {"version":3,"sources":["../../src/workspace/WorkspaceCreateOptions.ts"],"sourcesContent":["/**\n * {@link Workspace.create} options parameter.\n */\nexport type WorkspaceCreateOptions = {\n path: string;\n templateId: string;\n args: Record<string, unknown>;\n};\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAIE"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@jakubmazanec/carson",
3
- "version": "0.1.0-bc209e5",
3
+ "version": "0.1.0-dee6883",
4
4
  "description": "Tool for managing workspace and project configuration.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/jakubmazanec/js-tools",
7
+ "url": "git@github.com:jakubmazanec/js-tools.git",
8
8
  "directory": "packages/carson"
9
9
  },
10
10
  "license": "AGPL-3.0-only",
@@ -31,13 +31,13 @@
31
31
  "typecheck": "tsc --project tsconfig.typecheck.json"
32
32
  },
33
33
  "dependencies": {
34
- "@jakubmazanec/args": "1.0.1-bc209e5",
35
- "@jakubmazanec/cli": "0.1.0-bc209e5",
36
- "@jakubmazanec/error": "2.0.1-bc209e5",
37
- "@jakubmazanec/fs-utils": "0.1.0-bc209e5",
38
- "@jakubmazanec/template": "1.0.1-bc209e5",
39
- "@jakubmazanec/ts-utils": "2.1.0-bc209e5",
40
- "@jakubmazanec/zod-utils": "1.0.0-bc209e5",
34
+ "@jakubmazanec/args": "1.0.1-dee6883",
35
+ "@jakubmazanec/cli": "0.1.0-dee6883",
36
+ "@jakubmazanec/error": "2.0.1-dee6883",
37
+ "@jakubmazanec/fs-utils": "0.1.0-dee6883",
38
+ "@jakubmazanec/template": "1.0.1-dee6883",
39
+ "@jakubmazanec/ts-utils": "2.1.0-dee6883",
40
+ "@jakubmazanec/zod-utils": "1.0.0-dee6883",
41
41
  "chalk": "^5.2.0",
42
42
  "diff": "^5.1.0",
43
43
  "fast-glob": "^3.2.11",
@@ -1,5 +1,5 @@
1
1
  /**
2
- * {@link Workspace.create | Workspace.create} options parameter.
2
+ * {@link Workspace.create} options parameter.
3
3
  */
4
4
  export type WorkspaceCreateOptions = {
5
5
  path: string;