Marc
Marc

Reputation: 596

Workflow for building incremental updates for a JavaScript project with Grunt + Git

Sorry that I'm not able to define a title that brings my question to a point. But I will try to explain my problem here:

We're using Grunt in our JavaScript projects to compile Sass files to CSS and to browserify and minify our JavaScript modules.

The Sass and JavaScript sources are located in multiple folders (one per app-module) with the following folder structure:

src/
    styles/
        base.scss
        style.scss
    js/
        module1.js
        module2.js
        app.js

The Grunt tasks compiles this file into this structure:

dist/
    styles/
        style.css
    js/
        app.js

All files under dist are ignored by Git.

When we deploy our application, we create incremental updates which is basically a git diff --name-only to get a list of files that changed.

Here comes my problem: when I deploy the application, I will have to build all JavaScript and Sass files. As the compiled files are outside of Git, I have no clue which of these files have changed (compared to the latest release) or not.

The only solution that comes into my mind is adding the compiled CSS and JavaScript file to Git, too. But then we will have to struggle with merge conflicts in these files.

Any ideas or experiences how to optimize this workflow?

Update 2017-09-19: I've changed the title to be more accurate as what I was searching for is a workflow to build incremental updates on a JavaScript-project that uses Grunt and Git.

Upvotes: 0

Views: 95

Answers (2)

Marc
Marc

Reputation: 596

Based on the answer by @Dunno, the workflow for creating updates is now as follows:

Incremental updates

  1. Checkout HEAD into temporary directory with the help of git-archive
  2. Build the project with grunt
  3. Checkout the Commit before HEAD (HEAD^) into temporary directory with the help of git-archive
  4. Build the project with grunt
  5. Compare both directories with the help of git-diff --no-index (which allows to compare files in directories without an index)
  6. Store these differences into an archive with the help of tar and gzip, ignore all files in src folders

Full updates

  1. Checkout HEAD into temporary directory with the help of git-archive
  2. Build the project with grunt
  3. Store all project files into an archive with the help of tar and gzip, ignore all files in src folders

The usage of git-diff --no-index was really the life-saver, as neither diff nor rsync were able to report changes in the way I need them.

Upvotes: 0

Dunno
Dunno

Reputation: 3684

You shouldn't keep compiled files in your repository - it doesn't make any sense to do so. It only causes merge conflicts and makes a mess in commit history. You should track all neccessary source and configuration files, so that anyone can build easily from any point in history. If you do that, then your problem comes down to

git checkout newVersion
<build>
git checkout oldVersion
<build>
diff newBuild oldBuild

Upvotes: 2

Related Questions