fix(format): Improve concurrency control in cache and rollback management with mutex locking and refine formatting details
This commit is contained in:
@@ -35,7 +35,10 @@ export class Meta {
|
||||
* sorts the metaRepoData
|
||||
*/
|
||||
public async sortMetaRepoData() {
|
||||
const stringifiedMetadata = plugins.smartjson.stringify(this.metaRepoData, []);
|
||||
const stringifiedMetadata = plugins.smartjson.stringify(
|
||||
this.metaRepoData,
|
||||
[],
|
||||
);
|
||||
this.metaRepoData = plugins.smartjson.parse(stringifiedMetadata);
|
||||
}
|
||||
|
||||
@@ -45,11 +48,15 @@ export class Meta {
|
||||
public async readDirectory() {
|
||||
await this.syncToRemote(true);
|
||||
logger.log('info', `reading directory`);
|
||||
const metaFileExists = plugins.smartfile.fs.fileExistsSync(this.filePaths.metaJson);
|
||||
const metaFileExists = plugins.smartfile.fs.fileExistsSync(
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
if (!metaFileExists) {
|
||||
throw new Error(`meta file does not exist at ${this.filePaths.metaJson}`);
|
||||
}
|
||||
this.metaRepoData = plugins.smartfile.fs.toObjectSync(this.filePaths.metaJson);
|
||||
this.metaRepoData = plugins.smartfile.fs.toObjectSync(
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +83,10 @@ export class Meta {
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
// write .gitignore to disk
|
||||
plugins.smartfile.memory.toFsSync(await this.generateGitignore(), this.filePaths.gitIgnore);
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
await this.generateGitignore(),
|
||||
this.filePaths.gitIgnore,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,13 +94,17 @@ export class Meta {
|
||||
*/
|
||||
public async syncToRemote(gitCleanArg = false) {
|
||||
logger.log('info', `syncing from origin master`);
|
||||
await this.smartshellInstance.exec(`cd ${this.cwd} && git pull origin master`);
|
||||
await this.smartshellInstance.exec(
|
||||
`cd ${this.cwd} && git pull origin master`,
|
||||
);
|
||||
if (gitCleanArg) {
|
||||
logger.log('info', `cleaning the repository from old directories`);
|
||||
await this.smartshellInstance.exec(`cd ${this.cwd} && git clean -fd`);
|
||||
}
|
||||
logger.log('info', `syncing to remote origin master`);
|
||||
await this.smartshellInstance.exec(`cd ${this.cwd} && git push origin master`);
|
||||
await this.smartshellInstance.exec(
|
||||
`cd ${this.cwd} && git push origin master`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +112,9 @@ export class Meta {
|
||||
*/
|
||||
public async updateLocalRepos() {
|
||||
await this.syncToRemote();
|
||||
const projects = plugins.smartfile.fs.toObjectSync(this.filePaths.metaJson).projects;
|
||||
const projects = plugins.smartfile.fs.toObjectSync(
|
||||
this.filePaths.metaJson,
|
||||
).projects;
|
||||
const preExistingFolders = plugins.smartfile.fs.listFoldersSync(this.cwd);
|
||||
for (const preExistingFolderArg of preExistingFolders) {
|
||||
if (
|
||||
@@ -107,14 +123,18 @@ export class Meta {
|
||||
projectFolder.startsWith(preExistingFolderArg),
|
||||
)
|
||||
) {
|
||||
const response = await plugins.smartinteraction.SmartInteract.getCliConfirmation(
|
||||
`Do you want to delete superfluous directory >>${preExistingFolderArg}<< ?`,
|
||||
true,
|
||||
);
|
||||
const response =
|
||||
await plugins.smartinteraction.SmartInteract.getCliConfirmation(
|
||||
`Do you want to delete superfluous directory >>${preExistingFolderArg}<< ?`,
|
||||
true,
|
||||
);
|
||||
if (response) {
|
||||
logger.log('warn', `Deleting >>${preExistingFolderArg}<<!`);
|
||||
} else {
|
||||
logger.log('warn', `Not deleting ${preExistingFolderArg} by request!`);
|
||||
logger.log(
|
||||
'warn',
|
||||
`Not deleting ${preExistingFolderArg} by request!`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +180,9 @@ export class Meta {
|
||||
*/
|
||||
public async initProject() {
|
||||
await this.syncToRemote(true);
|
||||
const fileExists = await plugins.smartfile.fs.fileExists(this.filePaths.metaJson);
|
||||
const fileExists = await plugins.smartfile.fs.fileExists(
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
if (!fileExists) {
|
||||
await plugins.smartfile.memory.toFs(
|
||||
JSON.stringify({
|
||||
@@ -168,7 +190,10 @@ export class Meta {
|
||||
}),
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
logger.log(`success`, `created a new .meta.json in directory ${this.cwd}`);
|
||||
logger.log(
|
||||
`success`,
|
||||
`created a new .meta.json in directory ${this.cwd}`,
|
||||
);
|
||||
await plugins.smartfile.memory.toFs(
|
||||
JSON.stringify({
|
||||
name: this.dirName,
|
||||
@@ -176,9 +201,15 @@ export class Meta {
|
||||
}),
|
||||
this.filePaths.packageJson,
|
||||
);
|
||||
logger.log(`success`, `created a new package.json in directory ${this.cwd}`);
|
||||
logger.log(
|
||||
`success`,
|
||||
`created a new package.json in directory ${this.cwd}`,
|
||||
);
|
||||
} else {
|
||||
logger.log(`error`, `directory ${this.cwd} already has a .metaJson file. Doing nothing.`);
|
||||
logger.log(
|
||||
`error`,
|
||||
`directory ${this.cwd} already has a .metaJson file. Doing nothing.`,
|
||||
);
|
||||
}
|
||||
await this.smartshellInstance.exec(
|
||||
`cd ${this.cwd} && git add -A && git commit -m "feat(project): init meta project for ${this.dirName}"`,
|
||||
@@ -195,7 +226,9 @@ export class Meta {
|
||||
const existingProject = this.metaRepoData.projects[projectNameArg];
|
||||
|
||||
if (existingProject) {
|
||||
throw new Error('Project already exists! Please remove it first before adding it again.');
|
||||
throw new Error(
|
||||
'Project already exists! Please remove it first before adding it again.',
|
||||
);
|
||||
}
|
||||
|
||||
this.metaRepoData.projects[projectNameArg] = gitUrlArg;
|
||||
@@ -217,7 +250,10 @@ export class Meta {
|
||||
const existingProject = this.metaRepoData.projects[projectNameArg];
|
||||
|
||||
if (!existingProject) {
|
||||
logger.log('error', `Project ${projectNameArg} does not exist! So it cannot be removed`);
|
||||
logger.log(
|
||||
'error',
|
||||
`Project ${projectNameArg} does not exist! So it cannot be removed`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -228,7 +264,9 @@ export class Meta {
|
||||
await this.writeToDisk();
|
||||
|
||||
logger.log('info', 'removing directory from cwd');
|
||||
await plugins.smartfile.fs.remove(plugins.path.join(paths.cwd, projectNameArg));
|
||||
await plugins.smartfile.fs.remove(
|
||||
plugins.path.join(paths.cwd, projectNameArg),
|
||||
);
|
||||
await this.updateLocalRepos();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user