@lightdash/cli 0.1386.4 → 0.1387.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -49,9 +49,6 @@ export declare const lightdashApi: <T extends string | boolean | unknown[] | imp
|
|
49
49
|
owner: string;
|
50
50
|
} | import("@lightdash/common").KnexPaginatedData<import("@lightdash/common").ApiMetricsCatalogResults> | import("@lightdash/common").MetricsExplorerQueryResults | import("@lightdash/common").KnexPaginatedData<import("@lightdash/common").Group[] | import("@lightdash/common").GroupWithMembers[]> | {
|
51
51
|
tagUuid: string;
|
52
|
-
} | import("@lightdash/common").ChartAsCode[] | {
|
53
|
-
chart: import("@lightdash/common").ChartAsCode;
|
54
|
-
created: boolean;
|
55
|
-
} | null | undefined>({ method, url, body, }: LightdashApiProps) => Promise<T>;
|
52
|
+
} | import("@lightdash/common").ChartAsCode[] | null | undefined>({ method, url, body, }: LightdashApiProps) => Promise<T>;
|
56
53
|
export declare const checkLightdashVersion: () => Promise<void>;
|
57
54
|
export {};
|
@@ -70,7 +70,22 @@ const uploadHandler = async (options) => {
|
|
70
70
|
const filePath = path.join(inputDir, file);
|
71
71
|
const fileContent = await fs_1.promises.readFile(filePath, 'utf-8');
|
72
72
|
const chart = yaml.load(fileContent);
|
73
|
-
|
73
|
+
const fileUpdatedAt = (await fs_1.promises.stat(filePath)).mtime;
|
74
|
+
// We override the updatedAt to the file's updatedAt
|
75
|
+
// in case there were some changes made locally
|
76
|
+
// do not override if the file was just created
|
77
|
+
const downloadedAt = chart.downloadedAt
|
78
|
+
? new Date(chart.downloadedAt)
|
79
|
+
: undefined;
|
80
|
+
const needsUpdating = downloadedAt &&
|
81
|
+
Math.abs(fileUpdatedAt.getTime() - downloadedAt.getTime()) >
|
82
|
+
30000;
|
83
|
+
const locallyUpdatedChart = {
|
84
|
+
...chart,
|
85
|
+
updatedAt: needsUpdating ? fileUpdatedAt : chart.updatedAt,
|
86
|
+
needsUpdating: needsUpdating ?? true, // if downloadAt is not set, we force the update
|
87
|
+
};
|
88
|
+
charts.push(locallyUpdatedChart);
|
74
89
|
}
|
75
90
|
}
|
76
91
|
catch (error) {
|
@@ -82,21 +97,51 @@ const uploadHandler = async (options) => {
|
|
82
97
|
console.info(`Found ${charts.length} chart files`);
|
83
98
|
let created = 0;
|
84
99
|
let updated = 0;
|
100
|
+
let deleted = 0;
|
101
|
+
let skipped = 0;
|
102
|
+
let spacesCreated = 0;
|
103
|
+
let spacesUpdated = 0;
|
85
104
|
try {
|
86
105
|
for (const chart of charts) {
|
106
|
+
if (!chart.needsUpdating) {
|
107
|
+
globalState_1.default.debug(`Skipping chart "${chart.slug}" with no local changes`);
|
108
|
+
skipped += 1;
|
109
|
+
// eslint-disable-next-line no-continue
|
110
|
+
continue;
|
111
|
+
}
|
87
112
|
globalState_1.default.debug(`Upserting chart ${chart.slug}`);
|
88
113
|
const chartData = await (0, apiClient_1.lightdashApi)({
|
89
114
|
method: 'POST',
|
90
115
|
url: `/api/v1/projects/${projectId}/charts/${chart.slug}/code`,
|
91
116
|
body: JSON.stringify(chart),
|
92
117
|
});
|
93
|
-
|
94
|
-
|
95
|
-
|
118
|
+
globalState_1.default.debug(`Chart "${chart.name}": ${chartData.charts[0].action}`);
|
119
|
+
switch (chartData.spaces[0].action) {
|
120
|
+
case common_1.PromotionAction.CREATE:
|
121
|
+
spacesCreated += 1;
|
122
|
+
break;
|
123
|
+
case common_1.PromotionAction.UPDATE:
|
124
|
+
spacesUpdated += 1;
|
125
|
+
break;
|
126
|
+
default:
|
127
|
+
// ignore the rest
|
96
128
|
}
|
97
|
-
|
98
|
-
|
99
|
-
|
129
|
+
switch (chartData.charts[0].action) {
|
130
|
+
case common_1.PromotionAction.CREATE:
|
131
|
+
created += 1;
|
132
|
+
break;
|
133
|
+
case common_1.PromotionAction.UPDATE:
|
134
|
+
updated += 1;
|
135
|
+
break;
|
136
|
+
case common_1.PromotionAction.DELETE:
|
137
|
+
deleted += 1;
|
138
|
+
break;
|
139
|
+
case common_1.PromotionAction.NO_CHANGES:
|
140
|
+
skipped += 1;
|
141
|
+
break;
|
142
|
+
default:
|
143
|
+
globalState_1.default.debug(`Unknown action: ${chartData.charts[0].action}`);
|
144
|
+
break;
|
100
145
|
}
|
101
146
|
}
|
102
147
|
}
|
@@ -105,5 +150,10 @@ const uploadHandler = async (options) => {
|
|
105
150
|
}
|
106
151
|
console.info(`Total charts created: ${created} `);
|
107
152
|
console.info(`Total charts updated: ${updated} `);
|
153
|
+
console.info(`Total charts skipped: ${skipped} `);
|
154
|
+
if (deleted > 0)
|
155
|
+
console.info(`Total charts deleted: ${deleted} `); // We should not delete charts from the CLI
|
156
|
+
console.info(`Total spaces created: ${spacesCreated} `);
|
157
|
+
console.info(`Total spaces updated: ${spacesUpdated} `);
|
108
158
|
};
|
109
159
|
exports.uploadHandler = uploadHandler;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lightdash/cli",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1387.1",
|
4
4
|
"license": "MIT",
|
5
5
|
"bin": {
|
6
6
|
"lightdash": "dist/index.js"
|
@@ -11,8 +11,8 @@
|
|
11
11
|
],
|
12
12
|
"dependencies": {
|
13
13
|
"@actions/core": "^1.11.1",
|
14
|
-
"@lightdash/common": "^0.
|
15
|
-
"@lightdash/warehouses": "^0.
|
14
|
+
"@lightdash/common": "^0.1387.1",
|
15
|
+
"@lightdash/warehouses": "^0.1387.1",
|
16
16
|
"@types/columnify": "^1.5.1",
|
17
17
|
"ajv": "^8.11.0",
|
18
18
|
"ajv-formats": "^2.1.1",
|