aeria-populate 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +30 -36
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -131,11 +131,37 @@ export const main = async () => {
|
|
|
131
131
|
throw new Error();
|
|
132
132
|
}
|
|
133
133
|
const files = await Array.fromAsync(fs.promises.glob(pattern));
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
let failed = 0, successful = 0, dropped = 0;
|
|
135
|
+
const collections = [];
|
|
136
|
+
for (const file of files) {
|
|
137
|
+
const content = await fs.promises.readFile(file, {
|
|
138
|
+
encoding: 'utf-8',
|
|
139
|
+
});
|
|
140
|
+
const { frontmatter } = await parseMarkdown(content);
|
|
141
|
+
collections.push(frontmatter.collection);
|
|
142
|
+
}
|
|
143
|
+
if (opts.dropCollections) {
|
|
144
|
+
for (const collection of collections) {
|
|
145
|
+
if ((await db.listCollections().toArray()).some((subject) => collection === subject.name)) {
|
|
146
|
+
await db.collection(collection).deleteMany();
|
|
147
|
+
console.log(styleText(['green'], '✓'), 'dropped collection', styleText(['bold'], collection));
|
|
148
|
+
dropped++;
|
|
149
|
+
}
|
|
138
150
|
}
|
|
151
|
+
}
|
|
152
|
+
for (const file of files) {
|
|
153
|
+
const result = await visitFile(file);
|
|
154
|
+
failed += result.failed;
|
|
155
|
+
successful += result.successful;
|
|
156
|
+
}
|
|
157
|
+
console.log(dropped, 'dropped collections:', collections.map((collection) => styleText(['bold'], collection)).join(', '));
|
|
158
|
+
console.log(successful, 'documents imported successfully');
|
|
159
|
+
console.log(failed, 'failed to import');
|
|
160
|
+
if (failed) {
|
|
161
|
+
await client.close();
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
if (opts.watch) {
|
|
139
165
|
const watcher = chokidar.watch(files);
|
|
140
166
|
console.log('watching for changes in ', styleText(['bold'], pattern));
|
|
141
167
|
watcher.on('change', async (filePath) => {
|
|
@@ -143,37 +169,5 @@ export const main = async () => {
|
|
|
143
169
|
await visitFile(filePath);
|
|
144
170
|
});
|
|
145
171
|
}
|
|
146
|
-
else {
|
|
147
|
-
let failed = 0, successful = 0, dropped = 0;
|
|
148
|
-
const collections = [];
|
|
149
|
-
for (const file of files) {
|
|
150
|
-
const content = await fs.promises.readFile(file, {
|
|
151
|
-
encoding: 'utf-8',
|
|
152
|
-
});
|
|
153
|
-
const { frontmatter } = await parseMarkdown(content);
|
|
154
|
-
collections.push(frontmatter.collection);
|
|
155
|
-
}
|
|
156
|
-
if (opts.dropCollections) {
|
|
157
|
-
for (const collection of collections) {
|
|
158
|
-
if ((await db.listCollections().toArray()).some((subject) => collection === subject.name)) {
|
|
159
|
-
await db.collection(collection).drop();
|
|
160
|
-
console.log(styleText(['green'], '✓'), 'dropped collection', styleText(['bold'], collection));
|
|
161
|
-
dropped++;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
for (const file of files) {
|
|
166
|
-
const result = await visitFile(file);
|
|
167
|
-
failed += result.failed;
|
|
168
|
-
successful += result.successful;
|
|
169
|
-
}
|
|
170
|
-
console.log(dropped, 'dropped collections:', collections.map((collection) => styleText(['bold'], collection)).join(', '));
|
|
171
|
-
console.log(successful, 'documents imported successfully');
|
|
172
|
-
console.log(failed, 'failed to import');
|
|
173
|
-
if (failed) {
|
|
174
|
-
await client.close();
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
172
|
await client.close();
|
|
179
173
|
};
|