mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
async file operations
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
40103a80e4
commit
9306693570
@ -18,7 +18,7 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import fs from "fs";
|
import fse from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import hb from "handlebars";
|
import hb from "handlebars";
|
||||||
import { ResourceApplier } from "../../main/resource-applier";
|
import { ResourceApplier } from "../../main/resource-applier";
|
||||||
@ -40,7 +40,7 @@ export class ResourceStack {
|
|||||||
* @param templateContext sets the template parameters that are to be applied to any templated kubernetes resources that are to be applied.
|
* @param templateContext sets the template parameters that are to be applied to any templated kubernetes resources that are to be applied.
|
||||||
*/
|
*/
|
||||||
async kubectlApplyFolder(folderPath: string, templateContext?: any, extraArgs?: string[]): Promise<string> {
|
async kubectlApplyFolder(folderPath: string, templateContext?: any, extraArgs?: string[]): Promise<string> {
|
||||||
const resources = this.renderTemplates(folderPath, templateContext);
|
const resources = await this.renderTemplates(folderPath, templateContext);
|
||||||
|
|
||||||
return this.applyResources(resources, extraArgs);
|
return this.applyResources(resources, extraArgs);
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ export class ResourceStack {
|
|||||||
* @param templateContext sets the template parameters that are to be applied to any templated kubernetes resources that are to be applied.
|
* @param templateContext sets the template parameters that are to be applied to any templated kubernetes resources that are to be applied.
|
||||||
*/
|
*/
|
||||||
async kubectlDeleteFolder(folderPath: string, templateContext?: any, extraArgs?: string[]): Promise<string> {
|
async kubectlDeleteFolder(folderPath: string, templateContext?: any, extraArgs?: string[]): Promise<string> {
|
||||||
const resources = this.renderTemplates(folderPath, templateContext);
|
const resources = await this.renderTemplates(folderPath, templateContext);
|
||||||
|
|
||||||
return this.deleteResources(resources, extraArgs);
|
return this.deleteResources(resources, extraArgs);
|
||||||
}
|
}
|
||||||
@ -112,13 +112,15 @@ export class ResourceStack {
|
|||||||
return kubectlArgs;
|
return kubectlArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderTemplates(folderPath: string, templateContext: any): string[] {
|
protected async renderTemplates(folderPath: string, templateContext: any): Promise<string[]> {
|
||||||
const resources: string[] = [];
|
const resources: string[] = [];
|
||||||
|
|
||||||
logger.info(`[RESOURCE-STACK]: render templates from ${folderPath}`);
|
logger.info(`[RESOURCE-STACK]: render templates from ${folderPath}`);
|
||||||
fs.readdirSync(folderPath).forEach(filename => {
|
const files = await fse.readdir(folderPath);
|
||||||
|
|
||||||
|
for(const filename of files) {
|
||||||
const file = path.join(folderPath, filename);
|
const file = path.join(folderPath, filename);
|
||||||
const raw = fs.readFileSync(file);
|
const raw = await fse.readFile(file);
|
||||||
let resourceData: string;
|
let resourceData: string;
|
||||||
|
|
||||||
if (filename.endsWith(".hb")) {
|
if (filename.endsWith(".hb")) {
|
||||||
@ -143,7 +145,7 @@ export class ResourceStack {
|
|||||||
|
|
||||||
resources.push(yaml.safeDump(resource));
|
resources.push(yaml.safeDump(resource));
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user