Skip to content

Commit

Permalink
feat(build): build experimental branch
Browse files Browse the repository at this point in the history
- remove node (`fs-extra`) dependency for builder
  • Loading branch information
marcolink committed Feb 14, 2021
1 parent c2618a1 commit e49420e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- experimental

jobs:
build:
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@
"types": "lib/index.d.ts",
"release": {
"branches": [
"master"
"master",
{
"name": "experimental",
"channel": "experimental",
"prerelease": true
}
],
"plugins": [
[
Expand Down
5 changes: 2 additions & 3 deletions src/cf-definitions-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Field} from 'contentful';
import * as fs from 'fs-extra';
import * as path from 'path';
import {
forEachStructureChild,
Expand Down Expand Up @@ -61,12 +60,12 @@ export default class CFDefinitionsBuilder {
return this;
};

public write = async (dir: string): Promise<void> => {
public write = async (dir: string, writeCallback: (filePath: string, content: string) => Promise<void>): Promise<void> => {
this.addIndexFile();

const writePromises = this.project.getSourceFiles().map(file => {
const targetPath = path.resolve(dir, file.getFilePath().slice(1));
return fs.writeFile(targetPath, file.getFullText());
return writeCallback(targetPath, file.getFullText());
});
await Promise.all(writePromises);
};
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Command, flags} from '@oclif/command';
import * as fs from 'fs-extra';
import {writeFile} from 'fs-extra';
import * as path from 'path';
import CFDefinitionsBuilder from './cf-definitions-builder';

Expand Down Expand Up @@ -59,7 +60,7 @@ class ContentfulMdg extends Command {
await fs.remove(outDir);
}
await fs.ensureDir(outDir);
await builder.write(flags.out);
await builder.write(flags.out, writeFile);
} else {
this.log(builder.toString());
}
Expand Down
11 changes: 6 additions & 5 deletions test/cf-definitions-builder.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect} from '@oclif/test';
import {writeFile} from "fs-extra";
import * as fs from 'fs-extra';
import * as path from 'path';
//@ts-ignore
Expand Down Expand Up @@ -289,7 +290,7 @@ describe('A Contentful definitions builder', () => {
it('can write an interface to output file', async () => {
builder.appendType(modelType);

await builder.write(fixturesPath);
await builder.write(fixturesPath, writeFile);

const result = await fs.readFile(path.resolve(fixturesPath, 'TypeSysId.ts'));

Expand All @@ -314,7 +315,7 @@ describe('A Contentful definitions builder', () => {
}, fields: [],
});

await builder.write(fixturesPath);
await builder.write(fixturesPath, writeFile);

const result1 = await fs.readFile(path.resolve(fixturesPath, 'TypeSysId.ts'));
const result2 = await fs.readFile(path.resolve(fixturesPath, 'TypeMyType.ts'));
Expand Down Expand Up @@ -367,7 +368,7 @@ describe('A Contentful definitions builder', () => {
],
});

await builder.write(fixturesPath);
await builder.write(fixturesPath, writeFile);

const result1 = await fs.readFile(path.resolve(fixturesPath, 'TypeSysId.ts'));
const result2 = await fs.readFile(path.resolve(fixturesPath, 'TypeMyType.ts'));
Expand Down Expand Up @@ -395,7 +396,7 @@ describe('A Contentful definitions builder', () => {

it('can create index file', async () => {
builder.appendType(modelType);
await builder.write(fixturesPath);
await builder.write(fixturesPath, writeFile);

const result1 = await fs.readFile(path.resolve(fixturesPath, 'index.ts'));
expect('\n' + result1.toString()).to.equal(stripIndent(`
Expand Down Expand Up @@ -432,7 +433,7 @@ describe('A Contentful definitions builder', () => {
],
});

await builder.write(fixturesPath);
await builder.write(fixturesPath, writeFile);

const result2 = await fs.readFile(path.resolve(fixturesPath, 'TypeMyType.ts'));

Expand Down

0 comments on commit e49420e

Please sign in to comment.