handoff-app
Version:
Automated documentation toolchain for building client side documentation from figma
130 lines (129 loc) • 5.96 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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getComponentOutputPath = exports.SlotType = void 0;
exports.componentTransformer = componentTransformer;
exports.processSharedStyles = processSharedStyles;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const sass_1 = __importDefault(require("sass"));
const logger_1 = require("../../utils/logger");
const api_1 = __importStar(require("./component/api"));
const builder_1 = __importDefault(require("./component/builder"));
const css_1 = require("./component/css");
const javascript_1 = require("./component/javascript");
var SlotType;
(function (SlotType) {
SlotType["TEXT"] = "text";
SlotType["IMAGE"] = "image";
SlotType["BUTTON"] = "button";
SlotType["ARRAY"] = "array";
SlotType["NUMBER"] = "number";
SlotType["BOOLEAN"] = "boolean";
SlotType["OBJECT"] = "object";
SlotType["FUNCTION"] = "function";
SlotType["ENUM"] = "enum";
SlotType["ANY"] = "any";
})(SlotType || (exports.SlotType = SlotType = {}));
const getComponentOutputPath = (handoff) => path_1.default.resolve((0, api_1.getAPIPath)(handoff), 'component');
exports.getComponentOutputPath = getComponentOutputPath;
/**
* Create a component transformer
* @param handoff
* @param documentationObject
* @returns
*/
function componentTransformer(handoff) {
return __awaiter(this, void 0, void 0, function* () {
const componentData = yield (0, builder_1.default)(handoff);
yield (0, api_1.default)(handoff, componentData);
yield (0, javascript_1.buildMainJS)(handoff);
yield (0, css_1.buildMainCss)(handoff);
});
}
/**
* Process the shared styles with sass compileAsync
* @param handoff
* @returns
*/
function processSharedStyles(handoff) {
return __awaiter(this, void 0, void 0, function* () {
const custom = path_1.default.resolve(handoff.workingPath, `integration/components`);
const publicPath = path_1.default.resolve(handoff.workingPath, `public/api/component`);
// Is there a scss file with the same name?
const scssPath = path_1.default.resolve(custom, 'shared.scss');
const cssPath = path_1.default.resolve(custom, 'shared.css');
if (fs_extra_1.default.existsSync(scssPath) && !fs_extra_1.default.existsSync(cssPath)) {
logger_1.Logger.success(`Compiling shared styles`);
try {
const result = yield sass_1.default.compileAsync(scssPath, {
loadPaths: [
path_1.default.resolve(handoff.workingPath, 'integration/sass'),
path_1.default.resolve(handoff.workingPath, 'node_modules'),
path_1.default.resolve(handoff.workingPath),
path_1.default.resolve(handoff.workingPath, handoff.exportsDirectory, handoff.getProjectId()),
],
});
if (result.css) {
// write the css to the public folder
const css = '/* These are the shared styles used in every component. */ \n\n' + result.css;
const cssPath = path_1.default.resolve(publicPath, 'shared.css');
logger_1.Logger.success(`Writing shared styles to ${cssPath}`);
yield fs_extra_1.default.writeFile(cssPath, result.css);
return css;
}
}
catch (e) {
logger_1.Logger.error(`Error compiling shared styles`, e);
}
}
else if (fs_extra_1.default.existsSync(cssPath)) {
const css = yield fs_extra_1.default.readFile(cssPath, 'utf8');
return css;
}
});
}