UNPKG

1.92 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15Object.defineProperty(exports, "__esModule", { value: true });
16const bowerConfig = require("bower-config");
17const fs = require("fs");
18const path = require("path");
19function readConfigSync(filename, root) {
20 const configPath = path.resolve(root || '', filename);
21 let config;
22 try {
23 config = fs.readFileSync(configPath, 'utf-8');
24 }
25 catch (e) {
26 return {};
27 }
28 try {
29 return JSON.parse(config);
30 }
31 catch (e) {
32 console.error(`Could not parse ${configPath}`);
33 console.error(e);
34 }
35 return {};
36}
37/**
38 * Determines the package name by reading from the following sources:
39 *
40 * 1. `options.packageName`
41 * 2. bower.json, if options.npm is not true
42 * 3. package.json
43 * 4. The name of the root directory
44 */
45function getPackageName(options) {
46 return options.packageName ||
47 !options.npm && readConfigSync('bower.json', options.root).name ||
48 readConfigSync('package.json', options.root).name ||
49 path.basename(options.root);
50}
51exports.getPackageName = getPackageName;
52function getComponentDir(options) {
53 const root = options.root || process.cwd();
54 const bowerDir = bowerConfig.read(root).directory;
55 return options.componentDir || (options.npm ? 'node_modules' : bowerDir);
56}
57exports.getComponentDir = getComponentDir;
58//# sourceMappingURL=config.js.map
\No newline at end of file