Skip to content
Closed
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
62 changes: 37 additions & 25 deletions packages/evershop/scripts/postpack.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import fs from 'fs';
import path from 'path';
import packageJson from '../package.json' with { type: 'json' };
// Get the current version of the package from the nearest package.json file
const { version } = packageJson;
// Get the --pack-destination from the command line arguments
// Create a package.json file in the packDestination directory with dependencies is the package itself
fs.writeFileSync(
path.resolve(process.env.npm_config_pack_destination, 'package.json'),
JSON.stringify(
{
name: packageJson.name,
version,
dependencies: {
'@evershop/evershop': `file:./evershop-evershop-${version}.tgz`
},
scripts: {
setup: 'evershop install',
start: 'evershop start',
'start:debug': 'evershop start:debug',
build: 'evershop build',
dev: 'evershop dev',
'user:create': 'evershop user:create'
}

try {
// Extract package details
const { name, version } = packageJson;

// Get the pack destination directory from environment variables
const packDestination = process.env.npm_config_pack_destination;

if (!packDestination) {
throw new Error('❌ Missing environment variable: npm_config_pack_destination');
}

// Define the new package.json structure
const newPackageJson = {
name,
version,
dependencies: {
'@evershop/evershop': `file:./evershop-evershop-${version}.tgz`
},
null,
2
)
);
scripts: {
setup: 'evershop install',
start: 'evershop start',
'start:debug': 'evershop start:debug',
build: 'evershop build',
dev: 'evershop dev',
'user:create': 'evershop user:create'
}
};

// Write the new package.json file
const outputPath = path.resolve(packDestination, 'package.json');
fs.writeFileSync(outputPath, JSON.stringify(newPackageJson, null, 2));

console.log(`✅ package.json successfully created at: ${outputPath}`);
} catch (error) {
console.error('Error generating package.json:', error.message);
process.exit(1);
}
48 changes: 31 additions & 17 deletions packages/evershop/scripts/postpublish.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
import fs from 'fs';
import path from 'path';

function getFileRecursive(dir, files) {
const list = fs.readdirSync(dir);
list.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
getFileRecursive(filePath, files);
/**
* Recursively retrieves all files from a given directory.
* @param {string} dir - The directory to search.
* @param {string[]} fileList - Array to store file paths.
*/
const getAllFiles = (dir, fileList = []) => {
const items = fs.readdirSync(dir);

for (const item of items) {
const fullPath = path.join(dir, item);
const stats = fs.statSync(fullPath);

if (stats.isDirectory()) {
getAllFiles(fullPath, fileList);
} else {
files.push(filePath);
fileList.push(fullPath);
}
});
}
}

const files = [];
return fileList;
};

getFileRecursive(path.resolve(__dirname, './bin/serve'), files);
const baseDir = path.resolve(__dirname, './bin/serve');
const allFiles = getAllFiles(baseDir);

for (const file of allFiles) {
try {
const content = fs.readFileSync(file, 'utf8');
const updatedContent = content.replace(/\.\.\/dist/g, '../src');
fs.writeFileSync(file, updatedContent, 'utf8');
} catch (error) {
console.error(`Error processing file ${file}:`, error.message);
}
}

files.forEach((file) => {
const source = fs.readFileSync(file, { encoding: 'utf8', flag: 'r' });
const result = source.replace(/\.\.\/dist/g, '../src');
fs.writeFileSync(file, result, 'utf8');
});
console.log(`✅ Updated ${allFiles.length} files successfully.`);