@jakubmazanec/carson 0.2.1-unstable.9ab3865 → 0.3.0-next.dc4435e
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/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -1
- package/dist/constants.js.map +1 -1
- package/dist/template/applyTemplateRenders.js +1 -12
- package/dist/template/applyTemplateRenders.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +0 -1
- package/src/template/applyTemplateRenders.ts +1 -15
package/dist/constants.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export declare const PACKAGE_PATH: string;
|
|
|
2
2
|
export declare const CARSON_CONFIG_DIRECTORY = ".carson";
|
|
3
3
|
export declare const PROJECT_CONFIG_FILENAME = "project.json";
|
|
4
4
|
export declare const WORKSPACE_CONFIG_FILENAME = "workspace.json";
|
|
5
|
-
export declare const SNAPSHOTS_FILENAME = ".snapshots";
|
|
6
5
|
export declare const PROJECT_SNAPSHOT_FILENAME = "project.snapshot";
|
|
7
6
|
export declare const WORKSPACE_SNAPSHOT_FILENAME = "workspace.snapshot";
|
|
8
7
|
export declare const TEMPLATES_PATH = "templates";
|
package/dist/constants.js
CHANGED
|
@@ -5,7 +5,6 @@ export const PACKAGE_PATH = path.resolve(directory, '..');
|
|
|
5
5
|
export const CARSON_CONFIG_DIRECTORY = '.carson';
|
|
6
6
|
export const PROJECT_CONFIG_FILENAME = 'project.json';
|
|
7
7
|
export const WORKSPACE_CONFIG_FILENAME = 'workspace.json';
|
|
8
|
-
export const SNAPSHOTS_FILENAME = '.snapshots';
|
|
9
8
|
export const PROJECT_SNAPSHOT_FILENAME = 'project.snapshot';
|
|
10
9
|
export const WORKSPACE_SNAPSHOT_FILENAME = 'workspace.snapshot';
|
|
11
10
|
export const TEMPLATES_PATH = 'templates';
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["import path from 'node:path';\nimport url from 'node:url';\n\nlet directory = path.dirname(url.fileURLToPath(import.meta.url));\n\nexport const PACKAGE_PATH = path.resolve(directory, '..');\n\nexport const CARSON_CONFIG_DIRECTORY = '.carson';\nexport const PROJECT_CONFIG_FILENAME = 'project.json';\nexport const WORKSPACE_CONFIG_FILENAME = 'workspace.json';\nexport const
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["import path from 'node:path';\nimport url from 'node:url';\n\nlet directory = path.dirname(url.fileURLToPath(import.meta.url));\n\nexport const PACKAGE_PATH = path.resolve(directory, '..');\n\nexport const CARSON_CONFIG_DIRECTORY = '.carson';\nexport const PROJECT_CONFIG_FILENAME = 'project.json';\nexport const WORKSPACE_CONFIG_FILENAME = 'workspace.json';\nexport const PROJECT_SNAPSHOT_FILENAME = 'project.snapshot';\nexport const WORKSPACE_SNAPSHOT_FILENAME = 'workspace.snapshot';\nexport const TEMPLATES_PATH = 'templates';\nexport const TEMPLATE_CONFIG_FILENAME = 'config.json';\nexport const PACKAGE_JSON_FILENAME = 'package.json';\n"],"names":["path","url","directory","dirname","fileURLToPath","PACKAGE_PATH","resolve","CARSON_CONFIG_DIRECTORY","PROJECT_CONFIG_FILENAME","WORKSPACE_CONFIG_FILENAME","PROJECT_SNAPSHOT_FILENAME","WORKSPACE_SNAPSHOT_FILENAME","TEMPLATES_PATH","TEMPLATE_CONFIG_FILENAME","PACKAGE_JSON_FILENAME"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAC7B,OAAOC,SAAS,WAAW;AAE3B,IAAIC,YAAYF,KAAKG,OAAO,CAACF,IAAIG,aAAa,CAAC,YAAYH,GAAG;AAE9D,OAAO,MAAMI,eAAeL,KAAKM,OAAO,CAACJ,WAAW,MAAM;AAE1D,OAAO,MAAMK,0BAA0B,UAAU;AACjD,OAAO,MAAMC,0BAA0B,eAAe;AACtD,OAAO,MAAMC,4BAA4B,iBAAiB;AAC1D,OAAO,MAAMC,4BAA4B,mBAAmB;AAC5D,OAAO,MAAMC,8BAA8B,qBAAqB;AAChE,OAAO,MAAMC,iBAAiB,YAAY;AAC1C,OAAO,MAAMC,2BAA2B,cAAc;AACtD,OAAO,MAAMC,wBAAwB,eAAe"}
|
|
@@ -4,19 +4,12 @@ import path from 'node:path';
|
|
|
4
4
|
import prettier from 'prettier';
|
|
5
5
|
import { CarsonTemplateError } from './CarsonTemplateError.js';
|
|
6
6
|
import { createUsingTemplateRender, deleteUsingTemplateRender, insertUsingTemplateRender, loadTemplateRenderSnapshots, mergeUsingTemplateRender, overwriteUsingTemplateRender, saveTemplateRenderSnapshots, uninsertUsingTemplateRender, unmergeUsingTemplateRender } from './internals.js';
|
|
7
|
-
import { CARSON_CONFIG_DIRECTORY
|
|
7
|
+
import { CARSON_CONFIG_DIRECTORY } from '../constants.js';
|
|
8
8
|
/**
|
|
9
9
|
* Applies rendered Carson template to a specified path, i.e. creates and updates files based on the result of rendering each Carson template file.
|
|
10
10
|
*/ export async function applyTemplateRenders({ templateRenders, targetPath, snapshotPath, ignoreStrategies }) {
|
|
11
11
|
// we need to clear Prettier cache, because we are changing file system
|
|
12
12
|
await prettier.clearConfigCache();
|
|
13
|
-
// TODO: remove all logic about legacy snapshots after Carson reaches v1
|
|
14
|
-
// use previous version of snapshot file if it exists
|
|
15
|
-
let legacySnapshotPath = path.join(targetPath, CARSON_CONFIG_DIRECTORY, SNAPSHOTS_FILENAME);
|
|
16
|
-
if (await fs.pathExists(legacySnapshotPath)) {
|
|
17
|
-
// eslint-disable-next-line no-param-reassign -- needed; also, this is temporary feature
|
|
18
|
-
snapshotPath = legacySnapshotPath;
|
|
19
|
-
}
|
|
20
13
|
// first, we read the existing snapshots and use them to undo previous changes
|
|
21
14
|
if (await fs.pathExists(snapshotPath)) {
|
|
22
15
|
let templateRenderSnapshots = await loadTemplateRenderSnapshots(snapshotPath);
|
|
@@ -92,10 +85,6 @@ import { CARSON_CONFIG_DIRECTORY, SNAPSHOTS_FILENAME } from '../constants.js';
|
|
|
92
85
|
}
|
|
93
86
|
await fs.ensureDir(path.join(targetPath, CARSON_CONFIG_DIRECTORY));
|
|
94
87
|
await saveTemplateRenderSnapshots(templateRenders, snapshotPath);
|
|
95
|
-
// delete legacy snapshots
|
|
96
|
-
if (await fs.pathExists(legacySnapshotPath)) {
|
|
97
|
-
await fs.rm(legacySnapshotPath);
|
|
98
|
-
}
|
|
99
88
|
}
|
|
100
89
|
|
|
101
90
|
//# sourceMappingURL=applyTemplateRenders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/template/applyTemplateRenders.ts"],"sourcesContent":["// TODO: can this be fixed?\n/* eslint-disable complexity -- TODO */\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport prettier from 'prettier';\n\nimport {CarsonTemplateError} from './CarsonTemplateError.js';\nimport {\n createUsingTemplateRender,\n deleteUsingTemplateRender,\n insertUsingTemplateRender,\n loadTemplateRenderSnapshots,\n mergeUsingTemplateRender,\n overwriteUsingTemplateRender,\n saveTemplateRenderSnapshots,\n uninsertUsingTemplateRender,\n unmergeUsingTemplateRender,\n} from './internals.js';\nimport {type TemplateRenders} from './TemplateRenders.js';\nimport {CARSON_CONFIG_DIRECTORY
|
|
1
|
+
{"version":3,"sources":["../../src/template/applyTemplateRenders.ts"],"sourcesContent":["// TODO: can this be fixed?\n/* eslint-disable complexity -- TODO */\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport prettier from 'prettier';\n\nimport {CarsonTemplateError} from './CarsonTemplateError.js';\nimport {\n createUsingTemplateRender,\n deleteUsingTemplateRender,\n insertUsingTemplateRender,\n loadTemplateRenderSnapshots,\n mergeUsingTemplateRender,\n overwriteUsingTemplateRender,\n saveTemplateRenderSnapshots,\n uninsertUsingTemplateRender,\n unmergeUsingTemplateRender,\n} from './internals.js';\nimport {type TemplateRenders} from './TemplateRenders.js';\nimport {CARSON_CONFIG_DIRECTORY} from '../constants.js';\n\nexport type ApplyTemplateRendersOptions = {\n templateRenders: TemplateRenders;\n targetPath: string;\n snapshotPath: string;\n ignoreStrategies: string[];\n};\n\n/**\n * Applies rendered Carson template to a specified path, i.e. creates and updates files based on the result of rendering each Carson template file.\n */\nexport async function applyTemplateRenders({\n templateRenders,\n targetPath,\n snapshotPath,\n ignoreStrategies,\n}: ApplyTemplateRendersOptions) {\n // we need to clear Prettier cache, because we are changing file system\n await prettier.clearConfigCache();\n\n // first, we read the existing snapshots and use them to undo previous changes\n if (await fs.pathExists(snapshotPath)) {\n let templateRenderSnapshots = await loadTemplateRenderSnapshots(snapshotPath);\n\n for (let templateRenderSnapshot of templateRenderSnapshots) {\n let strategy =\n typeof templateRenderSnapshot.attributes.strategy === 'string'\n ? templateRenderSnapshot.attributes.strategy\n : templateRenderSnapshot.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'ensure') {\n await deleteUsingTemplateRender(templateRenderSnapshot, targetPath, {\n onlyDeleteWhenContentsMatch: true,\n });\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'overwrite') {\n await deleteUsingTemplateRender(templateRenderSnapshot, targetPath);\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'merge') {\n await unmergeUsingTemplateRender(templateRenderSnapshot, targetPath);\n }\n\n if (templateRenderSnapshot.attributes.strategy[0] === 'insert') {\n await uninsertUsingTemplateRender(templateRenderSnapshot, targetPath);\n }\n }\n }\n\n // second, we apply strategies that create files\n for (let templateRender of templateRenders) {\n let strategy =\n typeof templateRender.attributes.strategy === 'string'\n ? templateRender.attributes.strategy\n : templateRender.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRender.attributes.strategy === 'create') {\n await createUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'ensure') {\n let to = path.join(targetPath, templateRender.attributes.to);\n let doesToExist = await fs.pathExists(to);\n\n if (!doesToExist) {\n await createUsingTemplateRender(templateRender, targetPath);\n }\n }\n }\n\n // third, we apply strategies that change files\n for (let templateRender of templateRenders) {\n let strategy =\n typeof templateRender.attributes.strategy === 'string'\n ? templateRender.attributes.strategy\n : templateRender.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRender.attributes.strategy === 'overwrite') {\n await overwriteUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'merge') {\n await mergeUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy[0] === 'insert') {\n await insertUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'check') {\n let to = path.join(targetPath, templateRender.attributes.to);\n let doesToExist = await fs.pathExists(to);\n\n if (!doesToExist) {\n throw new CarsonTemplateError('STRATEGY_MISSING_FILE', {\n messageParameters: [templateRender.attributes.strategy, templateRender.template.path, to],\n data: {\n path: to,\n },\n });\n }\n }\n }\n\n await fs.ensureDir(path.join(targetPath, CARSON_CONFIG_DIRECTORY));\n\n await saveTemplateRenderSnapshots(templateRenders, snapshotPath);\n}\n"],"names":["fs","path","prettier","CarsonTemplateError","createUsingTemplateRender","deleteUsingTemplateRender","insertUsingTemplateRender","loadTemplateRenderSnapshots","mergeUsingTemplateRender","overwriteUsingTemplateRender","saveTemplateRenderSnapshots","uninsertUsingTemplateRender","unmergeUsingTemplateRender","CARSON_CONFIG_DIRECTORY","applyTemplateRenders","templateRenders","targetPath","snapshotPath","ignoreStrategies","clearConfigCache","pathExists","templateRenderSnapshots","templateRenderSnapshot","strategy","attributes","includes","onlyDeleteWhenContentsMatch","templateRender","to","join","doesToExist","messageParameters","template","data","ensureDir"],"mappings":"AAAA,2BAA2B;AAC3B,qCAAqC,GACrC,OAAOA,QAAQ,WAAW;AAC1B,OAAOC,UAAU,YAAY;AAC7B,OAAOC,cAAc,WAAW;AAEhC,SAAQC,mBAAmB,QAAO,2BAA2B;AAC7D,SACEC,yBAAyB,EACzBC,yBAAyB,EACzBC,yBAAyB,E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ACJ,eAAeH,UAAU,CAACD,QAAQ;wBAAEI,eAAeK,QAAQ,CAAC/B,IAAI;wBAAE2B;qBAAG;oBACzFK,MAAM;wBACJhC,MAAM2B;oBACR;gBACF;YACF;QACF;IACF;IAEA,MAAM5B,GAAGkC,SAAS,CAACjC,KAAK4B,IAAI,CAACb,YAAYH;IAEzC,MAAMH,4BAA4BK,iBAAiBE;AACrD"}
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -8,7 +8,6 @@ export const PACKAGE_PATH = path.resolve(directory, '..');
|
|
|
8
8
|
export const CARSON_CONFIG_DIRECTORY = '.carson';
|
|
9
9
|
export const PROJECT_CONFIG_FILENAME = 'project.json';
|
|
10
10
|
export const WORKSPACE_CONFIG_FILENAME = 'workspace.json';
|
|
11
|
-
export const SNAPSHOTS_FILENAME = '.snapshots';
|
|
12
11
|
export const PROJECT_SNAPSHOT_FILENAME = 'project.snapshot';
|
|
13
12
|
export const WORKSPACE_SNAPSHOT_FILENAME = 'workspace.snapshot';
|
|
14
13
|
export const TEMPLATES_PATH = 'templates';
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
unmergeUsingTemplateRender,
|
|
18
18
|
} from './internals.js';
|
|
19
19
|
import {type TemplateRenders} from './TemplateRenders.js';
|
|
20
|
-
import {CARSON_CONFIG_DIRECTORY
|
|
20
|
+
import {CARSON_CONFIG_DIRECTORY} from '../constants.js';
|
|
21
21
|
|
|
22
22
|
export type ApplyTemplateRendersOptions = {
|
|
23
23
|
templateRenders: TemplateRenders;
|
|
@@ -38,15 +38,6 @@ export async function applyTemplateRenders({
|
|
|
38
38
|
// we need to clear Prettier cache, because we are changing file system
|
|
39
39
|
await prettier.clearConfigCache();
|
|
40
40
|
|
|
41
|
-
// TODO: remove all logic about legacy snapshots after Carson reaches v1
|
|
42
|
-
// use previous version of snapshot file if it exists
|
|
43
|
-
let legacySnapshotPath = path.join(targetPath, CARSON_CONFIG_DIRECTORY, SNAPSHOTS_FILENAME);
|
|
44
|
-
|
|
45
|
-
if (await fs.pathExists(legacySnapshotPath)) {
|
|
46
|
-
// eslint-disable-next-line no-param-reassign -- needed; also, this is temporary feature
|
|
47
|
-
snapshotPath = legacySnapshotPath;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
41
|
// first, we read the existing snapshots and use them to undo previous changes
|
|
51
42
|
if (await fs.pathExists(snapshotPath)) {
|
|
52
43
|
let templateRenderSnapshots = await loadTemplateRenderSnapshots(snapshotPath);
|
|
@@ -147,9 +138,4 @@ export async function applyTemplateRenders({
|
|
|
147
138
|
await fs.ensureDir(path.join(targetPath, CARSON_CONFIG_DIRECTORY));
|
|
148
139
|
|
|
149
140
|
await saveTemplateRenderSnapshots(templateRenders, snapshotPath);
|
|
150
|
-
|
|
151
|
-
// delete legacy snapshots
|
|
152
|
-
if (await fs.pathExists(legacySnapshotPath)) {
|
|
153
|
-
await fs.rm(legacySnapshotPath);
|
|
154
|
-
}
|
|
155
141
|
}
|