-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-samples.js
More file actions
executable file
·149 lines (127 loc) · 3.77 KB
/
build-samples.js
File metadata and controls
executable file
·149 lines (127 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env node
const childProcess = require('child_process');
const fs = require('fs');
const path = require('path');
const sharp = require('sharp');
// Keep this info for later
var prevDotHaxelibPath = null;
// Retrieve samples lists
const samplesList = [];
for (item of fs.readFileSync(path.join(__dirname, 'samples.txt'), 'utf8').split('\n')) {
item = item.trim();
if (item.length > 0) {
samplesList.push(item);
}
}
/**
* Run a command
*/
function command(cmd, args, options) {
if (options == null) {
options = {};
}
options.stdio = 'inherit';
childProcess.execFileSync(cmd, args, options);
}
/**
* Build the given sample
*/
function build(sample, done) {
console.log('');
console.log(' --- build sample: ' + sample + ' ---');
console.log('');
// Recycle local haxelib directory to prevent having to redownload libs for each sample
var dotHaxelibPath = path.join(__dirname, sample, '.haxelib');
if (prevDotHaxelibPath != null) {
if (!fs.existsSync(dotHaxelibPath)) {
command('mv', [
prevDotHaxelibPath,
dotHaxelibPath
]);
}
}
prevDotHaxelibPath = dotHaxelibPath;
command(
'ceramic',
['clay', 'build', 'web', '--setup', '--assets', '-D', 'ceramic_web_minify', '-D', 'ceramic_no_skip', '-D', 'ceramic_allow_default_mouse_wheel', '-D', 'ceramic_allow_default_touches'],
{
cwd: path.join(__dirname, sample)
}
);
command('mv', [
path.join(__dirname, sample, 'project', 'web'),
path.join(__dirname, '_export', sample)
]);
var gitignorePath = path.join(__dirname, '_export', sample, '.gitignore');
if (fs.existsSync(gitignorePath)) {
fs.unlinkSync(gitignorePath);
}
var screenshotPath = path.join(__dirname, sample, 'screenshot.png');
var exportScreenshotPath = path.join(__dirname, '_export', sample, 'screenshot.png');
var exportScreenshot400Path = path.join(__dirname, '_export', sample, 'thumbnail.png');
if (fs.existsSync(screenshotPath)) {
console.log('Copy screenshot');
command('cp', [
screenshotPath,
exportScreenshotPath
]);
sharp(screenshotPath)
.resize({ width: 320 })
.toFile(exportScreenshot400Path)
.then(function() {
done();
});
}
else {
var screenshotGifPath = path.join(__dirname, sample, 'screenshot.gif');
var exportScreenshotGifPath = path.join(__dirname, '_export', sample, 'screenshot.gif');
if (fs.existsSync(screenshotGifPath)) {
console.log('Copy screenshot (gif)');
command('cp', [
screenshotGifPath,
exportScreenshotGifPath
]);
done();
}
else {
done();
}
}
}
// Reset _export directory
if (fs.existsSync('_export'))
command('rm', ['-rf', '_export']);
command('mkdir', ['_export']);
var remainingSamples = [].concat(samplesList);
function buildNext() {
if (remainingSamples.length > 0) {
build(remainingSamples.shift(), buildNext);
}
else {
allBuilt();
}
}
function allBuilt() {
// Generate index
//
var sampleLinks = [];
for (sample of samplesList) {
sampleLinks.push('<li><a href="' + sample + '">' + sample + '</a></li>');
}
var indexHtml = `
<!DOCTYPE html>
<html>
<head>
<title>Ceramic Samples</title>
</head>
<body>
<ul>
${sampleLinks.join('\n ')}
</ul>
</body>
</html>
`.trim();
fs.writeFileSync(path.join(__dirname, '_export', 'index.html'), indexHtml);
}
// Start building
buildNext();