What is the recommended directory structure for Grunt projects - sass

I am setting up a Grunt project for the first time. Is there a recommended directory structure? For example, keep sources under /src, intermediate build artifacts in /stage and final concatenated, minified artifacts in /dist.
I am also using compass/sass. I assume my scss files should go under /src, but what's the correct way to set up the build workflow so that I am building and testing quickly while not cluttering my source directory with build artifacts.

I just have /src and /build (which is your /dist), and no /stage. I haven't found a real need for stage, probably because I don't have much integration testing to do. Let me know what you're using /stage for -- I'm curious. :)
/myproject
/build
/src
/css
/sass
I do have both a /sass and a /css. /css holds the single main.css compiled w/ SASS. In my Gruntfile.js, I have 2 SASS targets, sass:dev & sass:build. sass:dev compiles into /src/css and sass:build into /build/css. /src/css/main.css is git-/svn-ignored.
At the end of the day, Grunt doesn't care how you organize your sources. It just assumes Gruntfile.js and /node_modules are at project root, and that's it. It's actually NPM that assumes package.json's at root.
So, try different structures and settle on one that you like, which always depends on what tools you use.
Hope this helps! :)

Running grunt init:jquery or grunt init:node should give you a pretty good start on answering this question.
Here is the result of running grunt init:jquery inside a directory called init_test and selecting the default answer for grunt-init's prompts.
Writing CONTRIBUTING.md...OK
Writing grunt.js...OK
Writing libs/jquery/jquery.js...OK
Writing libs/jquery-loader.js...OK
Writing libs/qunit/qunit.css...OK
Writing libs/qunit/qunit.js...OK
Writing README.md...OK
Writing src/init_test.js...OK
Writing test/init_test.html...OK
Writing test/init_test_test.js...OK
Writing LICENSE-MIT...OK
See https://github.com/gruntjs/grunt-init

Related

how to deploy a custom sub-directory within the project with capistrano?

I couldn't find a way to do this yet with capistrano, but lets say I have a project like
project
project/src
project/Capfile
project/config/deploy.rb
project/config/deploy/production.rb
project/build
project/build/main.js
project/build/other_src.js
so the intention is to deploy only what I have within the /build sub directory within the project.
I realize I can just move the capistrano files to the build directory, but the directory is build and dropped every time I compile the project, so I need to kept the capistrano files within the root dir of the project.
Any advice on how to do it in Capistrano?
I've always deployed the entire project and then pointed my webserver at the relevant subfolder. Alternately, you can write a custom task to rework the data in the release path.

Move main out of the repository root in go

I am creating a project in go. Since there is already a lot of things at the root of the repository of the project (doc, README.md...), I want all the source code to go in a folder src, and all the test code in a folder named test :
\go
\src
\github.com
\user
\my_project
\src
main.go
some_func.go
\test
test_main.go
test_some_func.go
\doc
README.md
But I have two issues :
The build command is not working while I am in the my_project folder. I have to go in the my_project/src to successfully run build. I want to do it from the my_project folder. How to inforce go to understand that the source for my_project is in the src code ?
Then the executable produced by the go install command is named src. How to change the name of that executable ?
I want all the source code to go in a folder src, and all the test code in a folder named test :
Go has a way that it organizes source code. Do not fight this. It is how the system works. Organize your code the way Go wants you to. Do not try to force Go to work the way you have learned working in some other language. Every language has its own ways of doing things. None of them are "correct." Like Java, Go has very specific ideas of what you're supposed to do. Do it that way. (This isn't an argument about whether Go is "right" or Go is "wrong." Go is Go, and it does things in the Go way.)
In particular, you should not create another "src" directory. There is already a "src" directory at the top of the "go" tree. If you create another, redundant, "src" directory, then the package name for your project is "github.com/user/my_project/src" which is likely not what you want.
To make the executable be named what you want, put it in a directory named what you want (probably "my_project"). Put test files with the files they test. This is how go works.
So your tree should look like:
\go
\src
\github.com
\user
\my_project
main.go
some_func.go
main_test.go
some_func_test.go
\doc
README.md
Attempts to do something other than this is going to blow up over and over again, and questions of "how do I make the build system do this other thing" will continually return "put your code in the way the build system expects."
For details on what Go expects, and how you should organize your code, see GOPATH environment variable in the Command Go documentation. Once you've built your system this way for a while, you will start to see where you can deviate from it (like creating other directories for test utilities, but not test cases). Don't start deviating until you've tried it the standard Go way.

Prevent Docpad from scanning vendor files (but still copy them)

I've got a project which holds third party files (installed with Bower) under src/public/vendor. It seems ever since I added those docpad has gotten considerably slower in generating ./out, no doubt cause it's going over all the vendor files.
I'd like to exclude the vendor files from being interpreted by DocPad, but they should still be copied to ./out.
Is there a built-in way to do this through DocPad or should I simply put the vendor files outside the src directory and have Grunt copy it manually to ./out?
Your issue is legit and I raised the same a while ago :
https://github.com/bevry/docpad/issues/276
In the end, hypercubed developed the "raw" plugin available through npm :
https://npmjs.org/package/docpad-plugin-raw
Depending on what you provide as options, it can either do a cp or a rsync command.
So it basically what you intend to do with a Grunt task.

Buildr - Exclude source files when compiling

Is there a way to exclude certain packages or source files when compiling in buildr? There isn't an exclude on the compile task as it looks in the src directory. We are building for multiple environments and for one of the environments we need to exclude a few source files otherwise it won't compile.
Any ideas?
thanks
compile.sources only contains the source directories and there is no way to tell buildr to exclude subdirectories directly from that. However, before compilation, buildr lists all the files in these directories to pass them on to the compiler (you can see this with buildr --trace compile). You could monkey-patch Buildr::Compiler::Base::files_from_sources to exclude some stuff, but that seems way too intrusive.
I would turn the problem upside down: instead of putting all the code in a single source directory, put environment-specific stuff in its own directory like so:
src/main/java
src/other-env/java
Most if not all IDEs support multiple source directories, so that should not be a problem.
Then define buildr projects for each of the environments by adding the appropriate source directory to the compilation path using compile.from (same for resources). If src/main/java compiles on its own, you could also separate that into its own project and have the others depend on it, thus avoiding having to recompile it over and over.
To make the build script simpler, think about making the various environments proper sub-projects.

How to make TeamCity only clean up certain files

Is it possible to make TeamCity only clean up certain files upon fetching files from my git repo? I modify one file as a build step, and thus always need a clean version of that file. However, it's really unnecessary to fetch the whole repo everytime because usually only a few files are modified (thus, I'd rather not use the 'Clean all files before build' command).
Thanks!
To clarify, lets say I have the following structure:
- index.html
- js/script.js
- js/plugins.js
I only want to always (regardless if any change has happened) to checkout index.html. The files in the js folder I only want to replace whenever any updates on them have happened.
If you are using TeamCity 6.5 or above you can use the Build Files Cleaner (Swabra) Build Feature. Once you have added it your build steps and run clean build it will clean any new unversioned files generated during the build either before the new build starts or at the end of the current build.
I personally prefer to run it before the new build starts as it allows you to look at any of the output when trying to work out why something went wrong.
Basically it makes sure that there is nothing in the build agents work folder that was not pulled from the repository before each build.

Resources