UNPKG

3.65 kBPlain TextView Raw
1#!/usr/bin/env node
2
3/**
4 * Command line interface of tmplconv.
5 * This file is auto generated by ape-tmpl.
6 */
7
8"use strict";
9
10const program = require('commander'),
11 pkg = require('../package'),
12 tmplconv = require('../lib');
13
14program
15 .version(pkg['version'])
16 .description(pkg['description'])
17;
18
19//=========================
20// Handle `tmplify` command
21//=========================
22
23program
24 .command("tmplify <srcDir> <destDir>") .description("Generate a template from existing files")
25 .option('-d, --data <data>', "Name or path of data module.")
26 .option('-p, --pattern <pattern>', "File name patterns")
27 .option('-i, --ignore <ignore>', "File name patterns to ignore")
28 .option('-P, --prefix <prefix>', "Embed prefix")
29 .option('-S, --suffix <suffix>', "Embed suffix")
30 .option('-e, --extname <extname>', "Embed Template extension name")
31 .option('-s, --silent', "Disable console logs")
32 .option('-c, --clean', "Cleanup destination directory before convert")
33 .option('-n, --once', "Write only first time. Skip if already exists")
34 .option('-m, --mode', "File permission to generate")
35 .action((srcDir, destDir, options) => {
36 tmplconv.tmplify(srcDir, destDir, options ,done);
37 });
38
39
40//=========================
41// Handle `render` command
42//=========================
43
44program
45 .command("render <srcDir> <destDir>") .description("")
46 .option('-d, --data <data>', "Name or path of data module.")
47 .option('-p, --pattern <pattern>', "File name patterns")
48 .option('-i, --ignore <ignore>', "File name patterns to ignore")
49 .option('-P, --prefix <prefix>', "Embed prefix")
50 .option('-S, --suffix <suffix>', "Embed suffix")
51 .option('-e, --extname <extname>', "Embed Template extension name")
52 .option('-s, --silent', "Disable console logs")
53 .option('-c, --clean', "Cleanup destination directory before convert")
54 .option('-n, --once', "Write only first time. Skip if already exists")
55 .option('-m, --mode', "File permission to generate")
56 .action((srcDir, destDir, options) => {
57 tmplconv.render(srcDir, destDir, options ,done);
58 });
59
60
61//=========================
62// Handle `transplant` command
63//=========================
64
65program
66 .command("transplant <src> <dest>") .description("Tmplify and render at once")
67 .option('-, --rule', "Rule for convert")
68 .option('-p, --pattern <pattern>', "File name patterns")
69 .option('-i, --ignore <ignore>', "File name patterns to ignore")
70 .option('-s, --silent', "Disable console logs")
71 .option('-c, --clean', "Cleanup destination directory before convert")
72 .option('-n, --once', "Write only first time. Skip if already exists")
73 .option('-m, --mode', "File permission to generate")
74 .action((src, dest, options) => {
75 tmplconv.transplant(src, dest, options ,done);
76 });
77
78
79program.parse(process.argv);
80
81//=========================
82// Check sub command
83//=========================
84
85{
86 let command = process.argv[2];
87 if (!command) {
88 program.outputHelp();
89 return;
90 }
91
92 let _isValid = name => {
93 for (let command of program.commands) {
94 let hit = (command.name() == name) || (command.alias() == name);
95 if(hit){
96 return true;
97 }
98 }
99 return false;
100 };
101 if (!_isValid(command)) {
102 console.log("[tmplconv] '%s' is not an tmplconv command. See 'tmplconv --help'.", command);
103 }
104
105};
106
107
108
109/** When command done. */
110function done(err) {
111 if (err) {
112 console.error(err);
113 process.exit(1);
114 } else {
115 process.exit(0);
116 }
117}