@m2c2kit/cli 0.1.1 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @m2c2kit/cli
2
+
3
+ This package contains a command line tool for developing m2c2kit apps.
4
+
5
+ License: MIT
package/dist/.env ADDED
@@ -0,0 +1 @@
1
+ CLI_VERSION=0.1.6
package/dist/cli.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- // https://github.com/yargs/yargs/issues/1854#issuecomment-792354121
3
2
  import yargs from "yargs";
4
3
  import { hideBin } from "yargs/helpers";
5
4
  import fs from "fs";
@@ -10,9 +9,53 @@ import { fileURLToPath } from "url";
10
9
  import { spawn } from "child_process";
11
10
  import ora from "ora";
12
11
  import chalk from "chalk";
12
+ import prompts from "prompts";
13
+ import Conf from "conf";
14
+ import { resolve } from "path";
15
+ import { readdir } from "fs/promises";
16
+ import FormData from "form-data";
17
+ import axios from "axios";
18
+ // this is the path of our @m2c2kit/cli program
19
+ // our templates are stored under here
13
20
  const packageHomeFolderPath = dirname(fileURLToPath(import.meta.url));
21
+ // we store the CLI version in .env. The .env file is created during the
22
+ // build process with the write-dotenv.js script
23
+ // I couldn't get dotenv working with a node cli, so just read it in with
24
+ // readFileSync()
25
+ let cliVersion;
26
+ try {
27
+ cliVersion = fs
28
+ .readFileSync(path.join(packageHomeFolderPath, ".env"))
29
+ .toString()
30
+ .split("=")[1];
31
+ }
32
+ catch {
33
+ cliVersion = "UNKNOWN";
34
+ }
35
+ function copyFile(copyFileInfo) {
36
+ const sourceContents = fs.readFileSync(copyFileInfo.sourceFilePath);
37
+ fs.writeFileSync(copyFileInfo.destinationFilePath, sourceContents);
38
+ return sourceContents.length;
39
+ }
40
+ function applyValuesToTemplate(templateFilePath, contents) {
41
+ const templateContents = fs.readFileSync(templateFilePath).toString();
42
+ const template = handlebars.compile(templateContents);
43
+ return template(contents);
44
+ }
45
+ // on the demo server, identify studies with a random 5 digit code
46
+ const generateStudyCode = () => {
47
+ let result = "";
48
+ // omit I, 1, O, and 0 due to potential confusion
49
+ const characters = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
50
+ const charactersLength = characters.length;
51
+ for (let i = 0; i < 5; i++) {
52
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
53
+ }
54
+ return result;
55
+ };
14
56
  const yarg = yargs(hideBin(process.argv));
