Skip to content

Commit

Permalink
fix(cli): Fix config json format by adding the missing newline and re…
Browse files Browse the repository at this point in the history
…move double quotes from commit message. (#2795)

Co-authored-by: Blayne Chard <[email protected]>
  • Loading branch information
Wentao-Kuang and blacha authored May 31, 2023
1 parent c33dda4 commit 76a77ae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@
"get-port": "^6.1.2",
"node-fetch": "^3.2.3",
"p-limit": "^4.0.0",
"prettier": "^2.8.8",
"pretty-json-log": "^1.0.0",
"slugify": "^1.6.5",
"zod": "^3.17.3"
},
"devDependencies": {
"@types/deep-diff": "^1.0.1",
"@types/prettier": "^2.7.2",
"@types/proj4": "^2.5.2",
"@types/sharp": "^0.31.0"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/cli/github/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export class Github {
*/
commit(message: string): void {
this.logger.info({ repository: this.repo }, 'GitHub: Commit all');
execFileSync('git', ['commit', '-am', JSON.stringify(message)], { cwd: this.repoName })
.toString()
.trim();
execFileSync('git', ['commit', '-am', message], { cwd: this.repoName }).toString().trim();
}

/**
Expand Down
27 changes: 20 additions & 7 deletions packages/cli/src/cli/github/make.cog.pr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ConfigLayer, ConfigTileSetRaster, ConfigTileSetVector } from '@basemaps/config';
import { ConfigLayer, ConfigTileSet, ConfigTileSetRaster, ConfigTileSetVector } from '@basemaps/config';
import { LogType, fsa } from '@basemaps/shared';
import { Category, DefaultCategorySetting } from '../cogify/action.make.cog.pr.js';
import { Github } from './github.js';
import prettier from 'prettier';

export class MakeCogGithub extends Github {
imagery: string;
Expand All @@ -10,6 +11,18 @@ export class MakeCogGithub extends Github {
this.imagery = imagery;
}

async formatConfigFile(targetPath: string, tileSet: ConfigTileSet): Promise<string> {
const cfg = await prettier.resolveConfigFile(targetPath);
if (cfg == null) {
this.logger.error('Prettier:MissingConfig');
return JSON.stringify(tileSet, null, 2);
}
const options = await prettier.resolveConfig(cfg);
this.logger.info({ configPath: cfg, prettierOptions: options }, 'Prettier:Config');
const formatted = prettier.format(JSON.stringify(tileSet), { ...options, parser: 'json' });
return formatted;
}

/**
* Prepare and create pull request for the aerial tileset config
*/
Expand All @@ -23,13 +36,13 @@ export class MakeCogGithub extends Github {

// Prepare new aerial tileset config
this.logger.info({ imagery: this.imagery }, 'GitHub: Get the master TileSet config file');
const path = `${this.repoName}/config/tileset/${filename}.json`;
const tileSet = await fsa.readJson<ConfigTileSetRaster>(path);
const tileSetPath = fsa.joinAll(this.repoName, 'config', 'tileset', `${filename}.json`);
const tileSet = await fsa.readJson<ConfigTileSetRaster>(tileSetPath);
const newTileSet = await this.prepareRasterTileSetConfig(layer, tileSet, category);

// skip pull request if not an urban or rural imagery
if (newTileSet == null) return;
await fsa.write(path, JSON.stringify(newTileSet, null, 2));
await fsa.write(tileSetPath, await this.formatConfigFile(tileSetPath, newTileSet));

// Commit and push the changes
const message = `config(raster): Add imagery ${this.imagery} to ${filename} config file.`;
Expand Down Expand Up @@ -118,13 +131,13 @@ export class MakeCogGithub extends Github {

// Prepare new aerial tileset config
this.logger.info({ imagery: this.imagery }, 'GitHub: Get the master TileSet config file');
const path = `${this.repoName}/config/tileset/${filename}.json`;
const tileSet = await fsa.readJson<ConfigTileSetVector>(path);
const tileSetPath = fsa.joinAll(this.repoName, 'config', 'tileset', `${filename}.json`);
const tileSet = await fsa.readJson<ConfigTileSetVector>(tileSetPath);
const newTileSet = await this.prepareVectorTileSetConfig(layer, tileSet);

// skip pull request if not an urban or rural imagery
if (newTileSet == null) return;
await fsa.write(path, JSON.stringify(newTileSet, null, 2));
await fsa.write(tileSetPath, await this.formatConfigFile(tileSetPath, newTileSet));

// Commit and push the changes
const message = `config(vector): Update the ${this.imagery} to ${filename} config file.`;
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,11 @@
dependencies:
"@types/node" "*"

"@types/prettier@^2.7.2":
version "2.7.2"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.2.tgz#6c2324641cc4ba050a8c710b2b251b377581fbf0"
integrity sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==

"@types/proj4@^2.5.2":
version "2.5.2"
resolved "https://registry.yarnpkg.com/@types/proj4/-/proj4-2.5.2.tgz#e3afa4e09e5cf08d8bc74e1b3de3b2111324ee33"
Expand Down Expand Up @@ -6751,6 +6756,11 @@ prettier@^2.8.2:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.3.tgz#ab697b1d3dd46fb4626fbe2f543afe0cc98d8632"
integrity sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==

prettier@^2.8.8:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==

pretty-json-log@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/pretty-json-log/-/pretty-json-log-1.0.0.tgz#8417783f93a114418dbccdb1302a6a2c0ed38654"
Expand Down

0 comments on commit 76a77ae

Please sign in to comment.