Skip to content

Commit a04bf6d

Browse files
committed
Generate all required packages
1 parent ecd2fd6 commit a04bf6d

File tree

2 files changed

+141
-61
lines changed

2 files changed

+141
-61
lines changed

src/main.js

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
const repo = require('./repository');
2-
const {setArchiveBaseDir, createPackagesForTag, createPackageForTag} = require('./package-modules');
3-
const {compareTags, httpSlurp} = require('./utils');
4-
5-
/**
6-
* package(s) | from | modules-folder | repo url
7-
* ------------------------------------------------------------------------------------------------------------------
8-
* magento core packages | 2.4.0 | 'app/code/Magento' | https://github.com/mage-os/mirror-magento2.git
9-
* magento base package | | '' | special folder and exclude config
10-
* magento framework packages | | ~ 'lib/internal' | special folders and exclude config
11-
* ------------------------------------------------------------------------------------------------------------------
12-
* magento security packages | 1.0.0 | '' | https://github.com/mage-os/mirror-security-package.git
13-
* ------------------------------------------------------------------------------------------------------------------
14-
* magento inventory packages | 1.0.3 | 'app/code/Magento' | https://github.com/mage-os/mirror-inventory.git
15-
* | | | special exclude until 1.1.4
16-
* magento inventory packages | 1.1.5 | '' | https://github.com/mage-os/mirror-inventory.git
17-
* ------------------------------------------------------------------------------------------------------------------
18-
* magento/zendframework1 | 1.13.0 | '' | https://github.com/mage-os/mirror-zf1.git
19-
* | | | single package, but requires exclude config
20-
* | | | version not in release composer.json files
21-
* ------------------------------------------------------------------------------------------------------------------
22-
*/
23-
2+
const {compareTags} = require('./utils');
3+
const {
4+
setArchiveBaseDir,
5+
createPackagesForTag,
6+
createPackageForTag,
7+
createMagentoCommunityEditionMetapackage,
8+
createMagentoCommunityEditionProject
9+
} = require('./package-modules');
2410

2511
const archiveBaseDir = 'archives';
2612

@@ -30,8 +16,24 @@ async function listTagsFrom(url, from) {
3016
return (await repo.listTags(url)).filter(tag => compareTags(tag, from) >= 0);
3117
}
3218

