-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.mjs
84 lines (72 loc) · 2.95 KB
/
deploy.mjs
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
#!/usr/bin/env node
import { exec as execCallback, spawn } from 'child_process';
import util from 'util';
import os from "os";
import margv from "margv";
import fs from "fs-extra";
import prompts from "prompts";
import path from "path";
const cwd = './';
const red = "\x1b[31m";
const green = "\x1b[32m";
const black = "\x1b[0m";
const exec = util.promisify(execCallback);
const platform = os.platform();
const osType = os.type();
const pkg = await fs.readJson(path.resolve("./package.json"));
let [node, script, commit = `v${pkg.version}`] = process.argv;
const args = margv();
commit = args.m || commit;
if(!commit) {
console.log(red, "Commit label not set. Aborting...", black);
process.exit(0);
}
const response = await prompts({
type: 'text',
name: 'value',
message: `Создать коммит ${commit}? Y/N`,
validate: value => value < 18 ? `Y or N` : true
});
if(response.value.toLowerCase() !== 'y') {
process.exit(0);
}
console.log(platform, osType);
/**
* C:\Program Files\Git\usr\bin
*
* Exec command
* @param {String} command
* @param {Array} args
* @param options
* @return {Promise<Number>}
*/
const spawnLog = (command, args = [], options = {}) => new Promise((resolve, reject) => {
options = Object.assign({
cwd, shell: true,
stdio: "inherit"
}, options);
const stream = spawn(command, args, options);
stream.on('close', code => resolve(code));
});
// hide loggin --quiet --silent -s
console.log(green, "1. Создание сборки", black);
await spawnLog("yarn build");
console.log(green, "2. Создание коммита " + commit, black);
await spawnLog("git add .", [], {stdio: "ignore"});
await spawnLog(`git commit -m "${commit}"`, [], {stdio: "ignore"});
await spawnLog("git push", [], {stdio: "ignore"});
if(/^v\d+\.\d+\.\d+$/.test(commit)) {
console.log(green, "2.1 Создание тега " + commit, black);
await spawnLog(`git tag "${commit}"`, [], {stdio: "ignore"});
await spawnLog("git push --tags", [], {stdio: "ignore"});
}
console.log(green, "3. Создание комита документации", black);
await spawnLog("git --git-dir=docs/.vitepress/dist/.git --work-tree=docs/.vitepress/dist add .", [], {stdio: "ignore"});
await spawnLog(`git --git-dir=docs/.vitepress/dist/.git --work-tree=docs/.vitepress/dist commit -m "${commit}"`, [], {stdio: "ignore"});
await spawnLog("git --git-dir=docs/.vitepress/dist/.git --work-tree=docs/.vitepress/dist push", [], {stdio: "ignore"});
console.log(green, "4. Публикация в npm", black);
await spawnLog("yarn publish ./dist --access=public --new-version=" + pkg.version, [], {stdio: "ignore"});
console.log(green, "5. Процесс успешно завершен", black);
console.log("GitHub", "https://github.com/webigorkiev/vue-touch-ripple/");
console.log("GitHub Pages", "https://webigorkiev.github.io/vue-touch-ripple-docs/");
console.log("npm", "https://www.npmjs.com/package/@vuemod/vue-touch-ripple");