Skip to content

Commit

Permalink
0.0.518
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Sep 16, 2024
1 parent 2cf1ee2 commit 5ff4f0c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,21 @@ const pckg = await packager.export({ packageLinkId: myPackageId });
// Import again in other system
await packager.import(pckg);
// Coming soon packager.update({ packageLinkId: myPackageId, pckg });
```

## Write and read packages locally for example on server
```bash
npx @deep-foundation/deeplinks --exec --localhost
```
```js
const packages = deep.Packages();
// export and write
const exported = await packages.export();
// { [name@version]: Package } // possible Package.errors
await packages.write(process.cwd(), exported);
// read and import
const readed = await packages.read(process.cwd());
// { [name@version]: Package }
const imported = await packages.import(readed);
// { [name@version]: Package } // possible Package.errors
```
8 changes: 4 additions & 4 deletions call.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ if (options.generate && (options.force || !fs.existsSync(`${cwd}/deep.config.jso
console.log(`${cwd}/deep.config.json or -c "$(cat your/path/to/deep.config.json)" is not defined`);
return;
}
const config = deepConfig || JSON.parse(options.config || DEEPLINKS_CALL_OPTIONS);
if (options.localhost) {
deepConfig.DEEPLINKS_PUBLIC_URL = 'http://localhost:3006'
deepConfig.NEXT_PUBLIC_DEEPLINKS_URL = 'http://localhost:3006'
deepConfig.NEXT_PUBLIC_GQL_PATH = 'http://localhost:3006/gql'
config.DEEPLINKS_PUBLIC_URL = 'http://localhost:3006'
config.NEXT_PUBLIC_DEEPLINKS_URL = 'http://localhost:3006'
config.NEXT_PUBLIC_GQL_PATH = 'http://localhost:3006/gql'
}
const config = deepConfig || JSON.parse(options.config || DEEPLINKS_CALL_OPTIONS);
console.log('config', config);

if (config && options.down) {
Expand Down
20 changes: 14 additions & 6 deletions imports/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,50 @@ export class Packages {
string: { value: { _neq: 'deep' } },
});
}
async export(address: string): Promise<{ [name: string]: Package }> {
async export(): Promise<{ [name: string]: Package }> {
const deep = this.deep;
const packager = deep.Packager();
const { data: packages } = await this.select();
console.log('export packages', packages.map(p => p.id).join(', '));
const results = {};
for (let i = 0; i < packages.length; i++) {
const p = packages[i];
console.log('export package', `${p.id} ${p?.value?.value}`);
const pckg = await packager.export({ packageLinkId: p.id });
results[pckg.package.name];
console.log('exported package', `${pckg.package.name} ${pckg.package.version}`);
results[`${pckg.package.name}@${pckg.package.version}`] = pckg;
}
return results;
}
async write(address: string, pckgs: { [name: string]: Package }) {
const packages = Object.values(pckgs);
const deep = this.deep;
console.log('write packages', Object.keys(pckgs).join(','));
for (let i = 0; i < packages.length; i++) {
const p = packages[i];
fs.writeFileSync(
path.join(address, `${p?.package?.name}@${p.package.version}`),
path.join(address, `${p?.package?.name}@${p.package.version}.json`),
JSON.stringify(p, null, 2),
{ encoding: 'utf-8' },
);
console.log('writeed package', `${path.join(address, `${p?.package?.name}@${p.package.version}`)}`);
}
}
async read(address: string): Promise<{ [name: string]: Package }> {
const deep = this.deep;
const packager = deep.Packager();
const pckgs = fs.readdirSync(address);
console.log(`read packages from ${address} ${pckgs.join(', ')}`);
const results = {};
for (let i = 0; i < pckgs.length; i++) {
if (pckgs[i].slice(-5) === '.json' && pckgs[i] != 'deep.config.json') {
console.log(path.join(address, pckgs[i]));
console.log('read package', path.join(address, pckgs[i]));
const json = fs.readFileSync(path.join(address, pckgs[i]), { encoding: 'utf-8' });
try {
const pckg = JSON.parse(json);
results[pckg.package.name] = pckg;
results[`${pckg.package.name}@${pckg.package.version}`] = pckg;
} catch(e) {
console.log(e);
console.log('error read package', e);
}
}
}
Expand All @@ -63,9 +69,11 @@ export class Packages {
const deep = this.deep;
const packager = deep.Packager();
const packages = Object.values(pckgs);
console.log(`import packages from ${Object.keys(pckgs).join(', ')}`);
const results = {};
for (let i = 0; i < packages.length; i++) {
const p = packages[i];
console.log(`import package ${p.package.name}@${p.package.version}`);
results[`${p.package.name}@${p.package.version}`] = await packager.import(p);
}
return results;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deep-foundation/deeplinks",
"version": "0.0.516",
"version": "0.0.518",
"license": "Unlicense",
"type": "module",
"main": "import.js",
Expand Down

0 comments on commit 5ff4f0c

Please sign in to comment.