1

So here's the situation. I currently have project with the following folder structure:

-- public_html
   -- assets
      -- scss (contains SCSS files, which can be located inside subfolders)
      -- scripts
         -- vendor 
            -- plugins (Also contain some SCSS files from the)
      -- css
      -- also some other folders (no scss or css here though)
   -- dist (distribution folder)
   -- other folders too for html, php etc...

When I want to upload the script to my remote server, I firstly process the complete folder structure in public_html to the dist. I do this with a build script, build.sh, which you can see here:

function prepareForBuild(){
    echo "Updating dependencies...";
    bower install

    echo "Preparing 'dist' directory...";
    mkdir -p dist
    rm -rf dist/*
    # for the stackoverflow markup... */
}

function buildApp(){
    cd assets
    echo "Creating temp directory..."
    mkDir -p temp

    ## MERGING TAKES (OR SHOULD) PLACE HERE
    find "/" -name '*.scss' -exec cat {} \; > merge.scss


    cd ../
    pause
    # requirejs optimization
    echo "Optimizing files...";
    node r.js -o build/build.js
}

function cleanup(){
    echo "Cleaning up unnecessary files...";
    cd dist

    rm -f bower.json .gitignore .bowerrc README.md .DS_Store config.rb
    rm -f build.sh build.txt composer.json composer.lock
    rm -rf build dist scss .git .sass-cache .idea
}

function pause(){
   read -p "$*"
}

prepareForBuild
buildApp && cleanup 

echo "Building finished!";

Problem:

However, when I run the script in the Git bash terminal it breaks at this line:

find "/" -name '*.scss' -exec cat {} \; > merge.scss

Edit: "/" or "\" does not seem to affect the problem :(
Also, run from root (public_html) directory: test run

where it returns in the normal command prompt "File not found - *.scss" (and outputs an empty merge.scss file) and simply stops working in the Git bash terminal. I based this line on this answer, but I can't get it to work for me. I also tried something like this instead but this only returns more errors. What am I missing here?

EDIT!

I thought the bash shell simply stopped working but it seems that was not the case. After a while it returns this: Git Bash error What does this mean? Is the reference folder incorrect?

Objective:

As said I would like to recursively scan the assets folder for .scss files and merge them into one default.scss.

If this is too much to ask another solution integrated with require.js (or simply with node) would also be possible, as you can see in my script I already use require.js for standard optimization.

Thanks for your time and patience!

Evochrome
  • 1,205
  • 1
  • 7
  • 20
  • install gentoo. – oguz ismail Oct 21 '18 at 18:06
  • That is, unfortunately, not an option ;) – Evochrome Oct 21 '18 at 19:30
  • Why are you specifying a REVERSE SOLIDUS (backslash) as the directory in `find '\' -name...`? Shouldn't that be a SOLIDUS (slash, virgule)? `find / -name...` – lit Oct 21 '18 at 19:36
  • @lit, thanks for the repy! Unfortunately, that was a typo and does not seem to work :( I'm quite clueless what the problem is with this line atm to be honest – Evochrome Oct 21 '18 at 22:07
  • The images you posted makes it appear that you are at a cmd.exe shell prompt and not a bash shell prompt. The Windows `find.exe` reports this error message. You need to start a bash shell. – lit Oct 22 '18 at 02:08
  • @lit, correct but this was just a test, the shell script is actually run in a bash shell(which just stops working when run). – Evochrome Oct 22 '18 at 12:22

2 Answers2

2

If you want to scan for files under the assets directory, then do not specify the root directory in the find command. Omitting directories might also be a good idea.

find . -name "*.scss" -not -type d -exec cat {} \; > merge.scss

In the chance the you are wanting the merge.scss file to be created in the newly created temp directory, you need to make it the current directory. Then you can do the file scan from the parent, assets, directory.

function buildApp(){
    cd assets
    echo "Creating temp directory..."
    mkDir -p temp

    ## MERGING TAKES (OR SHOULD) PLACE HERE
    cd temp
    find .. -name '*.scss' -not -type d -exec cat {} \; > merge.scss

    cd ../
    pause
    # requirejs optimization
    echo "Optimizing files...";
    node r.js -o build/build.js
}

Also, does a pause command work for you in the bash shell? That is a Windows command unless you have something else.

lit
  • 14,456
  • 10
  • 65
  • 119
  • Hey thanks for the answer! The `..` fixes the errors it gave before. However, I now get the error that `merge.scss` is both the input and output file... which is odd because I am a 100% sure there are other files which need to be added. Also, the pause works (I believe this is not the default function in windows but my own custom function at the end of the script). **Edit:** it works!!! I added a line to delete the merge file before merging and now it all merges perfectly! Thanks for the help! – Evochrome Oct 22 '18 at 15:04
  • 1
    You should create the `merge.scss` file somewhere outside of the directory structure being scanned or use a different filename extension. This is happening because it finds `merge.scss` and tries to write it to `merge.scss`. Perhaps `>merge.scss.txt`, Then `mv merge.scss.txt merge.scss` if that is the name you want. I see you `pause` function at the bottom. – lit Oct 22 '18 at 15:10
1

Your -exec option misses the {} special element, meaning the file matching each find iteration. In addition, you can't definitively use '\' as a root path, at least it would be '/'.

Nevertheless, ideally you should use a specific sub-path for better efficiencies, and for permissions access reasons (I guess your use may not have permission to access all sub path from the root path?).

At least, you can update your instruction to:

find '/' -type f -name "*.scss" -exec cat {} \; > merge.scss
Bsquare ℬℬ
  • 4,423
  • 11
  • 24
  • 44
  • Hey Bsquare, thanks for your answer! `\ ` would probably link to the recycle bin or something I would guess. Indeed you are right about the `{}` part, thanks for pointing that out! However, the script still stops working at this line, what could this be? – Evochrome Oct 22 '18 at 12:25
  • I've updated my question, it seems the shell didn't crash after all. Hope this helps to understand the problem – Evochrome Oct 22 '18 at 12:38
  • Ha yes! You have to ensure only files are regarded by the find instruction. I've edited my answer, adding the "**-type f**" option. Your error occurs because there is a directoy named ".scss" (and with the previous command, it was trying to cat the directory, which is senseless). – Bsquare ℬℬ Oct 22 '18 at 12:43
  • Allright I will try that one out and come back to you when I have the results(it has been running for a while now, don't know if thats fine but I'll wait a bit longer). Also, regarding the specific subpath you mention in your answer. This command is run in the assets directory (see script in question). Anyway, I'll let you know soon! – Evochrome Oct 22 '18 at 12:56
  • Still nothing, it seems the script simply stops. Any ideas? Edit: Bash gives no output but cmd gives `file not found '/'`, `file not found -type` etc. for each term in the line – Evochrome Oct 22 '18 at 13:27
  • The current directory may be the assets directory, but the `find` command has been told to search from the `root` "/" directory. – lit Oct 22 '18 at 13:31
  • @Evochrome What gives: **find -version** ? – Bsquare ℬℬ Oct 22 '18 at 13:36
  • 4.6.0 in the bash shell – Evochrome Oct 22 '18 at 14:59
  • Hey Bsquare, Thanks for all the help! It now works fine, your answer combined with lit's! You guys are my heroes for today :) – Evochrome Oct 22 '18 at 15:10