W
W
werewolf12020-05-12 18:41:19
JavaScript
werewolf1, 2020-05-12 18:41:19

How to resolve Error: EINVAL: invalid argument, mkdir?

// ФАЙЛ JS 
let project_folder = require("path").basename(__dirname);
let source_folder = "#src";

let fs = require('fs');

let path = {
  build: {
    html: project_folder + "/",
    css: project_folder + "/css/",
    js: project_folder + "/js/",
    img: project_folder + "/image/",
    fonts: project_folder + "/fonts/",
  },
  src: {
    html: [source_folder + "/*.html", "!"+source_folder + "/_*.html"],
    css: source_folder + "/scss/style.scss",
    js: source_folder + "/js/script.js",
    img: source_folder + "/image/**/*.{jpg,png,svg,gif,ico,webp}",
    fonts: source_folder + "/fonts/*.ttf",
  },
  watch: {
    html: source_folder + "/**/*.html",
    css: source_folder + "/scss/**/*.scss",
    js: source_folder + "/js/**/*.js",
    img: source_folder + "/image/**/*.{jpg,png,svg,gif,ico,webp}",
  },
  clean: "./" + project_folder + "/",
}


//ПЕРЕМЕННЫЕ ПЛАГИНОВ GULP
let { src, dest } = require('gulp'),
  gulp = require('gulp'),
  browsersync = require("browser-sync").create(),
  fileinclude = require("gulp-file-include"),
  del = require("del"),
  scss = require("gulp-sass"),
  autoprefixer = require("gulp-autoprefixer"),
  group_media = require("gulp-group-css-media-queries"),
  clean_css = require("gulp-clean-css"),
  rename = require("gulp-rename"),
  uglify = require("gulp-uglify-es").default,
  imagemin = require("gulp-imagemin"),
  webp = require("gulp-webp"),
  webphtml = require("gulp-webp-html"),
  webpcss = require("gulp-webpcss"),
  svgSprite = require("gulp-svg-sprite"),
  ttf2woff = require("gulp-ttf2woff"),
  ttf2woff2 = require("gulp-ttf2woff2"),
  fonter = require("gulp-fonter");



function browserSync(params) {
  browsersync.init({
    server: {
      baseDir: "./" + project_folder + "/"
    },
    port: 3000,
    notify: false
  })
}

function html() {
  return src(path.src.html)
    .pipe(fileinclude())
    .pipe(webphtml())//Интегрирует webp в html
    .pipe(dest(path.build.html))
    .pipe(browsersync.stream())
}

function css() {
  //Получаем исходники и обрабатываем SCSS
  return src(path.src.css)
    .pipe(
      scss({
        outputStyle: "expanded"
      })
    )
  //Группируем @media-запросы
    .pipe(
      group_media()
    )
  //Добовляем вендорные префиксы :
  //-o- — префикс для браузера Опера
  //-moz- — префикс для браузеров Mozilla
  //-ms — префикс для Интернет Експлорера 8 
  //-webkit- — префикс для браузеров Safari и Chrome
    .pipe(
      autoprefixer({
        overrideBrowserslist: ["last 5 version"],
        cascade: true
      })
    )
    .pipe(webpcss())//конвертирует webp  в css
  //Выгружаем 1 файл,сжимая переименовываем в .min.css
    .pipe(dest(path.build.css))
    .pipe(clean_css())
    .pipe(
      rename({
        extname: ".min.css"
      })
    )
  //Выгружаем 2 файл не сжимая
    .pipe(dest(path.build.css))
  //Выводим в live и следим за изменениями
    .pipe(browsersync.stream())
}

function js() {
  return src(path.src.js)
    .pipe(fileinclude())
  //Выгружаем 1 файл,сжимая переименовываем в .min.js
    .pipe(dest(path.build.js))
    .pipe(uglify())
    .pipe(
      rename({
        extname: ".min.js"
      })
    )
  //Выгружаем 2 файл не сжимая
    .pipe(dest(path.build.js))
  //Выводим в live и следим за изменениями
    .pipe(browsersync.stream())
}

