forked from okta/samples-js-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
60 lines (53 loc) · 1.74 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { series, src, dest, parallel } = require('gulp');
const clean = require('gulp-clean');
const fs = require('fs');
const shell = require('shelljs');
const cleanDir = dir => () => {
return src(dir, { read: false, allowEmpty: true })
.pipe(clean({ force: true }));
};
const cloneOktaReact = (done) => {
shell.exec('git clone --single-branch --branch master https://github.com/okta/okta-react.git');
done();
};
const copySample = sample => () => {
return src(['*', '.*'].map(regex => `okta-react/samples/${sample}/**/${regex}`))
.pipe(dest(`${sample}/`));
};
const getPublishedModuleVersion = (module, cb) => {
const stdout = shell.exec(`yarn info ${module} dist-tags --json`, { silent: true });
const distTags = JSON.parse(stdout);
const version = distTags.data.latest;
console.log(`Last published ${module} version: `, version);
cb && cb();
return version;
};
const updatePackageJson = sample => (done) => {
const oktaReactVersion = getPublishedModuleVersion('@okta/okta-react');
console.log(oktaReactVersion);
const packageJSON = JSON.parse(fs.readFileSync(`./${sample}/package.json`));
packageJSON.dependencies['@okta/okta-react'] = `^${oktaReactVersion}`;
delete packageJSON.comment;
fs.writeFileSync(`./${sample}/package.json`, JSON.stringify(packageJSON, null, 2));
console.log(packageJSON);
done();
};
module.exports = {
'pull-samples': series(
parallel(
cleanDir('okta-react'),
cleanDir('custom-login'),
cleanDir('okta-hosted-login')
),
cloneOktaReact,
parallel(
copySample('okta-hosted-login'),
copySample('custom-login')
),
parallel(
updatePackageJson('okta-hosted-login'),
updatePackageJson('custom-login')
),
cleanDir('okta-react')
)
};