1 | /*
|
2 | ** GemstoneJS -- Gemstone JavaScript Technology Stack
|
3 | ** Copyright (c) 2016-2018 Gemstone Project <http://gemstonejs.com>
|
4 | ** Licensed under Apache License 2.0 <https://spdx.org/licenses/Apache-2.0>
|
5 | */
|
6 |
|
7 | /* global module: false */
|
8 | /* global require: false */
|
9 | /* eslint no-console: 0 */
|
10 |
|
11 | var path = require("path")
|
12 | var chalk = require("chalk")
|
13 |
|
14 | module.exports = function (grunt) {
|
15 | /* define the Grunt task */
|
16 | grunt.registerMultiTask("gemstone", "Gemstone Tool Commands", function () {
|
17 | /* prepare options */
|
18 | let options = this.options({
|
19 | foo: "bar"
|
20 | })
|
21 | grunt.verbose.writeflags(options, "Options")
|
22 |
|
23 | /* iterate over all src-dest file pairs */
|
24 | this.files.forEach((f) => {
|
25 | try {
|
26 | f.src.forEach((src) => {
|
27 | if (!grunt.file.exists(src))
|
28 | throw new Error("Source file \"" + chalk.red(src) + "\" not found.")
|
29 | else {
|
30 | /* determine destination path */
|
31 | var dest = f.dest
|
32 | if (grunt.file.isDir(dest))
|
33 | dest = path.join(dest, path.basename(src))
|
34 |
|
35 | /* read, expand and post-adjust source */
|
36 | var txt = grunt.file.read(src)
|
37 |
|
38 | /* write destination */
|
39 | grunt.file.write(dest, txt)
|
40 | grunt.log.writeln("File \"" + chalk.green(dest) + "\" created.")
|
41 | }
|
42 | })
|
43 | }
|
44 | catch (e) {
|
45 | grunt.fail.warn(e)
|
46 | }
|
47 | })
|
48 | })
|
49 | }
|
50 |
|