forked from valentin-aleksandrov/core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
195 lines (163 loc) · 5.48 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* eslint-disable no-unused-vars */
// npm run release -- --addition,subtraction
const { series } = require('gulp');
const fs = require('fs');
const { join } = require('path');
const { spawn } = require('child_process');
const { PublishCommand } = require('@lerna/publish');
const git = require('simple-git')(__dirname);
const pkg = require('./package.json');
const typescript = require('rollup-plugin-typescript2');
const commonjs = require('@rollup/plugin-commonjs');
const node_resolve = require('@rollup/plugin-node-resolve');
const json = require('@rollup/plugin-json');
const terser = require('rollup-plugin-terser').terser;
const rollup = require('rollup');
const replace = require('@rollup/plugin-replace');
// const sync = require('./scripts/preversion/sync.js');
const stableBranch = 'master';
const releaseBranch = 'release-V2';
const ignored = ['.git', '.log', 'node_modules', 'packages', '.md', 'package-lock', '.vscode', 'demos', 'live-examples', '.cache', 'archive', 'e2e', 'tutorials', 'templates'];
const packagesDirectory = join(__dirname, '/packages/');
let packagesDirNamesToRelease = [];
let fullRelease = false;
const readDirPromise = (directory) => {
return new Promise((resolve, reject) => {
fs.readdir(directory, (err, files) => {
if (err) {
return reject(err);
}
resolve(files);
});
});
};
const validateReleasePackages = async () => {
packagesDirNamesToRelease = process.argv[3].replace('--', '').split(',');
if (packagesDirNamesToRelease.includes('all')) {
fullRelease = true;
return;
}
const areNamesValidType = packagesDirNamesToRelease.every((name) => (typeof name === 'string') && name.length > 0);
if (!areNamesValidType) {
throw new Error(`Invalid packages names: ${JSON.stringify(packagesDirNamesToRelease)}`);
}
const areNamesExisting = packagesDirNamesToRelease.every((pkgName) => fs.existsSync(join(packagesDirectory, pkgName)));
if (!areNamesExisting) {
throw new Error(`Non-existent packages names: ${JSON.stringify(packagesDirNamesToRelease)}`);
}
};
const checkout = async (branchName) => {
await git.checkout(branchName);
};
const checkoutRelease = async () => {
await checkout(releaseBranch);
await git.pull();
};
const checkoutMaster = async () => {
await checkout(stableBranch);
process.exitCode = 0;
};
const syncAllContentsExceptPackages = async () => {
const rootContents = await readDirPromise(__dirname);
const itemToSync = rootContents.filter((element) => !ignored.some((igElement) => element.includes(igElement)));
itemToSync.push('.gitignore');
for (const item of itemToSync) {
console.log(`checking out ${item}`);
await git.raw(['checkout', stableBranch, item]);
}
};
const syncPackagesToRelease = async () => {
if (fullRelease) {
console.log('Checking out all packages for full release');
await git.raw(['checkout', stableBranch, 'packages/']);
return;
}
for (const packageName of packagesDirNamesToRelease) {
console.log(`checking out ${packageName}`);
await git.raw(['checkout', stableBranch, `packages/${packageName}`]);
}
};
const bootstrap = () => {
return new Promise((resolve, reject) => {
const npmCommand = process.platform === 'win32'
? 'npm.cmd'
: 'npm';
const child = spawn(npmCommand, ['run', 'bootstrap'], { stdio: 'inherit' });
child.on('error', reject);
child.on('exit', (code) => {
if (code === 1) {
reject();
}
resolve();
});
});
};
// const versionSync = async () => {
// await sync(git, false);
// };
const addCommit = async (message) => {
await git.add('.');
await git.commit(message, undefined, { '--no-verify': null });
};
const commitIsolatedPackages = async () => {
await addCommit('Release package/s isolated');
};
const publish = async () => {
const command = new PublishCommand({});
await command.runner;
};
const buildGtf = async (name) => {
console.log(`Runner?: ${process.env.RUNNER}`);
const buildConfig = {
input: './e2e/config/gtf/index.ts',
external: [
...Object.keys(pkg.peerDependencies || {}),
],
plugins: [
typescript({
typescript: require('typescript')
}),
json(),
commonjs(),
node_resolve.default({
mainFields: ['module', 'main', 'browser']
}),
terser(),
replace({
preventAssignment: true,
exclude: 'node_modules/**',
'process.env.RUNNER': JSON.stringify(process.env.RUNNER)
})
]
};
const bundle = await rollup.rollup(buildConfig);
await bundle.write({
file: './e2e/config/gtf.js',
name: name,
format: 'umd',
sourcemap: false
});
};
exports.release = series(
validateReleasePackages,
checkoutRelease,
syncAllContentsExceptPackages,
syncPackagesToRelease,
bootstrap,
commitIsolatedPackages,
publish,
checkoutMaster
);
exports.buildGtf = series(
buildGtf
);
// stopped publish and checkoutMaster to allow for dist-tags
// exports.release = series(
// validateReleasePackages,
// checkoutRelease,
// syncAllContentsExceptPackages,
// syncPackagesToRelease,
// bootstrap,
// versionSync,
// commitIsolatedPackages
// );