BREAKING CHANGE(core): Migrate filesystem to smartfs (async) and add Elasticsearch service support; refactor format/commit/meta modules
This commit is contained in:
@@ -48,15 +48,17 @@ 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 = await plugins.smartfs
|
||||
.file(this.filePaths.metaJson)
|
||||
.exists();
|
||||
if (!metaFileExists) {
|
||||
throw new Error(`meta file does not exist at ${this.filePaths.metaJson}`);
|
||||
}
|
||||
this.metaRepoData = plugins.smartfile.fs.toObjectSync(
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
const content = (await plugins.smartfs
|
||||
.file(this.filePaths.metaJson)
|
||||
.encoding('utf8')
|
||||
.read()) as string;
|
||||
this.metaRepoData = JSON.parse(content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,15 +80,15 @@ export class Meta {
|
||||
*/
|
||||
public async writeToDisk() {
|
||||
// write .meta.json to disk
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
JSON.stringify(this.metaRepoData, null, 2),
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
await plugins.smartfs
|
||||
.file(this.filePaths.metaJson)
|
||||
.encoding('utf8')
|
||||
.write(JSON.stringify(this.metaRepoData, null, 2));
|
||||
// write .gitignore to disk
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
await this.generateGitignore(),
|
||||
this.filePaths.gitIgnore,
|
||||
);
|
||||
await plugins.smartfs
|
||||
.file(this.filePaths.gitIgnore)
|
||||
.encoding('utf8')
|
||||
.write(await this.generateGitignore());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,10 +114,25 @@ export class Meta {
|
||||
*/
|
||||
public async updateLocalRepos() {
|
||||
await this.syncToRemote();
|
||||
const projects = plugins.smartfile.fs.toObjectSync(
|
||||
this.filePaths.metaJson,
|
||||
).projects;
|
||||
const preExistingFolders = plugins.smartfile.fs.listFoldersSync(this.cwd);
|
||||
const metaContent = (await plugins.smartfs
|
||||
.file(this.filePaths.metaJson)
|
||||
.encoding('utf8')
|
||||
.read()) as string;
|
||||
const projects = JSON.parse(metaContent).projects;
|
||||
const entries = await plugins.smartfs.directory(this.cwd).list();
|
||||
const preExistingFolders: string[] = [];
|
||||
for (const entry of entries) {
|
||||
try {
|
||||
const stats = await plugins.smartfs
|
||||
.file(plugins.path.join(this.cwd, entry.path))
|
||||
.stat();
|
||||
if (stats.isDirectory) {
|
||||
preExistingFolders.push(entry.name);
|
||||
}
|
||||
} catch {
|
||||
// Skip entries that can't be accessed
|
||||
}
|
||||
}
|
||||
for (const preExistingFolderArg of preExistingFolders) {
|
||||
if (
|
||||
preExistingFolderArg !== '.git' &&
|
||||
@@ -143,9 +160,17 @@ export class Meta {
|
||||
await this.sortMetaRepoData();
|
||||
const missingRepos: string[] = [];
|
||||
for (const key of Object.keys(this.metaRepoData.projects)) {
|
||||
plugins.smartfile.fs.isDirectory(key)
|
||||
? logger.log('ok', `${key} -> is already cloned`)
|
||||
: missingRepos.push(key);
|
||||
const fullPath = plugins.path.join(this.cwd, key);
|
||||
try {
|
||||
const stats = await plugins.smartfs.file(fullPath).stat();
|
||||
if (stats.isDirectory) {
|
||||
logger.log('ok', `${key} -> is already cloned`);
|
||||
} else {
|
||||
missingRepos.push(key);
|
||||
}
|
||||
} catch {
|
||||
missingRepos.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
logger.log('info', `found ${missingRepos.length} missing repos`);
|
||||
@@ -165,7 +190,20 @@ export class Meta {
|
||||
await this.syncToRemote();
|
||||
|
||||
// go recursive
|
||||
const folders = await plugins.smartfile.fs.listFolders(this.cwd);
|
||||
const listEntries = await plugins.smartfs.directory(this.cwd).list();
|
||||
const folders: string[] = [];
|
||||
for (const entry of listEntries) {
|
||||
try {
|
||||
const stats = await plugins.smartfs
|
||||
.file(plugins.path.join(this.cwd, entry.path))
|
||||
.stat();
|
||||
if (stats.isDirectory) {
|
||||
folders.push(entry.name);
|
||||
}
|
||||
} catch {
|
||||
// Skip entries that can't be accessed
|
||||
}
|
||||
}
|
||||
const childMetaRepositories: string[] = [];
|
||||
for (const folder of folders) {
|
||||
logger.log('info', folder);
|
||||
@@ -180,27 +218,31 @@ export class Meta {
|
||||
*/
|
||||
public async initProject() {
|
||||
await this.syncToRemote(true);
|
||||
const fileExists = await plugins.smartfile.fs.fileExists(
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
const fileExists = await plugins.smartfs
|
||||
.file(this.filePaths.metaJson)
|
||||
.exists();
|
||||
if (!fileExists) {
|
||||
await plugins.smartfile.memory.toFs(
|
||||
JSON.stringify({
|
||||
projects: {},
|
||||
}),
|
||||
this.filePaths.metaJson,
|
||||
);
|
||||
await plugins.smartfs
|
||||
.file(this.filePaths.metaJson)
|
||||
.encoding('utf8')
|
||||
.write(
|
||||
JSON.stringify({
|
||||
projects: {},
|
||||
}),
|
||||
);
|
||||
logger.log(
|
||||
`success`,
|
||||
`created a new .meta.json in directory ${this.cwd}`,
|
||||
);
|
||||
await plugins.smartfile.memory.toFs(
|
||||
JSON.stringify({
|
||||
name: this.dirName,
|
||||
version: '1.0.0',
|
||||
}),
|
||||
this.filePaths.packageJson,
|
||||
);
|
||||
await plugins.smartfs
|
||||
.file(this.filePaths.packageJson)
|
||||
.encoding('utf8')
|
||||
.write(
|
||||
JSON.stringify({
|
||||
name: this.dirName,
|
||||
version: '1.0.0',
|
||||
}),
|
||||
);
|
||||
logger.log(
|
||||
`success`,
|
||||
`created a new package.json in directory ${this.cwd}`,
|
||||
@@ -264,9 +306,10 @@ 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.smartfs
|
||||
.directory(plugins.path.join(paths.cwd, projectNameArg))
|
||||
.recursive()
|
||||
.delete();
|
||||
await this.updateLocalRepos();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user