@agnostack/next-plugins
Version:
Please contact agnoStack via info@agnostack.com for any questions
91 lines • 4.33 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPrompts = exports.getEnvData = void 0;
const chalk_1 = __importDefault(require("chalk"));
const env_1 = require("@next/env");
const env_2 = require("@agnostack/env");
const display_1 = require("./display");
// NOTE: this has the same value found in next/constants { PHASE_DEVELOPMENT_SERVER } - w/o hard dep so we dont pin to a version
const PHASE_DEVELOPMENT_SERVER = 'phase-development-server';
const getEnvData = (dirName = './', envData) => {
const { combinedEnv } = (0, env_1.loadEnvConfig)(dirName);
return (0, env_2.parseEnvData)(Object.assign(Object.assign({}, combinedEnv), envData));
};
exports.getEnvData = getEnvData;
const getPrompts = async (_questions, { phase, disabled } = {}) => {
const questions = (0, display_1.ensureArray)(_questions).reduce((__questions, _a) => {
var { name, message } = _a, question = __rest(_a, ["name", "message"]);
return ([
...__questions,
Object.assign(Object.assign({ name }, question), message && {
message: `[${name}] ${message}`,
})
]);
}, []);
let values = questions.reduce((_values, { name, initial: value }) => (Object.assign(Object.assign({}, _values), { [name]: value })), {});
if (phase === PHASE_DEVELOPMENT_SERVER) {
if (!disabled) {
try {
const prompts = (await Promise.resolve().then(() => __importStar(require('prompts')))).default;
values = await prompts(questions);
}
catch (_ignore) {
console.warn(`${chalk_1.default.yellowBright('next-plugins')} - ${chalk_1.default.yellow('warn')} - ${
// eslint-disable-next-line max-len
chalk_1.default.yellow(`Ignoring ${chalk_1.default.bold("missing 'devDependency' for 'prompts'")} - required when setting 'interactive: true'`)}`);
}
}
else {
Object.entries(values).forEach(([name, value]) => {
var _a;
const { message } = (_a = questions.find((question) => question.name === name)) !== null && _a !== void 0 ? _a : {};
if (message) {
console.info(`${chalk_1.default.yellowBright('next-plugins')} - ${chalk_1.default.bold(message)}: ${value}`);
}
else {
console.info(`${chalk_1.default.yellowBright('next-plugins')} - [${chalk_1.default.bold(name)}]: ${value}`);
}
});
}
}
return values;
};
exports.getPrompts = getPrompts;
//# sourceMappingURL=config.js.map