19+
async function createMetaPackagesSinceTag(url, from) {
20+
const tags = await listTagsFrom(url, from);
21+
for (const tag of tags) {
22+
await createMagentoCommunityEditionMetapackage(url, tag);
23+
}
24+
return tags;
25+
}
26+
27+
async function createProjectPackagesSinceTag(url, from) {
28+
const tags = await listTagsFrom(url, from);
29+
for (const tag of tags) {
30+
await createMagentoCommunityEditionProject(url, tag);
31+
}
32+
return tags;
33+
}
34+
3335
async function createPackagesSinceTag(url, from, modulesPath, excludes) {
34-
const tags = await listTagsFrom(url, from);
36+
const tags = await listTagsFrom(url, from);
3537
for (const tag of tags) {
3638
await createPackagesForTag(url, modulesPath, excludes, tag);
3739
}
@@ -41,44 +43,61 @@ async function createPackagesSinceTag(url, from, modulesPath, excludes) {
4143
async function createPackageSinceTag(url, from, modulesPath, excludes, composerJsonUrl) {
4244
const tags = await listTagsFrom(url, from);
4345
for (const tag of tags) {
44-
await createPackageForTag(url, modulesPath, excludes, tag, composerJsonUrl.replace('{{version}}', tag));
46+
await createPackageForTag(url, modulesPath, excludes, tag, (composerJsonUrl || '').replace('{{version}}', tag));
4547
}
4648
return tags;
4749
}
4850

4951
(async function () {
5052
let tags, exclude, composerJsonUrl;
5153

52-
exclude = [];
53-
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'app/code/Magento', exclude)
54-
console.log('app/code/Magento modules', tags)
55-
56-
exclude = [".github/", "app/code/", "app/design/frontend/", "app/design/adminhtml/", "app/i18n/", "lib/internal/Magento/Framework/", "composer.lock"];
57-
composerJsonUrl = 'https://raw.githubusercontent.com/mage-os/magento2-base-composer-json/main/{{version}}/magento2-base/composer.json';
58-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', '', exclude, composerJsonUrl)
59-
console.log('magento/magento2-base', tags)
60-
61-
exclude = ['lib/internal/Magento/Framework/Amqp/', 'lib/internal/Magento/Framework/Bulk/', 'lib/internal/Magento/Framework/MessageQueue/'];
62-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework', exclude)
63-
console.log('magento/framework', tags)
64-
65-
exclude = [];
66-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Amqp', exclude)
67-
console.log('magento/framework-amqp', tags)
68-
69-
exclude = [];
70-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Bulk', exclude)
71-
console.log('magento/framework-bulk', tags);
72-
73-
exclude = [];
74-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/MessageQueue', exclude)
75-
console.log('magento/framework-message-queue', tags)
76-
77-
exclude = ['.github/', '_metapackage/'];
78-
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-security-package.git', '1.0.0', '', exclude)
79-
console.log('security packages', tags)
54+
// exclude = [];
55+
// tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'app/code/Magento', exclude)
56+
// console.log('app/code/Magento modules', tags)
57+
//
58+
// exclude = [".github/", "app/code/", "app/design/frontend/", "app/design/adminhtml/", "app/i18n/", "lib/internal/Magento/Framework/", "composer.lock"];
59+
// composerJsonUrl = 'https://raw.githubusercontent.com/mage-os/magento2-base-composer-json/main/{{version}}/magento2-base/composer.json';
60+
// tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', '', exclude, composerJsonUrl)
61+
// console.log('magento/magento2-base', tags)
62+
//
63+
// exclude = ['lib/internal/Magento/Framework/Amqp/', 'lib/internal/Magento/Framework/Bulk/', 'lib/internal/Magento/Framework/MessageQueue/'];
64+
// tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework', exclude)
65+
// console.log('magento/framework', tags)
66+
//
67+
// exclude = [];
68+
// tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Amqp', exclude)
69+
// console.log('magento/framework-amqp', tags)
70+
//
71+
// exclude = [];
72+
// tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Bulk', exclude)
73+
// console.log('magento/framework-bulk', tags);
74+
//
75+
// exclude = [];
76+
// tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/MessageQueue', exclude)
77+
// console.log('magento/framework-message-queue', tags)
78+
//
79+
// exclude = ['.github/', '_metapackage/'];
80+
// tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-security-package.git', '1.0.0', '', exclude)
81+
// console.log('security packages', tags)
82+
//
83+
// exclude = ['.github/', '_metapackage/', 'dev/'];
84+
// tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-inventory.git', '1.1.5', '', exclude)
85+
// console.log('inventory packages', tags)
86+
87+
// exclude = [];
88+
// tags = await createPackageSinceTag('https://github.com/mage-os/mirror-composer-root-update-plugin.git', '1.0.0', 'src/Magento/ComposerRootUpdatePlugin', exclude)
89+
// console.log('mirror-composer-root-update-plugin', tags)
90+
//
91+
// exclude = [];
92+
// tags = await createPackageSinceTag('https://github.com/mage-os/composer-dependency-version-audit-plugin.git', '0.1.0', '', exclude)
93+
// console.log('composer-dependency-version-audit-plugin', tags)
94+
95+
// create metapackage
96+
tags = await createMetaPackagesSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0');
97+
console.log('product-community-edition metapackage', tags);
98+
99+
// create project package
100+
tags = await createProjectPackagesSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0');
101+
console.log('project-community-edition', tags);
80102

81-
exclude = ['.github/', '_metapackage/', 'dev/'];
82-
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-inventory.git', '1.1.5', '', exclude)
83-
console.log('inventory packages', tags)
84103
})()

src/package-modules.js

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const JSZip = require('jszip');
44
const repo = require("./repository");
5-
const {lastTwoDirs, httpSlurp} = require('./utils');
5+
const {lastTwoDirs, httpSlurp, compareTags} = require('./utils');
66

77
const cliProgress = require('cli-progress');
88
const multibar = new cliProgress.MultiBar({
@@ -16,6 +16,8 @@ const multibar = new cliProgress.MultiBar({
1616

1717
let archiveBaseDir = 'archives';
1818

19+
const stableMtime = '2022-02-22 22:22:22';
20+
1921
/**
2022
* Given 'a/b/c/foo.txt', return ['a', 'a/b', 'a/b/c']
2123
*/
@@ -61,10 +63,6 @@ async function readComposerJson(url, dir, ref) {
6163
.then(b => Buffer.from(b).toString('utf8'));
6264
}
6365

64-
async function readComposerJsonUrl(url) {
65-
66-
}
67-
6866
function ensureArchiveDirectoryExists(archivePath) {
6967
const packageDir = path.dirname(archivePath);
7068
if (!fs.existsSync(packageDir)) fs.mkdirSync(packageDir, {recursive: true});
@@ -91,7 +89,7 @@ async function createPackageForTag(url, moduleDir, excludes, ref, composerJsonUr
9189
}
9290

9391
// use fixed date for stable package checksum generation
94-
const mtime = new Date('2022-02-22 22:22:22');
92+
const mtime = new Date(stableMtime);
9593

9694
const packageFilepath = archiveFilePath(name, version);
9795
if (fs.existsSync(packageFilepath)) {
@@ -119,6 +117,29 @@ async function createPackageForTag(url, moduleDir, excludes, ref, composerJsonUr
119117
stream.pipe(fs.createWriteStream(packageFilepath));
120118
}
121119

120+
async function createComposerJsonOnlyPackage(url, ref, name, transform) {
121+
const taggedComposerConfig = JSON.parse(await readComposerJson(url, '', ref));
122+
123+
const composerConfig = transform(taggedComposerConfig);
124+
125+
const files = [{
126+
filepath: 'composer.json',
127+
mtime: new Date(stableMtime),
128+
contentBuffer: Buffer.from(JSON.stringify(composerConfig), 'utf8'),
129+
isExecutable: false,
130+
}];
131+
132+
const packageFilepath = archiveFilePath(name, ref);
133+
if (fs.existsSync(packageFilepath)) {
134+
return;
135+
}
136+
137+
ensureArchiveDirectoryExists(packageFilepath);
138+
const zip = zipFileWith(files);
139+
const stream = await zip.generateNodeStream({streamFiles: false, platform: 'UNIX'});
140+
stream.pipe(fs.createWriteStream(packageFilepath));
141+
}
142+
122143

123144
module.exports = {
124145
setArchiveBaseDir(newArchiveBaseDir) {
@@ -152,4 +173,44 @@ module.exports = {
152173
multibar.stop();
153174
}, 100);
154175
},
176+
async createMagentoCommunityEditionMetapackage(url, ref) {
177+
const name = 'magento/product-community-edition';
178+
await createComposerJsonOnlyPackage(url, ref, name, taggedComposerConfig => {
179+
const composerConfig = Object.assign(taggedComposerConfig, {
180+
name: name,
181+
description: 'eCommerce Platform for Growth (Community Edition)',
182+
type: 'metapackage',
183+
require: Object.assign({'magento/magento2-base': ref}, taggedComposerConfig.require, taggedComposerConfig.replace)
184+
});
185+
186+
for (const k of ['autoload', 'autoload-dev', 'config', 'conflict', 'extra', 'minimum-stability', 'replace', 'require-dev', 'suggest']) {
187+
delete composerConfig[k];
188+
}
189+
return composerConfig;
190+
});
191+
},
192+
async createMagentoCommunityEditionProject(url, ref) {
193+
const name = 'magento/project-community-edition';
194+
await createComposerJsonOnlyPackage(url, ref, name, taggedComposerConfig => {
195+
const composerConfig = Object.assign(taggedComposerConfig, {
196+
name: name,
197+
description: 'eCommerce Platform for Growth (Community Edition)',
198+
extra: {'magento-force': 'override'},
199+
repositories: [{type: 'composer', url: 'https://repo.mage-os.org/'}],
200+
'minimum-stability': 'stable',
201+
require: Object.assign(
202+
{
203+
'magento/product-community-edition': ref,
204+
'magento/composer-root-update-plugin': '~1.1',
205+
},
206+
compareTags('2.4.3', ref) === -1 ? {} : {'magento/composer-dependency-version-audit-plugin': '~0.1'}
207+
)
208+
});
209+
210+
for (const k of ['replace', 'suggest']) {
211+
delete composerConfig[k];
212+
}
213+
return composerConfig;
214+
});
215+
}
155216
}

0 commit comments

Comments
 (0)