F
F
faramozzayw2018-08-20 16:41:40
css
faramozzayw, 2018-08-20 16:41:40

How to force npm to run in a row in a .bat file?

In general, the essence is this. I read this tutorial here and decided that I fell into the future (for now I'm just practicing all this (layout, etc.), if anything) to go into the console every time and prescribe all the commands. Therefore, I decided to make a small batch file that would run everything I needed in order without my intervention. The problem is that if you run the installation via npm directly with a batch file:

echo Install Gulp autoprefixer
  npm install --save-dev gulp-autoprefixer
    pause

Then after installation, the batch file immediately completes its work, although it is not fully completed (ie, after installing one plugin, the batch file closes). I "solved" this problem through a separate batch file for each installation and running it through start:
echo Install Gulp autoprefixer
  start start_file\plugin\gulp-autoprefixer.bat
    pause

But there are quite logical disadvantages: a lot of batch files + batch files launched through start do not close after execution (sic!) And they have to be closed manually, which I am also too lazy to do. I want all npm i to be launched from one batch file and from the installation went in a row (for the sake of convenience). Is it realistic to do this?
My batch files (do not beat for English, I used a translator to speed things up).
Actually the main batch file
@echo off
title Creating an assembly template
color 0F
echo Creating a Project Structure
pause
mkdir build
mkdir src
  dir > index.html
mkdir src\js
  mkdir src\js\partials
    cd src\js
      dir > main.js
    cd .. 
      rem возращаемся в src
    cd .. 
      rem возращаемся в папку проекта
mkdir src\img
mkdir src\fonts
mkdir src\style
  mkdir src\style\partials
    cd src\style
      dir > main.css
    cd .. 
      rem возращаемся в src
    cd .. 
      rem возращаемся в папку проекта
mkdir src\template
echo This part of the batch file creates bower.json
  pause
    start start_file\json\bower.bat
echo This part of the batch file creates package.json
  pause
    start start_file\json\package.bat
echo Install the gulp with the --save-dev flag
  pause 
    start start_file\plugi\gulp.bat
echo This part of the batch file installs the gulp plugins with the --save-dev flag
  pause
    echo Install Gulp autoprefixer
      start start_file\plugin\gulp-autoprefixer.bat
        pause
    echo Install Gulp clean css
      start start_file\plugin\gulp-clean-css.bat
        pause
    echo Install Gulp imagemin
      start start_file\plugin\gulp-imagemin.bat
        pause
    echo Install Gulp uglify
      start start_file\plugin\gulp-uglify.bat
        pause
    echo Install Gulp sass
      start start_file\plugin\gulp-sass.bat
        pause
    echo Install Gulp sourcemaps
      start start_file\plugin\gulp-sourcemaps.bat
        pause
    echo Install Gulp rigger
      start start_file\plugin\gulp-rigger.bat
        pause
    echo Install Gulp watch
      start plugin\gulp-watch.bat
        pause
    echo Install Rimraf
      start start_file\plugin\rimraf.bat
    pause
exit

An example of a batch file launched by the main batch file
@echo off
npm install --save-dev gulp-autoprefixer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Egorov, 2018-08-20
@faramozzayw

But no matter how they do it wrong ...
Once they set up all the directories and that's it. Then only three commands ->

git clone url/to/project
npm i
npm run serve

Almost all projects do this, including major frameworks and popular templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question