forked from asmyshlyaev177/react-horizontal-scrolling-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-gp.js
93 lines (69 loc) · 2.49 KB
/
deploy-gp.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
/*
* Script for deploy new version to github-pages
*
* 1 change version in package.json
* 2 npm publish
* 3 run this script (npm run deploy)
* */
import path from 'path';
import fs from 'fs';
import { execSync } from 'child_process';
import ghpages from 'gh-pages';
const rootPath = path.resolve(__dirname, './');
const examplePath = path.normalize(path.resolve(rootPath, 'example-nextjs'));
// eslint-disable-next-line radar/no-duplicate-string
const packageJsonPath = path.normalize(path.resolve(rootPath, 'package.json'));
const updatePackageJson = (examplePath) => {
const versionForReplace = parseFile(packageJsonPath).version;
const examplePackageJsonPath = path.resolve(examplePath, 'package.json');
const examplePackageJsonContent = parseFile(examplePackageJsonPath);
examplePackageJsonContent.dependencies[
'react-horizontal-scrolling-menu'
] = `^${versionForReplace}`;
examplePackageJsonContent.homepage =
'https://asmyshlyaev177.github.io/react-horizontal-scrolling-menu/';
writeFile(examplePackageJsonContent, examplePackageJsonPath);
return examplePath;
};
const deploy = (path) => {
process.chdir(path);
execSync('yarn install', { cwd: path });
execSync('NODE_ENV=production npx next build', { cws: path });
execSync('NODE_ENV=production npx next export -o dist', { cws: path });
// github pages ignore folders with staring with _ like _next
// this file tell jekyll don't ignore it
execSync('touch dist/.nojekyll', { cws: path });
ghpages.publish('dist', { dotfiles: true });
return path;
};
// for testing purposes
const restorePackageJson = (examplePath) => {
const examplePackageJsonPath = path.resolve(examplePath, 'package.json');
const examplePackageJsonContent = parseFile(examplePackageJsonPath);
examplePackageJsonContent.dependencies['react-horizontal-scrolling-menu'] =
'link:../.';
writeFile(examplePackageJsonContent, examplePackageJsonPath);
execSync('yarn install', { cwd: examplePath });
return examplePath;
};
const writeFile = (file, path) =>
fs.writeFileSync(path, JSON.stringify(file, null, 2));
const parseFile = (file) => {
const filePath = fs.readFileSync(file);
return JSON.parse(filePath);
};
const compose =
(...fns) =>
(val) =>
fns.reduce((acc, fn) => fn(acc), val);
const doTheMagicAndDeploy = compose(
updatePackageJson,
deploy,
restorePackageJson
);
function main() {
console.log('Working...');
doTheMagicAndDeploy(examplePath);
console.log('New version of example deployed!');
}
main();