Skip to content

Commit

Permalink
Add a partial deployment capability
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanlucut committed Aug 9, 2023
1 parent fe27a56 commit 8251edd
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 201 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TZ=Europe/Bucharest
SOURCE_DIR=../bes-lyrics/verified
OUT_DIR=./pp7-songs
3 changes: 2 additions & 1 deletion .env.remote
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TZ=Europe/Bucharest
SOURCE_DIR=../bes-lyrics/verified
OUT_DIR=/Users/ilucut/WORK/BES/CLOUD DATA/ProPresenter_Generated/ProPresenter_Generated_Version_10
OUT_DIR=/Users/ilucut/WORK/BES/CLOUD DATA/ProPresenter_Generated
5 changes: 0 additions & 5 deletions .run/Run migrator.run.xml

This file was deleted.

5 changes: 5 additions & 0 deletions .run/[Local] Run migrator.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="[Local] Run migrator" type="NodeJSConfigurationType" node-parameters="--require ts-node/register" path-to-js-file="runner.ts" working-dir="$PROJECT_DIR$">
<method v="2" />
</configuration>
</component>
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ const CONFIG = {

migrateSongsToPP7Format({
sourceDir: process.env.SOURCE_DIR as string,
outDir: process.env.OUT_DIR as string,
clearOutputDirFirst: true,
baseOutDir: process.env.OUT_DIR as string,
config: CONFIG,
});
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.ts",
"scripts": {
"test:ci": "NODE_ENV=test jest --runInBand --no-cache",
"test:watch": "NODE_ENV=test TZ='Europe/Berlin' jest --watch --logHeapUsage",
"test:watch": "NODE_ENV=test TZ='Europe/Bucharest' jest --watch --logHeapUsage",
"test": "is-ci-cli test:ci test:watch",
"migrate:local": "ts-node runner.ts",
"migrate:remote": "dotenv -e .env.remote ts-node runner.ts"
Expand Down
3 changes: 1 addition & 2 deletions runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const CONFIG = {
(async () => {
await migrateSongsToPP7Format({
sourceDir: process.env.SOURCE_DIR as string,
outDir: process.env.OUT_DIR as string,
clearOutputDirFirst: true,
baseOutDir: process.env.OUT_DIR as string,
config: CONFIG,
});
})();
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const SLASH = '/';

export const HASH = '#';

export const DASH = '-';

export const TXT_EXTENSION = '.txt';

export const TEST_FILE = 'TEMPLATE.txt';
Expand Down
41 changes: 41 additions & 0 deletions src/core.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {
parseDateFromVersionedDir,
getMetaSectionsFromTitle,
getSongInSectionTuples,
getTitleWithoutMeta,
getVersionedDir,
getClosestVersionedDir,
} from './core';
import { SIMPLE_SONG_MOCK_FILE_CONTENT } from '../mocks';

jest
.useFakeTimers()
.setSystemTime(new Date('2023-02-19T11:12:13.000Z').getTime());

describe('core', () => {
describe('getSongInSectionTuples', () => {
it('should work correctly', () => {
Expand Down Expand Up @@ -74,4 +81,38 @@ describe('core', () => {
`);
});
});

describe('getClosestVersionedDir', () => {
it('should work correctly', () => {
expect(getVersionedDir()).toMatchInlineSnapshot(`"2023-02-19-12:12:13"`);
});
});

describe('parseDateFromVersionedDir', () => {
it('should work correctly', () => {
expect(
parseDateFromVersionedDir('2023-02-19-11:12:13'),
).toMatchInlineSnapshot(`2023-02-19T10:12:13.000Z`);

expect(
parseDateFromVersionedDir('2023-08-08-19:17:25'),
).toMatchInlineSnapshot(`2023-08-08T17:17:25.000Z`);
});
});

describe('getClosestVersionedDir', () => {
it('should work correctly', () => {
expect(
getClosestVersionedDir(
parseDateFromVersionedDir('2023-26-20-11:12:13'),
[
parseDateFromVersionedDir('2023-02-20-11:12:13'),
parseDateFromVersionedDir('2023-02-19-11:12:13'),
parseDateFromVersionedDir('2023-02-23-11:12:13'),
parseDateFromVersionedDir('2023-02-24-11:12:13'),
],
),
).toMatchInlineSnapshot(`2023-02-24T10:12:13.000Z`);
});
});
});
42 changes: 33 additions & 9 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SequenceChar, SongMeta } from './types';
import {
COLON,
COMMA,
DASH,
DOUBLE_LINE_TUPLE,
EMPTY_STRING,
HASH,
Expand Down Expand Up @@ -130,18 +131,41 @@ ${tuples
export const convertSequenceToNumber = (sequenceOrderQualifier: string) =>
parseInt(sequenceOrderQualifier) || MISSING_SEQUENCE_NUMBER;

export const getTodayAsDateString = () => {
const now = new Date();

return (
('0' + now.getDate()).slice(-2) +
'-' +
('0' + (now.getMonth() + 1)).slice(-2) +
'-' +
now.getFullYear()
export const getVersionedDir = (now = new Date()) =>
now.getFullYear() +
DASH +
('0' + (now.getMonth() + 1)).slice(-2) +
DASH +
('0' + now.getDate()).slice(-2) +
DASH +
('0' + now.getHours()).slice(-2) +
COLON +
('0' + now.getMinutes()).slice(-2) +
COLON +
('0' + now.getSeconds()).slice(-2);

export const parseDateFromVersionedDir = (versionFolder: string) => {
const [year, month, day, time] = versionFolder.split(DASH);
const [hour, minute, second] = time.split(COLON);

return new Date(
parseInt(year),
parseInt(month) - 1,
parseInt(day),
parseInt(hour),
parseInt(minute),
parseInt(second),
);
};

export const getClosestVersionedDir = (diffDate: Date, dates: Date[]) =>
first(
dates.sort((a, b) => {
// @ts-ignore
return Math.abs(diffDate - a) - Math.abs(diffDate - b); // sort a before b when the distance is smaller
}),
);

export const assertUniqueness = (array: string[]) =>
assert.equal(
size(uniq(array)),
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './inventorySnapshotRunner';
export * from './migratorRunner';
export * from './proPresenter7SongConverter';
export * from './songsParser';
Expand Down
141 changes: 0 additions & 141 deletions src/inventorySnapshotRunner.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/manifestGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dotenv from 'dotenv';
import { assertUniqueness } from './core';
import { Song, SongManifest } from './types';

dotenv.config();

export const generateManifest = async (
deployableSongs: Array<{
song: Song;
fileName: string;
fileAsText: string;
}>,
) => {
assertUniqueness(deployableSongs.map(({ song }) => song.id));

return deployableSongs
.map(
({ song: { id, contentHash }, fileName }) =>
({
id,
fileName,
contentHash,
} as SongManifest),
)
.sort((a, b) => a.fileName.localeCompare(b.fileName));
};
Loading

0 comments on commit 8251edd

Please sign in to comment.