Skip to content

Commit

Permalink
Refactor code to exclude unnecessary deployments and create directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanlucut committed Sep 25, 2023
1 parent 61eb07c commit 924ce86
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ export const EMPTY_SPACE = ' ';
export const PRO_EXTENSION = `.pro`;

export const MANIFEST_FILE_NAME = 'manifest.json';

export const DS_STORE_FILE = '.DS_Store';
11 changes: 8 additions & 3 deletions src/converterService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import fs from 'fs';
import path from 'path';
import { isEqual } from 'lodash';
import recursive from 'recursive-readdir';
import { Presentation } from '../proto/presentation';
import {
Config,
convertSongToProPresenter7,
} from './proPresenter7SongConverter';
import { MANIFEST_FILE_NAME, PRO_EXTENSION, TXT_EXTENSION } from './constants';
import {
DS_STORE_FILE,
MANIFEST_FILE_NAME,
PRO_EXTENSION,
TXT_EXTENSION,
} from './constants';
import {
getClosestVersionedDir,
getVersionedDir,
Expand All @@ -18,7 +24,6 @@ import {
SongManifest,
SongsInventoryManifest,
} from './types';
import recursive from 'recursive-readdir';
import { parseSong } from './songsParser';
import { generateManifest } from './manifestGenerator';

Expand Down Expand Up @@ -116,7 +121,7 @@ export const getSongDiffFromManifest = (
};

export const getDeployableSongs = async (sourceDir: string) =>
(await recursive(sourceDir, ['.DS_Store'])).map((filePath) => {
(await recursive(sourceDir, [DS_STORE_FILE])).map((filePath) => {
const fileAsText = fs.readFileSync(filePath).toString();
const fileName = path.basename(filePath);
const song = parseSong(fileAsText);
Expand Down
28 changes: 11 additions & 17 deletions src/localConverterRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import fs from 'fs';
import fsExtra from 'fs-extra';
import path from 'path';
import assert from 'node:assert';
import { isEmpty } from 'lodash';
import { isEmpty, isEqual, negate } from 'lodash';
import { Config } from './proPresenter7SongConverter';
import { MANIFEST_FILE_NAME } from './constants';
import { DS_STORE_FILE, MANIFEST_FILE_NAME } from './constants';
import {
logFileWithLinkInConsole,
logProcessingFile,
Expand Down Expand Up @@ -54,16 +54,17 @@ export const convertSongsToPP7FormatLocally = async ({
baseLocalDir,
config,
}: {
sourceDir: string;
baseLocalDir: string;
config: Config;
sourceDir: string;
}) => {
const {
currentManifest,
deployableSongs,
deploymentDate,
deploymentVersionedDir,
deployableSongs,
currentManifest,
localManifestFilePath,
versionedDir,
} = await getBasicDeploymentInfo(sourceDir, baseLocalDir);

assert(
Expand All @@ -75,24 +76,17 @@ export const convertSongsToPP7FormatLocally = async ({
// Create directory
fsExtra.ensureDirSync(deploymentVersionedDir);

if (process.env.FORCE_RELEASE_OF_ALL_SONGS === 'true') {
console.log(`Just debug.`);

getConvertedAndWrittenToLocalOutDirSongs(
deployableSongs,
deploymentVersionedDir,
config,
);

return;
}

fs.writeFileSync(localManifestFilePath, JSON.stringify(currentManifest));

// ---
// Existing deployments
const allPreviousDeploymentDirs = fsExtra
.readdirSync(baseLocalDir)
.filter(
(deploymentDir) =>
negate(isEqual)(deploymentDir, DS_STORE_FILE) &&
negate(isEqual)(deploymentDir, versionedDir),
)
.map((deploymentDir) => ({
deploymentDir,
deploymentDirDate: parseDateFromVersionedDir(deploymentDir),
Expand Down

0 comments on commit 924ce86

Please sign in to comment.