-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgatsby-node.js
executable file
·143 lines (123 loc) · 4.37 KB
/
gatsby-node.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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const path = require("path");
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;
const mdTemplate = path.resolve(`src/templates/MarkdownTemplate.js`);
return graphql(`
{
allMarkdownRemark {
edges {
node {
frontmatter {
path
subnav
lang
title
}
}
}
}
}
`).then(result => {
if (result.errors) {
return Promise.reject(result.errors);
}
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.frontmatter.path,
component: mdTemplate,
});
});
});
};
const sass = require("node-sass");
var fs = require('fs');
exports.onPreBootstrap = () => {
// compile aurora.css for dist folder
sass.render({
file: path.join(__dirname, '/src/utils/custom.scss'),
outputStyle: 'nested',
outFile: path.join(__dirname, "/public/static/"),
}, function(error, result) {
if(!error){
// No errors during the compilation, write this result on the disk
fs.writeFile(path.join(__dirname, "/public/static/aurora.css"), result.css, function(err){
if(!err){
//file written on disk
} else {
console.log(err);
}
});
}
});
// compile aurora.min.css for dist folder
sass.render({
file: path.join(__dirname, '/src/utils/custom.scss'),
outputStyle: 'compressed',
outFile: path.join(__dirname, "/public/static/"),
}, function(error, result) {
if(!error){
// No errors during the compilation, write this result on the disk
fs.writeFile(path.join(__dirname, "/public/static/aurora.min.css"), result.css, function(err){
if(!err){
//file written on disk
} else {
console.log(err);
}
});
}
});
}
exports.onPostBootstrap = () => {
var archiver = require('archiver');
// create a file to stream archive data to.
var output = fs.createWriteStream(__dirname + '/public/static/aurora.zip');
var archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on('end', function() {
console.log('Data has been drained');
});
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', function(err) {
if (err.code === 'ENOENT') {
// log warning
} else {
// throw error
throw err;
}
});
// good practice to catch this error explicitly
archive.on('error', function(err) {
throw err;
});
// pipe archive data to the file
archive.pipe(output);
// append a file from stream
var file1 = __dirname + '/public/static/aurora.css';
archive.append(fs.createReadStream(file1), { name: 'aurora.css' });
var file2 = __dirname + '/public/static/aurora.min.css';
archive.append(fs.createReadStream(file2), { name: 'aurora.min.css' });
var file3 = __dirname + '/src/dist/aurora.js';
archive.append(fs.createReadStream(file3), { name: 'aurora.js' });
var file4 = __dirname + '/src/dist/aurora.min.js';
archive.append(fs.createReadStream(file4), { name: 'aurora.min.js' });
// finalize the archive (ie we are done appending files but streams have to finish yet)
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
archive.finalize();
}
/*
exports.onPostBuild = () => {
fs.copySync(
path.join(__dirname, "/src/img")
);
};
*/