forked from valentin-aleksandrov/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
135 lines (110 loc) · 3.77 KB
/
Copy pathgulpfile.js
File metadata and controls
135 lines (110 loc) · 3.77 KB
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
// 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/promise')(__dirname);
const sync = require('./scripts/preversion/sync.js');
const stableBranch = 'master';
const releaseBranch = 'release';
const ignored = ['.git', '.log', 'node_modules', 'packages', '.md', 'package-lock', '.vscode', 'demos', 'live-examples'];
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;
};
exports.release = series(
validateReleasePackages,
checkoutRelease,
syncAllContentsExceptPackages,
syncPackagesToRelease,
bootstrap,
versionSync,
commitIsolatedPackages,
publish,
checkoutMaster
);