Skip to content

Commit 5033515

Browse files
committed
chore: Bump gulp and node-fetch in Kyma
1 parent da3fb6a commit 5033515

File tree

1 file changed

+40
-50
lines changed

1 file changed

+40
-50
lines changed

kyma/gulpfile.js

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const fetch = require('node-fetch');
2-
const URL = require('url').URL;
3-
const fs = require('fs');
4-
const jsyaml = require('js-yaml');
1+
import fetch from 'node-fetch';
2+
import { URL } from 'url';
3+
import { readFile, lstatSync, readdirSync } from 'fs';
4+
import { load, dump } from 'js-yaml';
55

6-
const gulp = require('gulp');
7-
const through2 = require('through2');
8-
const concat = require('gulp-concat');
9-
const clean = require('gulp-clean');
6+
import { task, src, dest } from 'gulp';
7+
import { obj as _obj } from 'through2';
8+
import concat from 'gulp-concat';
9+
import clean from 'gulp-clean';
1010

1111
const mapValues = (obj, fn) =>
1212
Object.fromEntries(
@@ -21,12 +21,12 @@ const isUrl = str => {
2121
}
2222
};
2323

24-
const loadExtensions = through2.obj(async function(extensionsFile, _, cb) {
24+
const loadExtensions = _obj(async function(extensionsFile, _, cb) {
2525
const list = JSON.parse(extensionsFile.contents.toString());
2626

2727
const readLocalFile = filePath =>
2828
new Promise((resolve, reject) =>
29-
fs.readFile(filePath, (err, data) => {
29+
readFile(filePath, (err, data) => {
3030
if (err) {
3131
reject(err);
3232
} else {
@@ -50,9 +50,8 @@ const loadExtensions = through2.obj(async function(extensionsFile, _, cb) {
5050
if (isUrl(source)) {
5151
return readExternalFile(source);
5252
} else {
53-
if (fs.lstatSync(source).isDirectory()) {
54-
return fs
55-
.readdirSync(source)
53+
if (lstatSync(source).isDirectory()) {
54+
return readdirSync(source)
5655
.map(name => readLocalFile(source + '/' + name));
5756
} else {
5857
return readLocalFile(source);
@@ -71,9 +70,9 @@ const loadExtensions = through2.obj(async function(extensionsFile, _, cb) {
7170
cb();
7271
});
7372

74-
const loadPreparedExtensions = through2.obj((file, _, cb) => {
73+
const loadPreparedExtensions = _obj((file, _, cb) => {
7574
const convertYamlToObject = yamlString => {
76-
return jsyaml.load(yamlString, { json: true });
75+
return load(yamlString, { json: true });
7776
};
7877

7978
const checkExtensionVersion = metadata => {
@@ -87,102 +86,93 @@ const loadPreparedExtensions = through2.obj((file, _, cb) => {
8786
}
8887
};
8988

90-
const { data, metadata } = jsyaml.load(file.contents.toString());
89+
const { data, metadata } = load(file.contents.toString());
9190

9291
checkExtensionVersion(metadata);
9392

9493
file.contents = Buffer.from(
95-
jsyaml.dump(mapValues(data, convertYamlToObject)),
94+
dump(mapValues(data, convertYamlToObject)),
9695
);
9796
cb(null, file);
9897
});
9998

100-
gulp.task('clean-extensions', () => {
99+
task('clean-extensions', () => {
101100
const env = process.env.ENV;
102-
return gulp
103-
.src(`environments/temp/${env}/extensions-local`, {
101+
return src(`environments/temp/${env}/extensions-local`, {
104102
read: false,
105103
allowEmpty: true,
106104
})
107105
.pipe(clean({ force: true }));
108106
});
109107

110-
gulp.task('get-extensions', () => {
111-
return gulp
112-
.src(`environments/${process.env.ENV}/extensions.json`)
108+
task('get-extensions', () => {
109+
return src(`environments/${process.env.ENV}/extensions.json`)
113110
.pipe(loadExtensions)
114-
.pipe(gulp.dest(`temp/${process.env.ENV}/extensions-local/-/-`)); // gulp strips the 2 last path components?
111+
.pipe(dest(`temp/${process.env.ENV}/extensions-local/-/-`)); // gulp strips the 2 last path components?
115112
});
116113

117-
gulp.task('pack-extensions', () => {
114+
task('pack-extensions', () => {
118115
const env = process.env.ENV;
119-
return gulp
120-
.src(`temp/${env}/extensions-local/**/*.yaml`)
116+
return src(`temp/${env}/extensions-local/**/*.yaml`)
121117
.pipe(loadPreparedExtensions)
122118
.pipe(
123119
concat('extensions.yaml', {
124120
newLine: '---\n',
125121
}),
126122
)
127-
.pipe(gulp.dest(`build/${env}/extensions`));
123+
.pipe(dest(`build/${env}/extensions`));
128124
});
129125

130-
gulp.task('clean-statics', () => {
126+
task('clean-statics', () => {
131127
const env = process.env.ENV;
132-
return gulp
133-
.src(`environments/temp/${env}/extensions/statics-local`, {
128+
return src(`environments/temp/${env}/extensions/statics-local`, {
134129
read: false,
135130
allowEmpty: true,
136131
})
137132
.pipe(clean());
138133
});
139134

140-
gulp.task('get-statics', () => {
141-
return gulp
142-
.src(`environments/${process.env.ENV}/statics.json`)
135+
task('get-statics', () => {
136+
return src(`environments/${process.env.ENV}/statics.json`)
143137
.pipe(loadExtensions)
144-
.pipe(gulp.dest(`temp/${process.env.ENV}/statics-local/-/-`)); // gulp strips the 2 last path components?
138+
.pipe(dest(`temp/${process.env.ENV}/statics-local/-/-`)); // gulp strips the 2 last path components?
145139
});
146140

147-
gulp.task('pack-statics', () => {
141+
task('pack-statics', () => {
148142
const env = process.env.ENV;
149-
return gulp
150-
.src(`temp/${env}/statics-local/**/*.yaml`)
143+
return src(`temp/${env}/statics-local/**/*.yaml`)
151144
.pipe(loadPreparedExtensions)
152145
.pipe(
153146
concat('statics.yaml', {
154147
newLine: '---\n',
155148
}),
156149
)
157-
.pipe(gulp.dest(`build${env}/extensions`));
150+
.pipe(dest(`build${env}/extensions`));
158151
});
159152

160-
gulp.task('clean-wizards', () => {
153+
task('clean-wizards', () => {
161154
const env = process.env.ENV;
162-
return gulp
163-
.src(`environments/temp/${env}/extensions/wizards-local`, {
155+
return src(`environments/temp/${env}/extensions/wizards-local`, {
164156
read: false,
165157
allowEmpty: true,
166158
})
167159
.pipe(clean());
168160
});
169161

170-
gulp.task('get-wizards', () => {
171-
return gulp
172-
.src(`environments/${process.env.ENV}/wizards.json`)
162+
task('get-wizards', () => {
163+
return src(`environments/${process.env.ENV}/wizards.json`)
173164
.pipe(loadExtensions)
174-
.pipe(gulp.dest(`temp/${process.env.ENV}/wizards-local/-/-`)); // gulp strips the 2 last path components?
165+
.pipe(dest(`temp/${process.env.ENV}/wizards-local/-/-`)); // gulp strips the 2 last path components?
175166
});
176167

177-
gulp.task('pack-wizards', () => {
168+
task('pack-wizards', () => {
178169
const env = process.env.ENV;
179-
return gulp
180-
.src(`temp/${env}/wizards-local/**/*.yaml`)
170+
return src(`temp/${env}/wizards-local/**/*.yaml`)
181171
.pipe(loadPreparedExtensions)
182172
.pipe(
183173
concat('wizards.yaml', {
184174
newLine: '---\n',
185175
}),
186176
)
187-
.pipe(gulp.dest(`build/${env}/extensions`));
177+
.pipe(dest(`build/${env}/extensions`));
188178
});

0 commit comments

Comments
 (0)