UNPKG

4.23 kBPlain TextView Raw
1/**
2 * @license
3 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14
15// Be mindful of adding imports here, as this is on the hot path of all
16// commands.
17
18import {ArgDescriptor} from 'command-line-args';
19import {Environment} from './environment/environment';
20import {buildEnvironment} from './environments/environments';
21
22export const globalArguments: ArgDescriptor[] = [
23 {
24 name: 'env',
25 description: 'The environment to use to specialize certain commands, ' +
26 'like build',
27 type: (value: string): Environment | undefined => {
28 return buildEnvironment(value);
29 },
30 group: 'global',
31 },
32 {
33 name: 'entrypoint',
34 description: 'The main HTML file that will be requested for all routes.',
35 group: 'global',
36 },
37 {
38 name: 'shell',
39 type: String,
40 description: 'The app shell HTML import',
41 group: 'global',
42 },
43 {
44 name: 'fragment',
45 type: String,
46 multiple: true,
47 description: 'HTML imports that are loaded on-demand.',
48 group: 'global',
49 },
50 {
51 name: 'root',
52 type: String,
53 description: 'The root directory of your project. Defaults to the current' +
54 ' working directory.',
55 group: 'global',
56 },
57 {
58 name: 'sources',
59 type: String,
60 multiple: true,
61 description: 'Glob(s) that match your project source files. ' +
62 'Defaults to `src/**/*`.',
63 group: 'global',
64 },
65 {
66 name: 'extra-dependencies',
67 type: String,
68 multiple: true,
69 description: 'Glob(s) that match any additional dependencies not caught ' +
70 'by the analyzer to include with your build.',
71 group: 'global',
72 },
73 {
74 name: 'npm',
75 type: Boolean,
76 description: 'Sets npm mode: dependencies are installed from npm, ' +
77 'component directory is "node_modules" and the package name is read ' +
78 'from package.json',
79 },
80 {
81 name: 'module-resolution',
82 description: 'Algorithm to use for resolving module specifiers in import ' +
83 'and export statements when rewriting them to be web-compatible. ' +
84 'Valid values are "none" and "node". "none" disables module specifier ' +
85 'rewriting. "node" uses Node.js resolution to find modules.',
86 type: String,
87 // This overrides the default of 'none' in polyserve so that we don't
88 // erroneously override the config file
89 // TODO(justinfagnani): remove the default in polyserve
90 defaultValue: undefined,
91 },
92 {
93 name: 'component-dir',
94 type: String,
95 description: 'The component directory to use. Defaults to reading from ' +
96 'the Bower config (usually bower_components/).',
97 },
98 {
99 name: 'verbose',
100 description: 'turn on debugging output',
101 type: Boolean,
102 alias: 'v',
103 group: 'global',
104 },
105 {
106 name: 'help',
107 description: 'print out helpful usage information',
108 type: Boolean,
109 alias: 'h',
110 group: 'global',
111 },
112 {
113 name: 'quiet',
114 description: 'silence output',
115 type: Boolean,
116 alias: 'q',
117 group: 'global',
118 },
119];
120
121/**
122 * Performs a simple merge of multiple arguments lists. Does not mutate given
123 * arguments lists or arguments.
124 *
125 * This doesn't perform any validation of duplicate arguments, multiple
126 * defaults, etc., because by the time this function is run, the user can't do
127 * anything about it. Validation of command and global arguments should be done
128 * in tests, not on users machines.
129 */
130export function mergeArguments(argumentLists: ArgDescriptor[][]):
131 ArgDescriptor[] {
132 const argsByName = new Map<string, ArgDescriptor>();
133 for (const args of argumentLists) {
134 for (const arg of args) {
135 argsByName.set(
136 arg.name, Object.assign({}, argsByName.get(arg.name), arg));
137 }
138 }
139 return Array.from(argsByName.values());
140}