sfcc-dts
Version:
> High quality Salesforce Commerce Cloud type definitions. A dw-api-types "done right"
57 lines (55 loc) • 2.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const console_1 = require("console");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const picocolors_1 = __importDefault(require("picocolors"));
const prompts_1 = __importDefault(require("prompts"));
const customtypes_1 = require("./customtypes");
(async () => {
const banner = `
_|_| _| _|
_|_|_| _| _|_|_| _|_|_| _|_|_| _|_|_|_| _|_|_|
_|_| _|_|_|_| _| _| _|_|_|_|_| _| _| _| _|_|
_|_| _| _| _| _| _| _| _|_|
_|_|_| _| _|_|_| _|_|_| _|_|_| _|_| _|_|_|
`;
(0, console_1.log)(picocolors_1.default.magenta(banner));
(0, console_1.log)(`Welcome to ${picocolors_1.default.magenta('sfcc-dts')} custom attributes definition generator.\n`);
let defaultpath = './sites/site_template/meta/';
let extensionspath;
if (fs_1.default.existsSync(defaultpath)) {
(0, console_1.log)(`directory ${defaultpath} available`);
extensionspath = defaultpath;
}
else {
const response = await (0, prompts_1.default)([
{
type: 'text',
name: 'meta',
message: 'Directory containing system-objecttype-extensions.xml?',
initial: defaultpath,
validate: value => !fs_1.default.existsSync(value) ? `directory ${value} not found` : true
}
]);
extensionspath = response.meta;
}
(0, console_1.log)(`Generating definitions for custom attributes`);
if (extensionspath) {
await (0, customtypes_1.generateCustomTypes)(extensionspath);
}
(0, console_1.log)(`Write @types/dw/index.d.ts`);
let references = '/// <reference path="../../node_modules/sfcc-dts/@types/sfcc/index.d.ts" />\n';
if (extensionspath) {
references += '/// <reference path="./attrs.d.ts" />\n';
}
else {
references += '/// <reference path="../../node_modules/sfcc-dts/@types/sfcc/attrs.d.ts" />\n';
}
fs_1.default.writeFileSync(path_1.default.join('@types/dw', 'index.d.ts'), references);
(0, console_1.log)(`\nDone!`);
})();