This repository was archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathclaat-export.js
89 lines (82 loc) · 2.88 KB
/
claat-export.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
/**
* @fileoverview Gulp Task exporting CLAAT related docs.
*
* @author Pete LePage <[email protected]>
*/
'use strict';
const gulp = require('gulp');
const path = require('path');
const glob = require('globule');
const wfHelper = require('./wfHelper');
const runSequence = require('run-sequence');
const wfCodeLabHelper = require('./wfCodeLabHelper');
/**
* Update the files using the claat tool then return a list of files
*
* @param {string} srcPath Where to run the claat tool.
* @return {Promise} The promise with the list of all files updated.
*/
function getCLAATFiles(srcPath) {
let cmd = '../../../tools/claat update';
return new Promise(function(resolve, reject) {
wfHelper.promisedExec(cmd, srcPath)
.then(function() {
let opts = {
srcBase: srcPath,
prefixBase: true,
};
let files = glob.find('**/index.md', opts);
resolve(files);
});
});
}
/**
* Updates files, and copies them to the appropriate directory
*
* @param {string} srcPath The source directory to find the files.
* @param {string} destBase The destination to copy to.
* @param {Boolean} flatten Whether to flatten the files to one directory.
* @param {string} bookPath The location of the book.yaml file
* @param {string} projPath The location of the project.yaml file
* @return {Promise} The promise that will be resolved on completion.
*/
function exportAndUpdate(srcPath, destBase, flatten, bookPath, projPath) {
return getCLAATFiles(srcPath)
.then(function(files) {
return Promise.all(files.map(function(file) {
let srcFile = file;
let srcImgPath = file.replace('index.md', 'img/');
let destDir = file.replace(srcPath, '').replace('/index.md', '');
destDir = path.join(destBase, destDir);
let destFile = path.join(destDir, 'index.md');
if (flatten === true) {
destDir = path.resolve(destDir, '..');
destFile = destFile.replace('/index.md', '.md');
}
let destImgPath = path.join(destDir, 'img');
wfCodeLabHelper.updateCodeLab(srcFile, destFile, bookPath, projPath);
return wfHelper.promisedRSync(srcImgPath, destImgPath);
}));
});
}
gulp.task('claat:codelabs', function() {
const srcPath = 'src/data/codelabs';
const destPath = path.join(global.WF.src.content, 'fundamentals/codelabs');
const bookPath = '/web/fundamentals/_book.yaml';
const projPath = '/web/fundamentals/_project.yaml';
return exportAndUpdate(srcPath, destPath, false, bookPath, projPath);
});
gulp.task('claat:ilt-pwa', function() {
const srcPath = 'src/data/ilt-pwa';
const destPath = path.join(global.WF.src.content, 'ilt/pwa');
const bookPath = '/web/ilt/pwa/_book.yaml';
const projPath = '/web/_project.yaml';
return exportAndUpdate(srcPath, destPath, true, bookPath, projPath);
});
gulp.task('claat:all', function(callback) {
runSequence(
['claat:codelabs',
'claat:ilt-pwa'],
callback
);
});