Skip to content

Commit

Permalink
fix(algolia): import version from file
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Sep 9, 2020
1 parent e276c5e commit d880d8a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
3 changes: 1 addition & 2 deletions packages/autocomplete-preset-algolia/src/results.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { version } from '../package.json';

import { flatten } from './utils';
import { version } from './version';

type SearchClient = any;
export type Client = any;
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete-preset-algolia/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = '1.0.0-alpha.28';
49 changes: 32 additions & 17 deletions ship.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-commonjs */

const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

Expand All @@ -19,18 +20,6 @@ module.exports = {
return `yarn publish --access public --tag ${tag}`;
},
versionUpdated({ exec, dir, version }) {
const updatePackageDependencies = (...changes) => {
for (const change of changes) {
const { package, dependencies } = change;

exec(
`yarn workspace ${package} add ${dependencies
.map((dep) => `"${dep}"`)
.join(' ')}`
);
}
};

// Ship.js reads JSON and writes with `fs.writeFileSync(JSON.stringify(json, null, 2))`
// which causes a lint error in the `lerna.json` file.
exec('yarn eslint lerna.json --fix');
Expand All @@ -42,11 +31,19 @@ module.exports = {
`@algolia/autocomplete-preset-algolia@^${version}`,
],
});

fs.writeFileSync(
path.resolve(dir, 'packages', 'autocomplete-core', 'src', 'version.ts'),
`export const version = '${version}';\n`
);
updatePackagesVersion({
version,
files: [
path.resolve(dir, 'packages', 'autocomplete-core', 'src', 'version.ts'),
path.resolve(
dir,
'packages',
'autocomplete-preset-algolia',
'src',
'version.ts'
),
],
});
},
// Skip preparation if it contains only `chore` commits
shouldPrepare: ({ releaseType, commitNumbersPerType }) => {
Expand All @@ -59,3 +56,21 @@ module.exports = {
return true;
},
};

function updatePackageDependencies(...changes) {
for (const change of changes) {
const { package, dependencies } = change;

execSync(
`yarn workspace ${package} add ${dependencies
.map((dep) => `"${dep}"`)
.join(' ')}`
);
}
}

function updatePackagesVersion({ version, files }) {
for (const file of files) {
fs.writeFileSync(file, `export const version = '${version}';\n`);
}
}

0 comments on commit d880d8a

Please sign in to comment.