UNPKG

2.77 kBJavaScriptView Raw
1/**
2
3 pipelines-editor.js
4
5**/
6
7
8//
9// Dependencies
10//
11
12var chalk = require("chalk"),
13 utils = require("./cli-utils");
14
15
16
17//
18// Exports
19//
20
21module.exports = {
22
23 /**
24
25 Writes a list of available pipelines to server.
26
27 **/
28
29 list: function() {
30
31 var editor = require("./config-editor"),
32 pipelines = editor.get("pipelines"),
33 columns = [];
34
35 // Add in defaults for HTML, CSS and JS
36 ["html", "css", "js"].forEach(function(key) {
37 if (!pipelines[key]) pipelines[key] = key;
38 });
39
40 // Add to columns
41 for (var key in pipelines)
42 columns.push(["*." + key, pipelines[key]]);
43
44 utils.showGrid(columns, {
45 title : "Pipelines:",
46 len : 20,
47 headers : ["Extension", "Pipeline"]
48 });
49
50 },
51
52
53
54 /**
55
56 Adds a pipeline to the config file and acknowledges with confirmation.
57
58 @param {String} ext The extension to associate with the pipeline
59 @param {String} pipeline The pipeline (e.g. "jade>handlebars")
60
61 **/
62
63 add: function(ext, pipeline) {
64
65 ext = ext.replace(/^[\*\.]*/, "");
66
67 var editor = require("./config-editor"),
68 key = "pipelines." + ext,
69 prev = editor.get(key);
70
71 function suffix(val) {
72 return chalk.yellow("*." + ext) + " files with " + chalk.yellow(val);
73 }
74
75 console.log("");
76
77 if (prev === pipeline) {
78 console.log(" " + chalk.red("No Change:") + " shipp was already processing " + suffix(pipeline));
79 } else {
80 editor.set(key, pipeline);
81 editor.save();
82 if (prev && prev !== pipeline) console.log(" " + chalk.cyan("Removed:") + " shipp will no longer process " + suffix(prev));
83 console.log(" " + chalk.cyan("Added:") + " shipp will process " + suffix(editor.get(key)));
84 }
85
86 console.log("");
87
88 },
89
90
91 /**
92
93 Removes a pipeline from the config file and acknowledges with confirmation.
94
95 @param {String} ext The extension of the pipeline to remove
96
97 **/
98
99 remove: function(ext) {
100
101 ext = ext.replace(/^[\*\.]*/, "");
102
103 var editor = require("./config-editor"),
104 key = "pipelines." + ext,
105 prev = editor.get(key);
106
107 console.log("");
108
109 if (!prev) {
110 if (["html", "css", "js"].indexOf(ext) > -1)
111 console.log(" " + chalk.red("Error:") + " you can't remove the pipeline for " + chalk.yellow("*." + ext) + " files (it's static!)");
112 else
113 console.log(" " + chalk.red("No Change:") + " there was no pipeline associated with " + chalk.yellow("*." + ext) + " files ");
114 } else {
115 editor.unset("pipelines." + ext);
116 editor.save();
117 console.log(" " + chalk.cyan("Removed:") + " shipp will no longer process " + chalk.yellow("*." + ext) + " files with " + chalk.yellow(prev));
118 }
119
120 console.log("");
121
122 }
123
124};