15
- yarg
57
+ await yarg
58
+ .scriptName("m2")
16
59
  .command("new <name>", "create a new m2c2kit app", (yarg) => {
17
60
  yarg.positional("name", {
18
61
  describe: "name of new app",
@@ -20,19 +63,22 @@ yarg
20
63
  });
21
64
  }, (argv) => {
22
65
  const appName = argv["name"];
66
+ if (!isValidAppName(appName)) {
67
+ console.error(`${chalk.red("ERROR")}: the name ${appName} is not valid. The name must be a valid JavaScript identifer (e.g., begin with a letter, $ or _; not contain spaces; not be a reserved word, etc.).`);
68
+ yarg.exit(1, new Error("invalid name"));
69
+ }
70
+ const className = appName.charAt(0).toUpperCase() + appName.slice(1);
23
71
  const newFolderPath = path.join(path.resolve(), appName);
24
72
  if (fs.existsSync(newFolderPath)) {
25
- console.log(`${chalk.red("ERROR")}: folder ${newFolderPath} already exists. Please remove this folder and try again.`);
73
+ console.error(`${chalk.red("ERROR")}: folder ${newFolderPath} already exists. Please remove this folder and try again.`);
26
74
  yarg.exit(1, new Error("folder exists"));
27
75
  }
28
76
  fs.mkdirSync(newFolderPath);
29
77
  fs.mkdirSync(path.join(newFolderPath, "src"));
30
78
  fs.mkdirSync(path.join(newFolderPath, ".vscode"));
31
- function applyValuesToTemplate(templateFilePath, contents) {
32
- const templateContents = fs.readFileSync(templateFilePath).toString();
33
- const template = handlebars.compile(templateContents);
34
- return template(contents);
35
- }
79
+ fs.mkdirSync(path.join(newFolderPath, "fonts", "roboto"), {
80
+ recursive: true,
81
+ });
36
82
  const templateFolderPath = path.join(packageHomeFolderPath, "templates");
37
83
  const templates = [
38
84
  {
@@ -63,25 +109,59 @@ yarg
63
109
  templateFilePath: path.join(templateFolderPath, "launch.json.handlebars"),
64
110
  destinationFilePath: path.join(newFolderPath, ".vscode", "launch.json"),
65
111
  },
112
+ {
113
+ templateFilePath: path.join(templateFolderPath, "m2c2kit.json.handlebars"),
114
+ destinationFilePath: path.join(newFolderPath, "m2c2kit.json"),
115
+ },
66
116
  ];
67
117
  let errorProcessingTemplates = false;
68
118
  templates.forEach((t) => {
69
119
  try {
70
120
  const contents = applyValuesToTemplate(t.templateFilePath, {
71
121
  appName: appName,
122
+ className: className,
123
+ cliVersion: cliVersion,
124
+ studyCode: generateStudyCode(),
72
125
  });
73
126
  fs.writeFileSync(t.destinationFilePath, contents);
74
127
  console.log(`${chalk.green("CREATE")} ${t.destinationFilePath} (${contents.length} bytes)`);
75
128
  }
76
129
  catch (error) {
77
130
  errorProcessingTemplates = true;
78
- console.log(`${chalk.red("ERROR")} ${t.destinationFilePath}`);
131
+ console.error(`${chalk.red("ERROR")} ${t.destinationFilePath}`);
79
132
  }
80
133
  });
81
134
  if (errorProcessingTemplates) {
82
- console.log(`${chalk.red("ERROR")}: could not generate files`);
135
+ console.error(`${chalk.red("ERROR")}: could not generate files`);
83
136
  yarg.exit(1, new Error("template error"));
84
137
  }
138
+ // roboto is the default font we ship
139
+ // it's Apache 2,, so OK to use as long as we include license
140
+ const copyFiles = [
141
+ {
142
+ sourceFilePath: path.join(packageHomeFolderPath, "fonts", "roboto", "LICENSE.txt"),
143
+ destinationFilePath: path.join(newFolderPath, "fonts", "roboto", "LICENSE.txt"),
144
+ },
145
+ {
146
+ sourceFilePath: path.join(packageHomeFolderPath, "fonts", "roboto", "Roboto-Regular.ttf"),
147
+ destinationFilePath: path.join(newFolderPath, "fonts", "roboto", "Roboto-Regular.ttf"),
148
+ },
149
+ ];
150
+ let errorCopyingFiles = false;
151
+ copyFiles.forEach((c) => {
152
+ try {
153
+ const bytesCopied = copyFile(c);
154
+ console.log(`${chalk.green("COPY")} ${c.destinationFilePath} (${bytesCopied} bytes)`);
155
+ }
156
+ catch (error) {
157
+ errorCopyingFiles = true;
158
+ console.error(`${chalk.red("ERROR")} ${c.destinationFilePath}`);
159
+ }
160
+ });
161
+ if (errorCopyingFiles) {
162
+ console.error(`${chalk.red("ERROR")}: could not copy files`);
163
+ yarg.exit(1, new Error("copy files error"));
164
+ }
85
165
  const spinner = ora("Installing packages (npm)...").start();
86
166
  let npm;
87
167
  if (process.platform === "win32") {
@@ -97,17 +177,323 @@ yarg
97
177
  npm.stderr.on("data", (data) => {
98
178
  npmOut = npmOut + data.toString();
99
179
  });
180
+ // node will wait for the npm process to exit. Thus,
181
+ // this on exit listener is the last code we execute before
182
+ // the "m2 new" command is done
100
183
  npm.on("exit", (code) => {
101
184
  if (code === 0) {
102
185
  spinner.succeed("Packages installed successfully");
186
+ console.log(`Created ${appName} at ${newFolderPath}`);
187
+ console.log("Inside that directory, you can run several commands:\n");
188
+ console.log(` ${chalk.green("npm run serve")}`);
189
+ console.log(" Starts the development server.\n");
190
+ console.log(` ${chalk.green("npm run build")}`);
191
+ console.log(" Bundles the app for production.\n");
192
+ console.log(` ${chalk.green("m2 upload")}`);
193
+ console.log(" Uploads the app to a test server.\n");
194
+ console.log("We suggest you begin by typing:\n");
195
+ console.log(` ${chalk.green("cd")} ${appName}`);
196
+ console.log(` ${chalk.green("npm run serve")}`);
103
197
  }
104
198
  else {
105
199
  spinner.fail("Error during package installation");
106
200
  console.log(npmOut);
201
+ yarg.exit(1, new Error("npm install error"));
107
202
  }
108
203
  });
109
204
  })
205
+ // TODO: move npm script execution into this cli, so there's a single tool
110
206
  //.command("build", "compiles to output directory named dist/")
111
207
  //.command("serve", "builds and serves app, rebuilding on files changes")
208
+ .command("upload", "upload production build from dist/ to server", (yargs) => {
209
+ yargs
210
+ .option("url", {
211
+ alias: "u",
212
+ type: "string",
213
+ description: "server url",
214
+ })
215
+ .option("studyCode", {
216
+ alias: "s",
217
+ type: "string",
218
+ description: "study code. This 5-digit random alphanumeric code is automatically generated by the cli during the creation of a new app and stored in m2c2kit.json",
219
+ })
220
+ .option("remove", {
221
+ alias: "r",
222
+ type: "boolean",
223
+ description: "remove saved server credentials from local machine",
224
+ });
225
+ }, async (argv) => {
226
+ const m2c2kitProjectConfig = new Conf({
227
+ // store this config in the project folder, not user's ~/.config
228
+ cwd: ".",
229
+ configName: "m2c2kit",
230
+ });
231
+ // store server credentials in user folder, not project folder
232
+ // to avoid secrets getting into source control
233
+ const m2c2kitUserConfig = new Conf({
234
+ configName: "m2c2kit-cli-user",
235
+ projectName: "m2c2kit-cli",
236
+ projectSuffix: "",
237
+ accessPropertiesByDotNotation: false,
238
+ });
239
+ if (argv["remove"]) {
240
+ m2c2kitUserConfig.clear();
241
+ console.log(`all server credentials removed from ${m2c2kitUserConfig.path}`);
242
+ return;
243
+ }
244
+ let abort = false;
245
+ let serverConfig;
246
+ try {
247
+ serverConfig = m2c2kitProjectConfig.get("server");
248
+ }
249
+ catch {
250
+ serverConfig = {};
251
+ }
252
+ // get url first from command line, then from config file, then assign blank
253
+ let url = argv["url"] ?? serverConfig?.url ?? "";
254
+ if (url === "") {
255
+ const response = await prompts({
256
+ type: "text",
257
+ name: "url",
258
+ message: "server url?",
259
+ validate: (text) => text.length > 0
260
+ ? true
261
+ : "provide a valid server url (e.g., https://www.myserver.com)",
262
+ onState: (state) => (abort = state.aborted === true),
263
+ });
264
+ url = response.url;
265
+ }
266
+ if (abort) {
267
+ yarg.exit(1, new Error("user aborted"));
268
+ }
269
+ // get study code first from command line, then from config file, then assign blank
270
+ let studyCode = argv["studyCode"] ??
271
+ serverConfig?.studyCode ??
272
+ "";
273
+ if (studyCode === "") {
274
+ const response = await prompts({
275
+ type: "text",
276
+ name: "studyCode",
277
+ message: "study code?",
278
+ validate: (text) => text.length > 0
279
+ ? true
280
+ : "provide a study code (5 random alphanumeric digits, e.g., R5T7A)",
281
+ onState: (state) => (abort = state.aborted === true),
282
+ });
283
+ studyCode = response.studyCode;
284
+ }
285
+ if (abort) {
286
+ yarg.exit(1, new Error("user aborted"));
287
+ }
288
+ // if new url or study code was provided, save these
289
+ if (url !== serverConfig?.url || studyCode !== serverConfig?.studyCode) {
290
+ m2c2kitProjectConfig.set("server", { url, studyCode });
291
+ }
292
+ const serverCredentials = m2c2kitUserConfig.get(url);
293
+ let username = serverCredentials?.username ?? "";
294
+ let writeCredentials = false;
295
+ if (username === "") {
296
+ const response = await prompts({
297
+ type: "text",
298
+ name: "username",
299
+ message: `username for server at ${url}`,
300
+ validate: (text) => text.length > 0
301
+ ? true
302
+ : "username cannot be empty",
303
+ onState: (state) => (abort = state.aborted === true),
304
+ });
305
+ username = response.username;
306
+ writeCredentials = true;
307
+ }
308
+ if (abort) {
309
+ yarg.exit(1, new Error("user aborted"));
310
+ }
311
+ let password = serverCredentials?.password ?? "";
312
+ if (password === "") {
313
+ const response = await prompts({
314
+ type: "password",
315
+ name: "password",
316
+ message: `password for server at ${url}`,
317
+ validate: (text) => text.length > 0
318
+ ? true
319
+ : "password cannot be empty",
320
+ onState: (state) => (abort = state.aborted === true),
321
+ });
322
+ password = response.password;
323
+ writeCredentials = true;
324
+ }
325
+ if (abort) {
326
+ yarg.exit(1, new Error("user aborted"));
327
+ }
328
+ if (writeCredentials) {
329
+ m2c2kitUserConfig.set(url, {
330
+ username,
331
+ password,
332
+ });
333
+ console.log(`credentials (username, password) for server ${url} written to ${m2c2kitUserConfig.path}`);
334
+ }
335
+ const getFilenamesRecursive = async (dir) => {
336
+ const dirents = await readdir(dir, { withFileTypes: true });
337
+ const files = await Promise.all(dirents.map((dirent) => {
338
+ const res = resolve(dir, dirent.name);
339
+ return dirent.isDirectory() ? getFilenamesRecursive(res) : res;
340
+ }));
341
+ return Array.prototype.concat(...files);
342
+ };
343
+ const uploadFile = async (serverUrl, userPw, studyCode, fileContent, filename) => {
344
+ const basename = path.basename(filename);
345
+ let folderName = filename.replace(basename, "");
346
+ folderName = folderName.replace(/\/$/, ""); // no trailing slash
347
+ const form = new FormData();
348
+ form.append("folder", folderName);
349
+ form.append("file", fileContent, filename);
350
+ const userPwBase64 = Buffer.from(userPw, "utf-8").toString("base64");
351
+ const uploadUrl = `${serverUrl}/api/studies/${studyCode}/files`;
352
+ return axios.post(uploadUrl, form, {
353
+ headers: {
354
+ ...form.getHeaders(),
355
+ // this uses basic auth because it's simply a demo server
356
+ // but for production, a more robust auth must be used
357
+ Authorization: `Basic ${userPwBase64}`,
358
+ },
359
+ });
360
+ };
361
+ const distFolder = path.join(process.cwd(), "dist");
362
+ if (!fs.existsSync(distFolder)) {
363
+ console.error(`${chalk.red("ERROR")}: distribution folder not found. looked for ${distFolder}`);
364
+ yarg.exit(1, new Error("no files"));
365
+ }
366
+ const files = await getFilenamesRecursive(distFolder);
367
+ if (files.length === 0) {
368
+ console.error(`${chalk.red("ERROR")}: no files for upload in ${distFolder}`);
369
+ yarg.exit(1, new Error("no files"));
370
+ }
371
+ const uploadRequests = files.map((file) => {
372
+ let relativeName = file;
373
+ if (relativeName.startsWith(distFolder)) {
374
+ relativeName = relativeName.slice(distFolder.length);
375
+ // on server, normalize all paths to forward slash
376
+ relativeName = relativeName.replace(/\\/g, "/");
377
+ if (relativeName.startsWith("/")) {
378
+ relativeName = relativeName.slice(1);
379
+ }
380
+ }
381
+ const fileBuffer = fs.readFileSync(file);
382
+ return uploadFile(url, `${username}:${password}`, studyCode, fileBuffer, relativeName);
383
+ });
384
+ const spinner = ora(`Uploading files to ${url}...`).start();
385
+ Promise.all(uploadRequests)
386
+ .then(() => {
387
+ spinner.succeed(`All files uploaded from ${distFolder}`);
388
+ console.log(`Study can be viewed with browser at ${url}/studies/${studyCode}`);
389
+ })
390
+ .catch((error) => {
391
+ spinner.fail(`Failed uploading files from ${distFolder}`);
392
+ console.error(`${chalk.red("ERROR")}: ${error}`);
393
+ yarg.exit(1, new Error("upload error"));
394
+ });
395
+ })
112
396
  .demandCommand()
397
+ .strict()
398
+ // seems to have problems getting version automatically; thus I explicity
399
+ // provide
400
+ .version(cliVersion)
113
401
  .showHelpOnFail(true).argv;
402
+ function isValidAppName(name) {
403
+ const reserved = [
404
+ "abstract",
405
+ "arguments",
406
+ "await",
407
+ "boolean",
408
+ "break",
409
+ "byte",
410
+ "case",
411
+ "catch",
412
+ "char",
413
+ "class",
414
+ "const",
415
+ "continue",
416
+ "debugger",
417
+ "default",
418
+ "delete",
419
+ "do",
420
+ "double",
421
+ "else",
422
+ "enum",
423
+ "eval",
424
+ "export",
425
+ "extends",
426
+ "false",
427
+ "final",
428
+ "finally",
429
+ "float",
430
+ "for",
431
+ "function",
432
+ "goto",
433
+ "if",
434
+ "implements",
435
+ "import",
436
+ "in",
437
+ "instanceof",
438
+ "int",
439
+ "interface",
440
+ "let",
441
+ "long",
442
+ "native",
443
+ "new",
444
+ "null",
445
+ "package",
446
+ "private",
447
+ "protected",
448
+ "public",
449
+ "return",
450
+ "short",
451
+ "static",
452
+ "super",
453
+ "switch",
454
+ "synchronized",
455
+ "this",
456
+ "throw",
457
+ "throws",
458
+ "transient",
459
+ "true",
460
+ "try",
461
+ "typeof",
462
+ "var",
463
+ "void",
464
+ "volatile",
465
+ "while",
466
+ "with",
467
+ "yield",
468
+ ];
469
+ const builtin = [
470
+ "Array",
471
+ "Date",
472
+ "eval",
473
+ "function",
474
+ "hasOwnProperty",
475
+ "Infinity",
476
+ "isFinite",
477
+ "isNaN",
478
+ "isPrototypeOf",
479
+ "length",
480
+ "Math",
481
+ "name",
482
+ "NaN",
483
+ "Number",
484
+ "Object",
485
+ "prototype",
486
+ "String",
487
+ "toString",
488
+ "undefined",
489
+ "valueOf",
490
+ ];
491
+ if (reserved.includes(name) || builtin.includes(name)) {
492
+ return false;
493
+ }
494
+ const re = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
495
+ if (!re.test(name)) {
496
+ return false;
497
+ }
498
+ return true;
499
+ }
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.