code-workshop-kit
Version:
The future of remote code workshops & training
42 lines • 1.75 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearAppKey = exports.generateAppKey = void 0;
const core_1 = require("@babel/core");
const crypto_1 = __importDefault(require("crypto"));
const fs_1 = __importDefault(require("fs"));
const babel_plugin_app_key_1 = __importDefault(require("./babel-plugin-app-key"));
const generateAppKey = (dir, len = 28) => {
var _a;
const workshopCfg = `${dir}/cwk.config.js`;
let key = '';
if (fs_1.default.existsSync(workshopCfg)) {
key = crypto_1.default.randomBytes(len).toString('hex');
const cfgCode = fs_1.default.readFileSync(workshopCfg, 'utf8');
const newCfgCode = (_a = core_1.transformSync(cfgCode, {
plugins: [[babel_plugin_app_key_1.default, { key }]],
})) === null || _a === void 0 ? void 0 : _a.code;
if (newCfgCode) {
fs_1.default.writeFileSync(workshopCfg, newCfgCode);
}
}
return key;
};
exports.generateAppKey = generateAppKey;
const clearAppKey = (dir) => {
var _a;
const workshopCfg = `${dir}/cwk.config.js`;
if (fs_1.default.existsSync(workshopCfg)) {
const cfgCode = fs_1.default.readFileSync(workshopCfg, 'utf8');
const newCfgCode = (_a = core_1.transformSync(cfgCode, {
plugins: [[babel_plugin_app_key_1.default, { clear: true }]],
})) === null || _a === void 0 ? void 0 : _a.code;
if (newCfgCode) {
fs_1.default.writeFileSync(workshopCfg, newCfgCode);
}
}
};
exports.clearAppKey = clearAppKey;
//# sourceMappingURL=generateAppKey.js.map