Skip to content

Commit

Permalink
chore: modify script
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwozdz committed Aug 25, 2023
1 parent 2daee95 commit fc8ce30
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions fork-scripts/modify-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ async function modifyPackageFiles() {
for (let i = 0; i < packages.length; i++) {
const filePath = path.join('../', packages[i], 'package.json');
const packageFile = require(filePath);
const name = packageFile.name.replace('@koopjs/', '');
const name = packageFile.name.replace('@koopjs/', '').replace('koop-', '');
const buildDest = `../../customdata/framework/${name}`;
const dependencies = stripKoopDeps(packageFile.dependencies);

await modifyJsonFile(
path.join(packages[i], 'package.json'),
{
name,
dependencies: stripKoopDeps(packageFile.dependencies),
author: undefined,
description: undefined,
keywords: undefined,
dependencies,
devDependencies: undefined,
files: undefined,
contributors: undefined,
Expand All @@ -39,14 +44,29 @@ async function modifyPackageFiles() {
types: undefined,
scripts: {
clean: `shx rm -rf ${buildDest} && shx rm package-lock.json`,
build: `shx mkdir ${buildDest} && shx cp package.json ${buildDest} && shx cp -r ./src ${buildDest} && shx cp -r ./node_modules ${buildDest}`,
build: generateBuildCmd(buildDest, dependencies),
},
},
{ ifFieldIsMissing: 'skip' },
);
}
}

function generateBuildCmd(buildDest, dependencies) {
const mkDir = `shx mkdir ${buildDest}`;
const cpPackage = `shx cp package.json ${buildDest}`;
const cpSrc = `shx cp -r ./src ${buildDest}`;

const build = `${mkDir} && ${cpPackage} && ${cpSrc}`;

if (Object.keys(dependencies).length === 0) {
return build;
}

const cpNodeModules = `shx cp -r ./node_modules ${buildDest}`;
return `${build} && ${cpNodeModules}`;
}

function stripKoopDeps(dependencies) {
return Object.entries(dependencies)
.filter(([key]) => {
Expand All @@ -70,6 +90,7 @@ async function deleteNonEssentialFiles() {
'!packages/**/LICENSE',
]);
await deleteAsync([
'packages/**/test',
'packages/**/.nycrc',
'packages/**/*.svg',
'packages/**/*.md',
Expand All @@ -82,7 +103,7 @@ async function deleteNonEssentialFiles() {
}

async function copyGithubAction() {
return copy(['fork-scripts/ci-tests.yml', '.github/workflows'], { up: true});
return copy(['fork-scripts/ci-tests.yml', '.github/workflows'], { up: true });
}

async function replacePackageReferences() {
Expand Down

0 comments on commit fc8ce30

Please sign in to comment.