Skip to content

Commit 1706a76

Browse files
authored
Merge pull request #1094 from junaidrsd/fix-dev-default-styles-option
Improvement in default styles management and fix dev gulp task
2 parents c50db4d + 2bd02bb commit 1706a76

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ Install plugin locally:
6161
npm install sc5-styleguide --save-dev
6262
```
6363

64-
Install without global default styles
65-
66-
```bash
67-
npm install sc5-styleguide --excludeDefaultStyles=true
68-
```
69-
7064
The gulp plugin contains two functions that requires different set of file streams:
7165

7266
`generate()`: All unprocessed styles containing the KSS markup and style variables. This will process the KSS markup and collects variable information.
@@ -228,8 +222,8 @@ Enables side navigation. When this option parameter is enabled, styleguide will
228222

229223
When this option parameter is enabled, style guide will show reference numbers on navigation, headings and designer tool.
230224

231-
<a name="option-excludeDefaultStyles"></a>
232-
**excludeDefaultStyles** (boolean, optional, default: false)
225+
<a name="option-includeDefaultStyles"></a>
226+
**includeDefaultStyles** (boolean, optional, default: true)
233227

234228
Exclude defualt styles.
235229

gulpfile.babel.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ gulp.task('dev:generate', () => {
9191
rootPath: outputPath,
9292
overviewPath: 'README.md',
9393
styleVariables: 'lib/app/css/_styleguide_variables.css',
94-
excludeDefaultStyles: false,
94+
includeDefaultStyles: true,
9595
parsers: {
9696
css: 'postcss'
9797
}
@@ -100,13 +100,14 @@ gulp.task('dev:generate', () => {
100100
});
101101

102102
gulp.task('dev:applystyles', () => {
103-
if (!fs.existsSync(distPath)) {
103+
if (!fs.existsSync(distPath) || !fs.existsSync(distPath + '/css/styleguide-app.css')) {
104104
process.stderr.write(chalk.red.bold('Error:') + ' Directory ' + distPath + ' does not exist. You probably installed library by cloning repository directly instead of NPM repository.\n');
105105
process.stderr.write('You need to run ' + chalk.green.bold('gulp build') + ' first\n');
106106
process.exit(1);
107107
return 1;
108108
}
109109
return gulp.src(distPath + '/css/styleguide-app.css')
110+
.pipe(replace('{{{appRoot}}}', ''))
110111
.pipe(postcss([
111112
require('postcss-partial-import'),
112113
require('postcss-mixins'),
@@ -120,14 +121,17 @@ gulp.task('dev:applystyles', () => {
120121
require('autoprefixer'),
121122
require('postcss-inline-comment')
122123
]))
124+
.pipe(replace(/url\((.*)\)/g, function(replacement, parsedPath) {
125+
return 'url(\'' + parsedPath.replace(/'/g, '') + '\')';
126+
}))
123127
.pipe(rename('styleguide-app.css'))
124128
.pipe(styleguide.applyStyles())
125129
.pipe(gulp.dest(outputPath));
126130
});
127131

128-
gulp.task('dev', ['dev:doc', 'dev:static', 'dev:applystyles'], () => {
132+
gulp.task('dev', ['dev:doc', 'dev:static'], () => {
129133
//Do intial full build and create styleguide
130-
runSequence('build:dist', 'dev:generate');
134+
runSequence('build:dist', 'dev:generate', 'dev:applystyles');
131135

132136
gulp.watch('lib/app/css/**/*.css', () => {
133137
runSequence('copy:css', 'dev:applystyles', 'dev:generate');

lib/modules/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function sanitizeOptions(opt) {
3232
basicAuth: opt.basicAuth || null,
3333
rootPath: opt.rootPath,
3434
readOnly: opt.readOnly || false,
35-
excludeDefaultStyles: opt.excludeDefaultStyles || false,
35+
includeDefaultStyles: opt.includeDefaultStyles === false ? false : true,
3636
parsers: opt.parsers || {
3737
sass: 'sass',
3838
scss: 'scss',

lib/styleguide.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function generateStyleguideAppStyles(opt) {
147147
var srcFiles;
148148
srcFiles = [distPath + '/css/_fontpath_and_mixin_definition.css'];
149149

150-
if (!opt.excludeDefaultStyles) {
150+
if (opt.includeDefaultStyles) {
151151
srcFiles.push(distPath + '/css/_styleguide_default_styles.css');
152152
}
153153

@@ -182,7 +182,7 @@ function copyUsedOptionsToJsonConfig(opt, json) {
182182
'afterSections',
183183
'showMarkupSection',
184184
'hideSubsectionsOnMainSection',
185-
'excludeDefaultStyles',
185+
'includeDefaultStyles',
186186
'additionalNgDependencies',
187187
];
188188
json.config = {};
@@ -271,7 +271,6 @@ function filterFiles(files, filter) {
271271
}
272272

273273
module.exports.generate = function(options) {
274-
generateStyleguideAppStyles(options);
275274
var opt = common.sanitizeOptions(options),
276275
filesBuffer = {},
277276
throughOpts = {
@@ -375,34 +374,10 @@ module.exports.generate = function(options) {
375374
overviewProcessed,
376375
filesCopied,
377376
favIcon,
378-
indexHtmlProcessed,
379-
srcFiles,
380-
cssCopiedLib,
381-
cssCopiedDist;
382-
383-
srcFiles = [distPath + '/css/_fontpath_and_mixin_definition.css'];
384-
385-
if (!opt.excludeDefaultStyles) {
386-
srcFiles.push(distPath + '/css/_styleguide_default_styles.css');
387-
}
388-
389-
srcFiles.push(distPath + '/css/_custom_styles_mixin.css');
390-
391-
cssCopiedLib = Q.Promise(function(resolve) {
392-
gulp.src(srcFiles)
393-
.pipe(concat('styleguide-app.css'))
394-
.pipe(gulp.dest(libPath + '/css/'))
395-
.on('finish', resolve);
396-
});
397-
398-
cssCopiedDist = Q.Promise(function(resolve) {
399-
gulp.src(srcFiles)
400-
.pipe(concat('styleguide-app.css'))
401-
.pipe(gulp.dest(distPath + '/css/'))
402-
.on('finish', resolve);
403-
});
377+
indexHtmlProcessed;
404378

405379
overviewProcessed = processOverviewMarkdown(opt);
380+
generateStyleguideAppStyles(opt);
406381
var cssSrc = [distPath + '/css/styleguide-app.css', distPath + '/css/styleguide_helper_elements.css'];
407382

408383
// Copy all files (except index.html) from dist from to output stream
@@ -489,7 +464,7 @@ module.exports.generate = function(options) {
489464
.on('finish', resolve);
490465
});
491466

492-
Q.all([cssCopiedLib, cssCopiedDist, stylesCompiled, overviewProcessed, filesCopied, favIcon, indexHtmlProcessed])
467+
Q.all([stylesCompiled, overviewProcessed, filesCopied, favIcon, indexHtmlProcessed])
493468
.then(function() {
494469
if (opt.server) {
495470
opt.fileHashes = fileHashes;

0 commit comments

Comments
 (0)