Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions examples/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ module.exports = function(grunt) {
});
await migrations.migrate({ journal, logger });

// Todo - {
// display changes success/failure and request user confirmation before completing
// move saving of content outside of the language loop
// only 1 confirmation per course rather than 1 per language
// output journal entries for revert
// }

// group all content items by path
const outputFilePathItems = _.groupBy(content, '__path__');
// sort items inside each path
Expand All @@ -136,7 +129,6 @@ module.exports = function(grunt) {
const stripped = isSingleObject
? undressPathIndex(outputItems[0]) // config.json, course.json
: outputItems.map(undressPathIndex); // contentObjects.json, articles.json, blocks.json, components.json
// console.log(journal.entries)
fs.writeJSONSync(outputPath, stripped, { replacer: null, spaces: 2 });
});
}
Expand Down
31 changes: 31 additions & 0 deletions npm_hooks/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs/promises';
import path from 'path';

const destinationPath = path.resolve('./../../grunt/tasks/migration.js');
const sourcePath = path.resolve('./examples/migrations.js');

async function checkFileExists () {
try {
await fs.access(destinationPath);
return true;
} catch (error) {
return false;
}
}

async function copyMigrationFile () {
try {
const destinationDir = path.dirname(destinationPath);
await fs.mkdir(destinationDir, { recursive: true });

// Copy the file
await fs.copyFile(sourcePath, destinationPath);
console.log(`File copied successfully to: ${destinationPath}`);
} catch (error) {
console.error('Error copying file:', error.message);
}
}

if (!await checkFileExists()) {
await copyMigrationFile();
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"type": "module",
"main": "index.js",
"version": "1.2.0",
"scripts": {
"postinstall": "node npm_hooks/postinstall.js"
},
"devDependencies": {
"eslint": "^8.42.0",
"eslint-config-standard": "^17.1.0",
Expand Down