Repository: fmal/gulp-inline-source Branch: master Commit: 213d9346bec9 Files: 24 Total size: 9.9 KB Directory structure: gitextract_unj3s5mj/ ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test/ ├── expected/ │ ├── inlined-image-png.html │ ├── inlined-image-svg.html │ ├── inlined-link.html │ ├── inlined-nominify.html │ ├── inlined-script.html │ └── inlined-with-attributes.html ├── fixtures/ │ ├── image-png.html │ ├── image-svg.html │ ├── link.html │ ├── nominify.html │ ├── script-es6.html │ ├── script-es6.js │ ├── script-relative.html │ ├── script.html │ ├── script.js │ ├── style.css │ └── with-attributes.html └── main.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ node_modules/ npm-debug.log *.sublime-* ================================================ FILE: .travis.yml ================================================ language: node_js cache: directories: - node_modules - ~/.npm node_js: - "9" - "7.6" after_success: - npm run travis-deploy-once "npm run semantic-release" branches: except: - /^v\d+\.\d+\.\d+$/ ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2014 Filip Malinowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # gulp-inline-source [![NPM Version](https://img.shields.io/npm/v/gulp-inline-source.svg?style=flat-square)](https://www.npmjs.com/package/gulp-inline-source) [![Build Status](https://img.shields.io/travis/fmal/gulp-inline-source/master.svg?style=flat-square)](http://travis-ci.org/fmal/gulp-inline-source) [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/) > Inline all ` ``` ```js // located at src/js/inlineScript.js function test() { var foo = 'lorem ipsum'; return foo; } ``` Output: ```html ``` ## Install ```bash $ npm install gulp-inline-source --save-dev ``` ## Usage ```javascript var gulp = require('gulp'); var inlinesource = require('gulp-inline-source'); gulp.task('inlinesource', function () { return gulp.src('./src/*.html') .pipe(inlinesource()) .pipe(gulp.dest('./out')); }); ``` Optionally, you can provide [some options](https://github.com/popeindustries/inline-source#usage) through an options object: ```javascript var gulp = require('gulp'); var inlinesource = require('gulp-inline-source'); gulp.task('inlinesource', function () { var options = { compress: false }; return gulp.src('./src/*.html') .pipe(inlinesource(options)) .pipe(gulp.dest('./out')); }); ``` ================================================ FILE: index.js ================================================ 'use strict'; const { inlineSource } = require('inline-source'); const PluginError = require('plugin-error'); const path = require('path'); const through = require('through2'); const PLUGIN_NAME = 'gulp-inline-source'; function gulpInlineSource (options) { return through.obj(function (file, enc, cb) { var self = this; if (file.isNull() || file.isDirectory()) { this.push(file); return cb(); } if (file.isStream()) { this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported')); return cb(); } var fileOptions = { rootpath: path.dirname(file.path), htmlpath: file.path }; if (options) { for (var i in options) { fileOptions[i] = options[i]; } } inlineSource(file.contents.toString(), fileOptions) .then(html => { file.contents = Buffer.from(html || ''); self.push(file); cb(); }) .catch(err => { self.emit('error', new PluginError(PLUGIN_NAME, err)); }); }); } module.exports = gulpInlineSource; ================================================ FILE: package.json ================================================ { "name": "gulp-inline-source", "version": "0.0.0-development", "description": "Inline flagged js & css sources.", "license": "MIT", "author": "Filip Malinowski ", "repository": "git://github.com/fmal/gulp-inline-source.git", "keywords": [ "gulpplugin", "inline", "css", "javascript" ], "engines": { "node": ">=7.6" }, "scripts": { "test": "tape test/*.js | faucet", "commit": "git-cz", "commitmsg": "validate-commit-msg", "prepush": "npm test", "semantic-release": "semantic-release", "travis-deploy-once": "travis-deploy-once" }, "dependencies": { "plugin-error": "~1.0.1", "inline-source": "~6.1.8", "through2": "~2.0.0" }, "main": "index.js", "devDependencies": { "commitizen": "^2.9.6", "cz-conventional-changelog": "^2.0.0", "faucet": "0.0.1", "husky": "^0.13.3", "semantic-release": "^15.6.0", "tape": "^4.0.1", "travis-deploy-once": "^5.0.0", "validate-commit-msg": "^2.14.0", "vinyl": "^2.1.0" }, "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" } } } ================================================ FILE: test/expected/inlined-image-png.html ================================================ ================================================ FILE: test/expected/inlined-image-svg.html ================================================ ================================================ FILE: test/expected/inlined-link.html ================================================ ================================================ FILE: test/expected/inlined-nominify.html ================================================ ================================================ FILE: test/expected/inlined-script.html ================================================ ================================================ FILE: test/expected/inlined-with-attributes.html ================================================ ================================================ FILE: test/fixtures/image-png.html ================================================ ================================================ FILE: test/fixtures/image-svg.html ================================================ ================================================ FILE: test/fixtures/link.html ================================================ ================================================ FILE: test/fixtures/nominify.html ================================================ ================================================ FILE: test/fixtures/script-es6.html ================================================ ================================================ FILE: test/fixtures/script-es6.js ================================================ function test() { const foo = `lorem ipsum`; return foo; } ================================================ FILE: test/fixtures/script-relative.html ================================================ ================================================ FILE: test/fixtures/script.html ================================================ ================================================ FILE: test/fixtures/script.js ================================================ function test() { var foo = 'lorem ipsum'; return foo; } ================================================ FILE: test/fixtures/style.css ================================================ .classname { color: red; } ================================================ FILE: test/fixtures/with-attributes.html ================================================ ================================================ FILE: test/main.js ================================================ 'use strict'; const path = require('path'); const Vinyl = require('vinyl'); const fs = require('fs'); const test = require('tape'); const inlinesource = require('../'); function getFile (filePath, contents) { return new Vinyl({ path: filePath, base: path.dirname(filePath), contents: contents || fs.readFileSync(filePath) }); } function getFixture (filePath) { return getFile(path.join(__dirname, 'fixtures', filePath)); } function getExpected (filePath) { return getFile(path.join(__dirname, 'expected', filePath)); } function compare (stream, fixtureName, expectedName, t) { stream.on('data', function (newFile) { t.equal(String(newFile.contents), String(getExpected(expectedName).contents)); }); stream.on('end', function () { t.end(); }); stream.write(getFixture(fixtureName)); stream.end(); } test('inlines