forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.ts
More file actions
135 lines (119 loc) · 4.41 KB
/
docs.ts
File metadata and controls
135 lines (119 loc) · 4.41 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
import { createReadStream, writeFileSync } from 'fs';
import { join, relative } from 'path';
import * as Dgeni from 'dgeni';
import { split, map } from 'event-stream';
import { src, dest, task } from 'gulp';
import { AllHtmlEntities } from 'html-entities';
import * as mkdirp from 'mkdirp';
import { valid }from 'semver';
import { argv } from 'yargs';
import { DEMOS_ROOT } from '../constants';
task('docs', ['docs.dgeni', 'docs.copyDemos', 'docs.sassVariables']);
task('docs.dgeni', () => {
const docVersion = argv['doc-version'] || 'nightly';
const initialVersionBuild = argv['initial-build'] || false;
if (docVersion !== 'nightly' && ! valid(docVersion)) {
console.log('Usage: gulp docs --doc-version=(nightly|versionName)\nversionName must be a valid semver version.');
return process.exit(1);
}
try {
const ionicPackage = require('../../docs/dgeni-config')(docVersion, initialVersionBuild);
const dgeni = new Dgeni([ionicPackage]);
return dgeni.generate();
} catch (err) {
console.log(err.stack);
}
});
task('docs.demos', ['demos.build'], (done: Function) => {
const config = require('../../config.json');
const outputDir = join(config.docsDest, 'demos');
let promises = [];
promises.push(copyDemoCss(join(outputDir, 'css')));
promises.push(copyDemoFonts(join(outputDir, 'fonts')));
promises.push(copyDemoPolyfills(join(outputDir, 'polyfills')));
promises.push(copyDemoContent(join(outputDir, 'src')));
Promise.all(promises).then(() => {
done();
}).catch(err => {
done(err);
});
});
function copyDemoCss(outputDir: string) {
return new Promise((resolve, reject) => {
const stream = src(`${DEMOS_ROOT}/css/*`).pipe(dest(outputDir));
stream.on('end', () => {
resolve();
});
});
}
function copyDemoFonts(outputDir: string) {
return new Promise((resolve, reject) => {
const stream = src(`${DEMOS_ROOT}/fonts/*`).pipe(dest(outputDir));
stream.on('end', () => {
resolve();
});
});
}
function copyDemoPolyfills(outputDir: string) {
return new Promise((resolve, reject) => {
const stream = src(`${DEMOS_ROOT}/polyfills/*`).pipe(dest(outputDir));
stream.on('end', () => {
resolve();
});
});
}
function copyDemoContent(outputDir: string) {
return new Promise((resolve, reject) => {
const stream = src([`${DEMOS_ROOT}/src/**/index.html`, `${DEMOS_ROOT}/src/**/main.bundle.js`, `${DEMOS_ROOT}/src/scrollbar-fix.*`]).pipe(dest(outputDir));
stream.on('end', () => {
resolve();
});
});
}
task('docs.sassVariables', () => {
let variables = [];
const outputFile = 'tmp/sass.json';
function addVariable(variableName, defaultValue, file) {
const entities = new AllHtmlEntities();
defaultValue = entities.encode(defaultValue);
defaultValue = defaultValue.replace('!default;', '');
variables.push({
name: variableName,
defaultValue: defaultValue.trim(),
file: relative('./', file.path)
});
}
return src('./src/**/*.scss')
.pipe(map((file, callback) => {
let variableLine, variableName, defaultValue, multiline;
createReadStream(file.path, { flags: 'r'})
.pipe(split())
.pipe(map((line, callback) => {
if (line.charAt(0) === '$') {
variableLine = line.split(/:(.+)/);
variableName = variableLine[0];
defaultValue = variableLine[1];
// If there is a semicolon then it isn't a multiline value
multiline = line.indexOf(';') > -1 ? false : true;
if (!multiline && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
}
} else if (multiline === true) {
defaultValue += '\n' + line;
// If the line has a semicolon then we've found the end of the value
if (line.indexOf(';') > -1 && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
multiline = false;
}
}
callback();
}));
callback();
}).on('end', () => {
const config = require('../../config.json');
console.log(`Writing to file at /driftyco/ionic/${outputFile}`);
console.log(`Place this file in /driftyco/ionic-site/${config.v2DocsDir}/theming/overriding-ionic-variables in order to update the docs`);
mkdirp.sync('tmp');
writeFileSync(outputFile, JSON.stringify(variables));
}));
});