function images() {
  return src(path.src.img)
  //Сжатие картинок
  //webp - Интегрирует формат .webp только в те браузеры - которые поддерживают этот формат
    .pipe(
      webp({
        quality: 70 //Качество изображения
      })
    )
    .pipe(dest(path.build.img))
    .pipe(src(path.src.img))
  //после обработки webp сразу идет копирование обычных изображений
  //Ниже уже идет обработка обычных изображений
    .pipe(
      imagemin({
        progressive: true,
        interlaced: true,
        optimizationLevel: 3 //0 to 7 //Сила сжатия изображения
      })
    )
    .pipe(dest(path.build.img))
    .pipe(browsersync.stream())
}

function fonts() {
  src(path.src.fonts)
    .pipe(ttf2woff())
    .pipe(dest(path.build.fonts));
  return src(path.src.fonts)
    .pipe(ttf2woff2())
    .pipe(dest(path.src.fonts));
};

//ЗАДАЧА для конвертирования OTF в TTF  (В исходной папке)
gulp.task('otf2ttf', function () {
  return src([source_folder + '/fonts/*.otf'])
    .pipe(fonter({
      formats: ['ttf']
    }))
    .pipe(dest(source_folder + '/fonts/'));
})

function fontsStyle(params) {

  let file_content = fs.readFileSync(source_folder + '/scss/fonts.scss');
  if (file_content = '') {
    fs.writeFile(source_folder + '/scss/fonts.scss', '', cb);
    return fs.readdir(path.build.fonts, function (err, items) {
      if (items) {
        let c_fontname;
        for (var i = 0; i < items.length; i++) {
          let fontname = items[i].split('.');
          fontname = fontname[0];
          if (c_fontname != fontname) {
            fs.appendFile(source_folder + '/scss/fonts.scss', '@include font("' + fontname + '", "' + fontname + '", "400", "normal");\r\n', cb);
          }
          c_fontname = fontname;
        }
      }
    })
  }
}

function cd() {

}

//Отслеживание файлов
function watchFiles(params) {
  gulp.watch([path.watch.html], html);
  gulp.watch([path.watch.css], css);
  gulp.watch([path.watch.js], js);
  gulp.watch([path.watch.img], images);
}

function clean(params){
  return del(path.clean);
}

//Процесс Выполнения 
let build = gulp.series(clean, gulp.parallel(js,css, html, images, fonts), fontsStyle);
let watch = gulp.parallel(build, watchFiles, browserSync);

exports.fontsStyle = fontsStyle;
exports.fonts = fonts;
exports.images = images;
exports.js = js;
exports.css = css;
exports.html = html;
exports.build = build;
exports.watch = watch;
exports.default = watch;


//GULP PACKAGES
{
"name": "lesson6",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": " echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
" del": "^5.1.0",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^7.0.1",
"gulp-clean-css": "^4.3.0",
"gulp-file-include": "^2.2.2",
"gulp-fonter": "^0.3.0",
"gulp-group-css-media-queries": "^1.2.2",
"gulp- imagemin": "^7.1.0",
"gulp-rename": "^2.0.0",
"gulp-sass": "^4.1.0",
"gulp-svg-sprite": "^1.5.0",
"gulp-ttf2woff": "^1.1.1",
"gulp-ttf2woff2": "^3.0 .0",
"gulp-uglify-es": "^2.0.0",
"gulp-webp": "^4.0.1",
"gulp-webp-html": "^1.0.2",
"gulp- webpcss": "^1.1.1",
"rename": "^1.0.4"
}
}

//And console text

PS C:\git full\kurs\Lesson6> gulp
[18:41:07] Using gulpfile C: \git full\kurs\Lesson6\gulpfile.js
[18:41:07] Starting 'default'...
[18:41:07] Starting 'watchFiles'...
[18:41:07] Starting 'browserSync'...
[18:41:07] Starting 'clean'...
[18:41:07] Finished 'clean' after 38 ms
[18:41:07] Starting 'js'.. .
[18:41:07] Starting 'css'...
[18:41:07] Starting 'html'...
[18:41:07] Starting 'images'...
[18:41:07] Starting 'fonts'...
[18:41:10] 'fonts' errored after 2.74 s
[18:41:10] Error: EINVAL: invalid argument, mkdir 'C:\git full\kurs\Lesson6\#src\fonts \*.ttf'
[18:41:10] 'default' errored after 2.78 s
[18:41:10] The following tasks did not complete: watchFiles, browserSync, js, css, html, images
[18:41:10 ] Did you forget to signal async completion?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question