@lightdash/cli 0.2038.1 → 0.2039.1
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/dbt/context.js
CHANGED
|
@@ -7,6 +7,7 @@ const fs_1 = require("fs");
|
|
|
7
7
|
const yaml = tslib_1.__importStar(require("js-yaml"));
|
|
8
8
|
const path = tslib_1.__importStar(require("path"));
|
|
9
9
|
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
|
10
|
+
const templating_1 = require("./templating");
|
|
10
11
|
const getDbtContext = async ({ projectDir, initialProjectDir, }) => {
|
|
11
12
|
globalState_1.default.debug(`> Loading dbt_project.yml file from: ${projectDir}`);
|
|
12
13
|
const projectFilename = path.join(projectDir, 'dbt_project.yml');
|
|
@@ -25,7 +26,9 @@ const getDbtContext = async ({ projectDir, initialProjectDir, }) => {
|
|
|
25
26
|
const msg = (0, common_1.getErrorMessage)(e);
|
|
26
27
|
throw new common_1.ParseError(`Is ${initialProjectDir} a valid dbt project directory? Couldn't find a valid dbt_project.yml on ${initialProjectDir} or any of its parents:\n ${msg}`);
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
// Render Jinja templating (e.g., env_var) before parsing YAML
|
|
30
|
+
const renderedFile = (0, templating_1.renderProfilesYml)(file);
|
|
31
|
+
const config = yaml.load(renderedFile);
|
|
29
32
|
const targetSubDir = config['target-path'] || './target';
|
|
30
33
|
globalState_1.default.debug(`> dbt target directory: ${targetSubDir}`);
|
|
31
34
|
const targetDir = path.join(projectDir, targetSubDir);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const os = tslib_1.__importStar(require("os"));
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
const context_1 = require("./context");
|
|
8
|
+
describe('getDbtContext', () => {
|
|
9
|
+
const { env } = process;
|
|
10
|
+
let tempDir;
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
jest.resetModules();
|
|
13
|
+
process.env = { ...env };
|
|
14
|
+
// Create a temporary directory for test files
|
|
15
|
+
tempDir = await fs_1.promises.mkdtemp(path.join(os.tmpdir(), 'dbt-context-test-'));
|
|
16
|
+
});
|
|
17
|
+
afterEach(async () => {
|
|
18
|
+
process.env = env;
|
|
19
|
+
// Clean up temporary directory
|
|
20
|
+
await fs_1.promises.rm(tempDir, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
describe('target-path with env_var templating', () => {
|
|
23
|
+
test('should resolve env_var in target-path', async () => {
|
|
24
|
+
process.env.DBT_ENV__TARGET_FOLDER = 'custom-target';
|
|
25
|
+
const dbtProjectContent = `name: test_project
|
|
26
|
+
profile: test_profile
|
|
27
|
+
target-path: "{{ env_var('DBT_ENV__TARGET_FOLDER', 'target') }}"
|
|
28
|
+
models-path: "models"
|
|
29
|
+
`;
|
|
30
|
+
await fs_1.promises.writeFile(path.join(tempDir, 'dbt_project.yml'), dbtProjectContent);
|
|
31
|
+
const context = await (0, context_1.getDbtContext)({ projectDir: tempDir });
|
|
32
|
+
expect(context.targetDir).toBe(path.join(tempDir, 'custom-target'));
|
|
33
|
+
expect(context.projectName).toBe('test_project');
|
|
34
|
+
expect(context.profileName).toBe('test_profile');
|
|
35
|
+
});
|
|
36
|
+
test('should use default value when env_var is not set', async () => {
|
|
37
|
+
const dbtProjectContent = `name: test_project
|
|
38
|
+
profile: test_profile
|
|
39
|
+
target-path: "{{ env_var('DBT_ENV__TARGET_FOLDER', 'target') }}"
|
|
40
|
+
models-path: "models"
|
|
41
|
+
`;
|
|
42
|
+
await fs_1.promises.writeFile(path.join(tempDir, 'dbt_project.yml'), dbtProjectContent);
|
|
43
|
+
const context = await (0, context_1.getDbtContext)({ projectDir: tempDir });
|
|
44
|
+
expect(context.targetDir).toBe(path.join(tempDir, 'target'));
|
|
45
|
+
});
|
|
46
|
+
test('should work with models-path env_var', async () => {
|
|
47
|
+
process.env.DBT_MODELS_PATH = 'custom-models';
|
|
48
|
+
const dbtProjectContent = `name: test_project
|
|
49
|
+
profile: test_profile
|
|
50
|
+
target-path: "target"
|
|
51
|
+
models-path: "{{ env_var('DBT_MODELS_PATH', 'models') }}"
|
|
52
|
+
`;
|
|
53
|
+
await fs_1.promises.writeFile(path.join(tempDir, 'dbt_project.yml'), dbtProjectContent);
|
|
54
|
+
const context = await (0, context_1.getDbtContext)({ projectDir: tempDir });
|
|
55
|
+
expect(context.modelsDir).toBe(path.join(tempDir, 'custom-models'));
|
|
56
|
+
});
|
|
57
|
+
test('should work without any templating', async () => {
|
|
58
|
+
const dbtProjectContent = `name: test_project
|
|
59
|
+
profile: test_profile
|
|
60
|
+
target-path: "target"
|
|
61
|
+
models-path: "models"
|
|
62
|
+
`;
|
|
63
|
+
await fs_1.promises.writeFile(path.join(tempDir, 'dbt_project.yml'), dbtProjectContent);
|
|
64
|
+
const context = await (0, context_1.getDbtContext)({ projectDir: tempDir });
|
|
65
|
+
expect(context.targetDir).toBe(path.join(tempDir, 'target'));
|
|
66
|
+
expect(context.modelsDir).toBe(path.join(tempDir, 'models'));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2039.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"lightdash": "dist/index.js"
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"parse-node-version": "^2.0.0",
|
|
33
33
|
"unique-names-generator": "^4.7.1",
|
|
34
34
|
"uuid": "^11.0.3",
|
|
35
|
-
"@lightdash/
|
|
36
|
-
"@lightdash/
|
|
35
|
+
"@lightdash/warehouses": "0.2039.1",
|
|
36
|
+
"@lightdash/common": "0.2039.1"
|
|
37
37
|
},
|
|
38
38
|
"description": "Lightdash CLI tool",
|
|
39
39
|
"devDependencies": {
|