Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm run build
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"lint": "eslint . --ext .ts",
"format": "prettier --write \"src/**/*.ts\"",
"prepare": "npm run build",
"prepack": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
Expand Down
5 changes: 0 additions & 5 deletions shareable/cs-lp-script.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<script type='module'>
if (!window.ContentstackLivePreviewInitialized) {
const { default: ContentstackLivePreview } = await import('https://esm.sh/@contentstack/[email protected]');
console.log("Initializing the live preview sdk");
ContentstackLivePreview.init({
enable: true,
ssr: false,
Expand Down Expand Up @@ -113,7 +112,6 @@
});
}

console.log("Matched preview elements:", previewElements);

if (previewElements.length) {
let newElements = doc.querySelectorAll(
Expand All @@ -127,7 +125,6 @@
);
}

console.log("Matched new elements:", newElements, doc);

previewElements.forEach((previewEl, index) => {
const newEl = newElements[index];
Expand All @@ -151,7 +148,6 @@
event.data.type === "live-preview" &&
event.data.data?.type === "client-data-send"
) {
console.log("Message received:", event.data);

function parseJSONSafe(jsonString) {
try {
Expand Down Expand Up @@ -370,7 +366,6 @@
{%- endif %}

if (livePreviewInfo?.isLivePreview) {
console.log("theme:", theme_variable);
sendPreviewRequest(theme_variable, livePreviewInfo);
}
}
Expand Down
21 changes: 0 additions & 21 deletions src/Github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ async function downloadRepositoryZip(
const zipPath = path.join(targetPath, 'repo.zip');

try {
console.log(`Downloading ${owner}/${repo} (${branch}) from GitHub API...`);

const response = await axios({
method: 'GET',
Expand All @@ -44,7 +43,6 @@ async function downloadRepositoryZip(
// Download the zip file
await pipeline(response.data, createWriteStream(zipPath));

console.log(`Downloaded repository zip to ${zipPath}`);

// Extract the zip file (we'll need to implement this next)
await extractZipFile(zipPath, targetPath);
Expand All @@ -63,14 +61,12 @@ async function downloadRepositoryZip(
*/
async function extractZipFile(zipPath: string, targetPath: string): Promise<void> {
try {
console.log(`Attempting to extract ${zipPath} to ${targetPath}...`);

const zip = new AdmZip(zipPath);

// Extract all files to target directory
zip.extractAllTo(targetPath, true);

console.log(`Successfully extracted repository to ${targetPath}`);

// Handle GitHub's zip structure - move files from the root subdirectory
const items = fs.readdirSync(targetPath);
Expand Down Expand Up @@ -102,7 +98,6 @@ async function extractZipFile(zipPath: string, targetPath: string): Promise<void

// Remove the now-empty subdirectory
fs.rmSync(rootDirPath, { recursive: true, force: true });
console.log(`Reorganized files from GitHub zip structure`);
}

} catch (error) {
Expand All @@ -129,20 +124,16 @@ export async function cloneRepository(
let actualTargetPath = targetPath;

// First, try to use the provided target path (should be the pre-built views directory)
console.log(`Attempting to use target directory: ${actualTargetPath}`);

try {
// Test if we can write to the target directory
if (fs.existsSync(actualTargetPath)) {
console.log(`Target directory exists, testing write permissions...`);
// Try to create a test file to check write permissions
const testFile = path.join(actualTargetPath, '.write-test');
fs.writeFileSync(testFile, 'test');
fs.unlinkSync(testFile);
console.log(`Write permissions confirmed for ${actualTargetPath}`);

// Empty the directory for fresh clone
console.log(`Emptying directory: ${actualTargetPath}`);
const items = fs.readdirSync(actualTargetPath);
for (const item of items) {
const itemPath = path.join(actualTargetPath, item);
Expand All @@ -152,9 +143,7 @@ export async function cloneRepository(
fs.unlinkSync(itemPath);
}
}
console.log(`Successfully emptied ${actualTargetPath}`);
} else {
console.log(`Creating target directory: ${actualTargetPath}`);
fs.mkdirSync(actualTargetPath, { recursive: true });
}
} catch (error) {
Expand All @@ -165,14 +154,11 @@ export async function cloneRepository(
// This provides some persistence within the same serverless container lifecycle
const repoIdentifier = `${owner}-${repo}`.replace(/[^a-zA-Z0-9-]/g, '-');
const fallbackDir = path.join('/tmp', `views-${repoIdentifier}`);
console.log(`Using fallback directory: ${fallbackDir}`);
console.log(`Note: Repository will be cloned to temporary location. Content may be lost between container restarts.`);

actualTargetPath = fallbackDir;

// Create or clean the fallback directory
if (fs.existsSync(fallbackDir)) {
console.log(`Cleaning existing fallback directory: ${fallbackDir}`);
const items = fs.readdirSync(fallbackDir);
for (const item of items) {
const itemPath = path.join(fallbackDir, item);
Expand All @@ -183,12 +169,8 @@ export async function cloneRepository(
}
}

// Try git clone first, fall back to GitHub API if git is not available
const branchInfo = branch ? ` (branch: ${branch})` : ' (default branch)';

try {
// First, try using git clone
console.log(`Attempting to clone ${owner}/${repo}${branchInfo} using git...`);

let cloneCommand = `git clone --depth 1`;
if (branch) {
Expand All @@ -197,18 +179,15 @@ export async function cloneRepository(
cloneCommand += ` https://${auth}@github.com/${owner}/${repo}.git .`;

execSync(cloneCommand, { cwd: actualTargetPath, stdio: 'inherit' });
console.log(`Successfully cloned ${owner}/${repo}${branchInfo} into ${actualTargetPath} using git`);

} catch (gitError) {
const error = gitError as Error & { status?: number };

// If git command is not found (status 127), try GitHub API download
if (error.status === 127 || error.message.includes('git: command not found')) {
console.log(`Git not available (${error.message}), falling back to GitHub API download...`);

try {
await downloadRepositoryZip(cloneConfig, actualTargetPath);
console.log(`Successfully downloaded ${owner}/${repo}${branchInfo} into ${actualTargetPath} using GitHub API`);
} catch (apiError) {
console.error(`Both git clone and GitHub API download failed:`, apiError);
throw new Error(`Failed to obtain repository: Git unavailable and API download failed - ${(apiError as Error).message}`);
Expand Down
13 changes: 0 additions & 13 deletions src/Liquid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function setupLiquidEngine(options: LiquidEngineOptions = {}): Liquid {
const schemaJson = this.schemaContent.join('\n');
try {
const schema = JSON.parse(schemaJson);
console.log('Parsed schema:', schema);
return `<script type="application/json">${JSON.stringify(schema)}</script>`;
} catch (err) {
console.error('Error parsing schema:', err.message);
Expand All @@ -129,10 +128,8 @@ export function setupLiquidEngine(options: LiquidEngineOptions = {}): Liquid {
});

engine.registerFilter('image_url', (image, options = {}) => {
console.log('image_url filter called with:', image, options);

if (!image) {
console.log('No image provided, returning placeholder');
return '/placeholder-image.jpg';
}

Expand All @@ -144,7 +141,6 @@ export function setupLiquidEngine(options: LiquidEngineOptions = {}): Liquid {
} else if (image.src) {
baseUrl = image.src;
} else {
console.log('No valid URL found in image object');
return '/placeholder-image.jpg';
}

Expand Down Expand Up @@ -320,7 +316,6 @@ export function setupLiquidEngine(options: LiquidEngineOptions = {}): Liquid {

if (block.type) {
filenameToRender = block.type === '@app' ? 'app-block' : block.type;
console.log(`[Custom Render] Rendering for block type: ${block.type}, using snippet: ${filenameToRender}.liquid`);
} else {
throw new Error(`[Custom Render] Cannot render block: "block.type" is missing. Block data: ${JSON.stringify(block)}`);
}
Expand Down Expand Up @@ -397,14 +392,6 @@ export function setupLiquidEngine(options: LiquidEngineOptions = {}): Liquid {
...localContextFromParams // Explicit render parameters (highest priority)
};

console.log(`[Custom Render] Rendering ${filePath} with globals:`, {
hasShop: !!renderCtx.shop,
hasProduct: !!renderCtx.product,
hasLocalization: !!renderCtx.localization,
locale: renderCtx.localization?.language?.iso_code,
productTitle: renderCtx.product?.title
});

try {
const html = await this.liquid.renderFile(filePath, renderCtx);
return html;
Expand Down
2 changes: 0 additions & 2 deletions src/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ const saveDataInObject = (type, path, data, dataType, entryMetaObject, extraData
}

const getUpdatedProductMetafields = async (currentMetafields, contentType, entry, { ctUid, entryUid, hash }) => {
console.log("🚀 ~ getUpdatedProductMetafields ~ currentMetafields:", currentMetafields)
if (!currentMetafields || typeof currentMetafields !== 'object') return;
const updatedMetafields = {};
for (const [key, value] of Object.entries(currentMetafields)) {
Expand Down Expand Up @@ -705,7 +704,6 @@ const getUpdatedMetaobject = async (currentMetaobjects, keyBasedCt, entry, { ctU
}
currentMetaobjects[type] = updatedMetaobjects[type];
}
console.log("🚀 ~ getUpdatedMetaobject ~ updatedMetaobjects:", JSON.stringify(updatedMetaobjects, null, 4))
return {
currentMetaobjects,
dataCSLPMapping
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
Expand Down