padl
Version:
Develop pattern libraries with lit-element
103 lines (84 loc) • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.randomPort = exports.getRightPathLocation = exports.getConfigArgs = exports.terserConfig = exports.babelConfig = exports.runCommand = void 0;
var _findNodeModules = _interopRequireDefault(require("find-node-modules"));
var _child_process = require("child_process");
var _path = _interopRequireDefault(require("path"));
var _fs = _interopRequireDefault(require("fs"));
var _net = _interopRequireDefault(require("net"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const randomPort = () => {
return new Promise(function (resolve, reject) {
const server = _net.default.createServer().listen(0, function () {
const port = server.address().port;
server.close(function () {
resolve(port);
});
}).on('error', reject);
});
};
exports.randomPort = randomPort;
const runCommand = command => {
return new Promise((resolve, reject) => {
(0, _child_process.exec)(command, (error, stdout, stderr) => {
if (error) {
reject(stdout + stderr);
} else {
resolve(stdout);
}
});
});
};
exports.runCommand = runCommand;
const babelConfig = {
babelrc: false,
babelHelpers: 'runtime',
compact: false,
presets: [['@babel/preset-env', {
targets: ">0.25%",
loose: true,
corejs: 3,
useBuiltIns: 'entry'
}]],
plugins: ["@babel/plugin-transform-spread", ["@babel/plugin-transform-runtime", {
"regenerator": true,
"useESModules": true
}]]
};
exports.babelConfig = babelConfig;
const terserConfig = {
output: {
comments: function (node, comment) {
const {
value,
type
} = comment;
if (type == "comment2") {
return /@version:/i.test(value);
}
}
}
};
exports.terserConfig = terserConfig;
const getConfigArgs = () => {
let config;
try {
config = JSON.parse(_fs.default.readFileSync('.padl').toString());
} catch (e) {
console.error('Missing config, is this the right folder?');
process.exit(1);
}
return config;
};
exports.getConfigArgs = getConfigArgs;
const getRightPathLocation = dir => {
return (0, _findNodeModules.default)().map(nodePath => {
const totalPath = _path.default.join(nodePath, dir);
if (_fs.default.existsSync(totalPath)) {
return totalPath;
}
}).filter(nodePath => nodePath)[0];
};
exports.getRightPathLocation = getRightPathLocation;