Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few issues with your code. First:</p> <pre><code>common_libs_js : this.common_libs + "lib/general/static/js/" </code></pre> <p>Unfortunately <code>this.common_libs</code> is undefined (<code>this</code> doesn't point to where you think it does), so common_libs_js ends up being <code>'undefinedlib/general/static/js/'</code>, which doesn't work.</p> <p>The second problem is that on that same line you are concatenating paths, but the first path (from the properties file) doesn't seem to end with a slash, and would become <code>'/home/user/projects/commonlib/general/static/js/'</code> if it wasn't for the previous issue.</p> <p>Third, you'd get a whole bunch of folders inside your dest path. When the expand option is used, Grunt uses the paths as given in the src property to create the folder structure. If you want <code>/home/user/projects/common/lib/general/static/js/foo.js</code> to be copied to <code>lib/foo.js</code>, you should set the <code>cwd</code> option to <code>paths.common_libs_js</code> and the src to <code>'*.js'</code> (or <code>'**/*.js'</code> for a match on any level).</p> <p>People usually embed configuration properties inside Grunt's config, and then use template strings to access them. A very common way to write your task would be something like this (with a few changes, adjust as needed):</p> <pre><code>module.exports = function(grunt) { grunt.initConfig({ properties: grunt.file.readJSON('properties.json'), copy: { main: { expand: true, cwd: '&lt;%= properties.common_libs %&gt;/lib/general/static/js', src: '**/*.js', dest: 'lib' } } }); grunt.loadNpmTasks('grunt-contrib-copy'); }; </code></pre> <p>Alternatively, if you want your files to end up in '<code>lib/general/static/js/</code>' in the destination path too:</p> <pre><code>module.exports = function(grunt) { grunt.initConfig({ properties: grunt.file.readJSON('properties.json'), copy: { main: { expand: true, cwd: '&lt;%= properties.common_libs %&gt;', src: 'lib/general/static/js/**/*.js', dest: '.' // because src includes 'lib' } } }); grunt.loadNpmTasks('grunt-contrib-copy'); }; </code></pre> <p>If you're not sure how Grunt sees your files, run it with <code>grunt -v</code> and it will tell you.</p> <p>You might also want to consider git submodules for a non-Grunt solution.</p> <p>For task-specific constants: you could use the task's (or target's) <code>options</code> hash for that, and access it with template strings:</p> <pre><code>module.exports = function(grunt) { grunt.initConfig({ properties: grunt.file.readJSON('properties.json'), copy: { options: { foo: 'lib' }, main: { options: { bar: '**/*.js' }, expand: true, cwd: '&lt;%= properties.common_libs %&gt;/&lt;%= copy.options.foo %&gt;/general/static/js', src: '&lt;%= copy.options.main.bar %&gt;', dest: 'lib' } } }); grunt.loadNpmTasks('grunt-contrib-copy'); }; </code></pre> <p>This is rarely done for anything other than actual options, though. Conflicts with real options can occur. You could also use the target namespace directly, setting the property directly inside <code>main</code>. But again, there are a few property names that may conflict.</p> <p>If you want to override properties (e.g. for a release build), you can do this:</p> <pre><code>module.exports = function(grunt) { grunt.registerTask('release', function() { grunt.config.set('properties.common_libs', '/usr/lib/shared'); }); grunt.initConfig({ properties: grunt.file.readJSON('properties.json'), copy: { main: { expand: true, cwd: '&lt;%= properties.common_libs %&gt;/lib/general/static/js', src: '**/*.js', dest: 'lib' } } }); grunt.loadNpmTasks('grunt-contrib-copy'); }; </code></pre> <p>Then you'd call your task with <code>grunt release copy</code>.</p> <p><strong>EDIT</strong></p> <p>Based on your updated question, it doesn't seem like the <code>properties.json</code> file is of much use to you. Why not just specify the properties in your Gruntfile?</p> <pre><code>module.exports = function(grunt) { grunt.initConfig({ properties: { base_dir: '../common', base_js_dir: '&lt;%= properties.base_dir %&gt;/lib/general/static/js', base_css_dir: '&lt;%= properties.base_dir %&gt;/lib/general/static/css' }, copy: { main: { expand: true, cwd: '&lt;%= properties.base_js_dir %&gt;', src: '**/*.js', dest: 'lib' } } }); grunt.loadNpmTasks('grunt-contrib-copy'); }; </code></pre> <p>You can also use the file together with this, if you want. Or even put these properties (with the template strings) inside the <code>properties.json</code> file. In the end it's just a matter of making Grunt see an object with template strings. It's up to you to provide that somehow.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload