@lightdash/cli 0.1467.1 → 0.1469.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/handlers/compile.js +2 -20
- package/dist/handlers/deploy.js +1 -1
- package/dist/lightdash-config/index.d.ts +1 -2
- package/dist/lightdash-config/index.js +11 -14
- package/dist/lightdash-config/lightdash-config.test.d.ts +1 -0
- package/dist/lightdash-config/lightdash-config.test.js +66 -0
- package/package.json +3 -3
package/dist/handlers/compile.js
CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compileHandler = exports.compile = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const common_1 = require("@lightdash/common");
|
6
|
-
const fs_1 = require("fs");
|
7
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
8
7
|
const uuid_1 = require("uuid");
|
9
8
|
const analytics_1 = require("../analytics/analytics");
|
@@ -11,28 +10,11 @@ const context_1 = require("../dbt/context");
|
|
11
10
|
const manifest_1 = require("../dbt/manifest");
|
12
11
|
const validation_1 = require("../dbt/validation");
|
13
12
|
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
13
|
+
const lightdash_config_1 = require("../lightdash-config");
|
14
14
|
const styles = tslib_1.__importStar(require("../styles"));
|
15
15
|
const compile_1 = require("./dbt/compile");
|
16
16
|
const getDbtVersion_1 = require("./dbt/getDbtVersion");
|
17
17
|
const getWarehouseClient_1 = tslib_1.__importDefault(require("./dbt/getWarehouseClient"));
|
18
|
-
const readAndLoadLightdashProjectConfig = async (projectDir) => {
|
19
|
-
const configPath = path_1.default.join(projectDir, 'lightdash.config.yml');
|
20
|
-
try {
|
21
|
-
const fileContents = await fs_1.promises.readFile(configPath, 'utf8');
|
22
|
-
const config = await (0, common_1.loadLightdashProjectConfig)(fileContents);
|
23
|
-
return config;
|
24
|
-
}
|
25
|
-
catch (e) {
|
26
|
-
globalState_1.default.debug(`No lightdash.config.yml found in ${configPath}`);
|
27
|
-
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
|
28
|
-
// Return default config if file doesn't exist
|
29
|
-
return {
|
30
|
-
spotlight: common_1.DEFAULT_SPOTLIGHT_CONFIG,
|
31
|
-
};
|
32
|
-
}
|
33
|
-
throw e;
|
34
|
-
}
|
35
|
-
};
|
36
18
|
const compile = async (options) => {
|
37
19
|
const dbtVersion = await (0, getDbtVersion_1.getDbtVersion)();
|
38
20
|
globalState_1.default.debug(`> dbt version ${dbtVersion}`);
|
@@ -92,7 +74,7 @@ ${errors.join('')}`));
|
|
92
74
|
}
|
93
75
|
globalState_1.default.debug(`> Converting explores with adapter: ${manifest.metadata.adapter_type}`);
|
94
76
|
globalState_1.default.debug(`> Loading lightdash project config from ${absoluteProjectPath}`);
|
95
|
-
const lightdashProjectConfig = await readAndLoadLightdashProjectConfig(absoluteProjectPath);
|
77
|
+
const lightdashProjectConfig = await (0, lightdash_config_1.readAndLoadLightdashProjectConfig)(absoluteProjectPath);
|
96
78
|
globalState_1.default.debug(`> Loaded lightdash project config`);
|
97
79
|
const validExplores = await (0, common_1.convertExplores)(validModelsWithTypes, false, manifest.metadata.adapter_type, [
|
98
80
|
common_1.DbtManifestVersion.V10,
|
package/dist/handlers/deploy.js
CHANGED
@@ -44,7 +44,7 @@ const deploy = async (explores, options) => {
|
|
44
44
|
process.exit(1);
|
45
45
|
}
|
46
46
|
}
|
47
|
-
const lightdashProjectConfig = await (0, lightdash_config_1.
|
47
|
+
const lightdashProjectConfig = await (0, lightdash_config_1.readAndLoadLightdashProjectConfig)(path_1.default.resolve(options.projectDir));
|
48
48
|
await replaceProjectYamlTags(options.projectUuid, lightdashProjectConfig);
|
49
49
|
await (0, apiClient_1.lightdashApi)({
|
50
50
|
method: 'PUT',
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
export declare const loadLightdashProjectConfig: (configPath: string) => Promise<LightdashProjectConfig>;
|
1
|
+
export declare const readAndLoadLightdashProjectConfig: (projectDir: string) => Promise<import("@lightdash/common").LightdashProjectConfig>;
|
@@ -1,23 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.readAndLoadLightdashProjectConfig = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const common_1 = require("@lightdash/common");
|
6
|
-
const
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
6
|
+
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
8
|
+
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
9
|
+
const readAndLoadLightdashProjectConfig = async (projectDir) => {
|
10
|
+
const configPath = path_1.default.join(projectDir, 'lightdash.config.yml');
|
11
11
|
try {
|
12
|
-
const
|
13
|
-
const
|
14
|
-
|
15
|
-
const errors = (0, better_ajv_errors_1.default)(common_1.lightdashProjectConfigSchema, configFile, validate.errors || [], { indent: 2 });
|
16
|
-
throw new common_1.ParseError(`Invalid lightdash.config.yml at ${configPath}\n${errors}`);
|
17
|
-
}
|
18
|
-
return configFile;
|
12
|
+
const fileContents = await promises_1.default.readFile(configPath, 'utf8');
|
13
|
+
const config = await (0, common_1.loadLightdashProjectConfig)(fileContents);
|
14
|
+
return config;
|
19
15
|
}
|
20
16
|
catch (e) {
|
17
|
+
globalState_1.default.debug(`No lightdash.config.yml found in ${configPath}`);
|
21
18
|
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
|
22
19
|
// Return default config if file doesn't exist
|
23
20
|
return {
|
@@ -27,4 +24,4 @@ const loadLightdashProjectConfig = async (configPath) => {
|
|
27
24
|
throw e;
|
28
25
|
}
|
29
26
|
};
|
30
|
-
exports.
|
27
|
+
exports.readAndLoadLightdashProjectConfig = readAndLoadLightdashProjectConfig;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const tslib_1 = require("tslib");
|
4
|
+
const common_1 = require("@lightdash/common");
|
5
|
+
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
6
|
+
const _1 = require(".");
|
7
|
+
const VALID_CONFIG_CONTENTS = 'spotlight:\n' +
|
8
|
+
' default_visibility: show # Optional, defaults to "show"\n' +
|
9
|
+
' categories:\n' +
|
10
|
+
' core:\n' +
|
11
|
+
' label: "Core Metrics"\n' +
|
12
|
+
' color: blue\n' +
|
13
|
+
' experimental:\n' +
|
14
|
+
' label: "Experimental Metrics"\n' +
|
15
|
+
' color: orange\n' +
|
16
|
+
' sales:\n' +
|
17
|
+
' label: "Sales"\n' +
|
18
|
+
' color: green\n';
|
19
|
+
const VALID_CONFIG = {
|
20
|
+
spotlight: {
|
21
|
+
default_visibility: 'show',
|
22
|
+
categories: {
|
23
|
+
core: { label: 'Core Metrics', color: 'blue' },
|
24
|
+
experimental: { label: 'Experimental Metrics', color: 'orange' },
|
25
|
+
sales: { label: 'Sales', color: 'green' },
|
26
|
+
},
|
27
|
+
},
|
28
|
+
};
|
29
|
+
const INVALID_CONFIG_CONTENTS = 'I am invalid';
|
30
|
+
const readFileSpy = jest.spyOn(promises_1.default, 'readFile');
|
31
|
+
describe('Existing lightdash.config.yml file', () => {
|
32
|
+
describe('when valid', () => {
|
33
|
+
it('should load the config file', async () => {
|
34
|
+
readFileSpy.mockResolvedValueOnce(VALID_CONFIG_CONTENTS);
|
35
|
+
const config = await (0, _1.readAndLoadLightdashProjectConfig)('');
|
36
|
+
expect(config).toEqual(VALID_CONFIG);
|
37
|
+
});
|
38
|
+
});
|
39
|
+
describe('when invalid', () => {
|
40
|
+
it('should throw an error', async () => {
|
41
|
+
readFileSpy.mockResolvedValueOnce(INVALID_CONFIG_CONTENTS);
|
42
|
+
await expect((0, _1.readAndLoadLightdashProjectConfig)('')).rejects.toThrow(/Invalid lightdash.config.yml with errors/);
|
43
|
+
});
|
44
|
+
});
|
45
|
+
});
|
46
|
+
class MockedFSError extends Error {
|
47
|
+
code;
|
48
|
+
constructor(message, code) {
|
49
|
+
super(message);
|
50
|
+
this.code = code;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
describe('Missing lightdash.config.yml file', () => {
|
54
|
+
it('should load the default config', async () => {
|
55
|
+
// ! Throwing a mock error, not something we should rely on but when running the test in jest `e instanceof Error` is false, but when running the code in node it is true
|
56
|
+
// ! Check: https://github.com/jestjs/jest/issues/11808
|
57
|
+
readFileSpy.mockRejectedValueOnce(new MockedFSError('file not found', 'ENOENT'));
|
58
|
+
const config = await (0, _1.readAndLoadLightdashProjectConfig)('./some/path/to/nonexisting/file');
|
59
|
+
expect(config).toEqual({
|
60
|
+
spotlight: common_1.DEFAULT_SPOTLIGHT_CONFIG,
|
61
|
+
});
|
62
|
+
});
|
63
|
+
});
|
64
|
+
afterAll(() => {
|
65
|
+
jest.restoreAllMocks();
|
66
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lightdash/cli",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1469.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"bin": {
|
6
6
|
"lightdash": "dist/index.js"
|
@@ -30,8 +30,8 @@
|
|
30
30
|
"parse-node-version": "^2.0.0",
|
31
31
|
"unique-names-generator": "^4.7.1",
|
32
32
|
"uuid": "^11.0.3",
|
33
|
-
"@lightdash/common": "0.
|
34
|
-
"@lightdash/warehouses": "0.
|
33
|
+
"@lightdash/common": "0.1469.0",
|
34
|
+
"@lightdash/warehouses": "0.1469.0"
|
35
35
|
},
|
36
36
|
"description": "Lightdash CLI tool",
|
37
37
|
"devDependencies": {
|