Skip to content

Fix parent base url #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "7"
- "8"
35 changes: 4 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
# gulp-sass-inheritance

[![npm](https://img.shields.io/npm/v/gulp-sass-inheritance.svg)](https://www.npmjs.com/package/gulp-sass-inheritance)
[![npm](https://img.shields.io/npm/dm/gulp-sass-inheritance.svg)](https://www.npmjs.com/package/gulp-sass-inheritance)
![travis](https://api.travis-ci.org/berstend/gulp-sass-inheritance.svg?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/berstend/gulp-sass-inheritance.svg)](https://greenkeeper.io/)
![deps](https://david-dm.org/berstend/gulp-sass-inheritance.svg)


> Rebuild a sass/scss file with other files that have imported this file

* Based on [gulp-jade-inheritance](https://github.com/juanfran/gulp-jade-inheritance)
* Uses [sass-graph](https://github.com/xzyfer/sass-graph) for the heavy lifting
# gulp-sass-parent

Useful when working on a larger project: Styles can be (re-)built incrementally on a per-need basis.


## Changelog


#### v1.1.0 (2017-05-13)

* **The file initially emitted is now being passed through as well**
* **Support for nested imports** - Thanks [@safareli](https://github.com/safareli)! Fixes [#3](https://github.com/berstend/gulp-sass-inheritance/issues/3) [#5](https://github.com/berstend/gulp-sass-inheritance/issues/5)
* Added [tests](./test) & solid coverage
* Updated dependencies


###### Previous: v0.5.1 (2015-04-09)



## Install

```bash
# Using npm
npm install gulp-sass-inheritance --save
npm install gulp-sass-parent --save

# Using yarn
yarn add gulp-sass-inheritance
yarn add gulp-sass-parent
```




## Usage

You can use `gulp-sass-inheritance` with `gulp-changed` to only process the files that have changed but also recompile files that import the one that changed.

```js
'use strict';
var gulp = require('gulp');
var sassInheritance = require('gulp-sass-inheritance');
var sassInheritance = require('gulp-sass-parent');
var sass = require('gulp-sass');
var cached = require('gulp-cached');
var gulpif = require('gulp-if');
Expand Down
51 changes: 29 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ var fs = require('fs');
var gutil = require('gulp-util');
var sassGraph = require('sass-graph');
var PLUGIN_NAME = 'gulp-sass-inheritance';
var pathRequire = require('path');

var stream;

function gulpSassInheritance(options) {
options = options || {};
if (typeof options.dir !== 'string') {

if (typeof options.dir !== 'string' && !Array.isArray(options.dir)) {
throw new Error('gulp-sass-inheritance: Missing dir in options');
}

if (typeof options.dir === 'string') {
options.dir = [options.dir];
}

var files = [];

function writeStream(currentFile) {
Expand All @@ -36,31 +42,32 @@ function gulpSassInheritance(options) {
var stream = this;
if (files.length) {
var allPaths = _.map(files, 'path');
var graph = sassGraph.parseDir(options.dir, options);
var newFiles = files;
_.forEach(files, function(file) {
if (graph.index && graph.index[file.path]) {
var fullpaths = recureOnImports([],graph, file.path);
_.forEach(options.dir, function(dir) {
var graph = sassGraph.parseDir(dir, options);
_.forEach(files, function(file) {
if (graph.index && graph.index[file.path]) {
var fullpaths = recureOnImports([],graph, file.path);

fullpaths.forEach(function (path) {
if (!_.includes(allPaths, path)) {
allPaths.push(path);
newFiles.push(new gutil.File({
cwd: file.cwd,
base: file.base,
path: path,
stat: fs.statSync(path),
contents: fs.readFileSync(path)
}));
}
});
fullpaths.forEach(function (path) {
if (!_.includes(allPaths, path)) {
allPaths.push(path);
newFiles.push(new gutil.File({
cwd: file.cwd,
base: pathRequire.join(file.cwd,dir),
path: path,
stat: fs.statSync(path),
contents: fs.readFileSync(path)
}));
}
});

if (options.debug) {
console.log('File', file.path);
console.log(' - importedBy', fullpaths);
if (options.debug) {
console.log('File', file.path);
console.log(' - importedBy', fullpaths);
}
}
}

});
});
es.readArray(files)
.pipe(es.through(
Expand Down
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
{
"name": "gulp-sass-inheritance",
"version": "1.1.2",
"name": "gulp-sass-parent",
"version": "2.0.0",
"description": "Rebuild only changed sass/scss files and all it's dependencies",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "[email protected]:berstend/gulp-sass-inheritance.git"
"url": "[email protected]:luckyraul/gulp-sass-parent.git"
},
"keywords": [
"gulpplugin",
"sass",
"sass-inheritance",
"sass-graph",
"gulp-sass-graph",
"sass-dependencies",
"gulp-cached"
],
"author": "berstend & Juanfran Alcántara",
"author": "Nikita Tarasov",
"license": "MIT",
"bugs": {
"url": "https://github.com/berstend/gulp-sass-inheritance/issues"
"url": "https://github.com/luckyraul/gulp-sass-parent/issues"
},
"homepage": "https://github.com/berstend/gulp-sass-inheritance",
"homepage": "https://github.com/luckyraul/gulp-sass-parent",
"dependencies": {
"event-stream": "3.3.4",
"event-stream": "4.0.1",
"gulp-util": "^3.0.8",
"lodash": "^4.17.4",
"sass-graph": "^2.2.3",
"through2": "^2.0.3",
"vinyl-fs": "^3.0.0"
"lodash": "^4.17.15",
"sass-graph": "^3.0.4",
"through2": "^3.0.1",
"vinyl-fs": "^3.0.3"
},
"devDependencies": {
"chai": "^4.0.1",
"gulp": "^3.9.1",
"mocha": "^4.0.0",
"chai": "^4.2.0",
"gulp": "^4.0.2",
"mocha": "^6.2.2",
"stream-assert": "^2.0.3"
}
}
Loading