Skip to content

Commit

Permalink
Merge pull request #13 from strapi/chore/script-hosted-demo
Browse files Browse the repository at this point in the history
chore: add hosted demmo script
  • Loading branch information
Mcastres authored Oct 3, 2024
2 parents 058973e + 625d310 commit 02b268a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion strapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"strapi": "strapi",
"deploy": "strapi deploy",
"seed": "strapi import -f ./data/export_20241002155953.tar.gz",
"postinstall": "node ./scripts/updateUuid.ts"
"postinstall": "node ./scripts/updateUuid.js"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
63 changes: 63 additions & 0 deletions strapi/scripts/prefillLoginFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const fs = require("fs");
const path = require("path");
const glob = require("glob");

// Specify the directory path and the pattern to find the file
const directoryPath = "./node_modules/@strapi/admin/dist/admin/";
const filePattern = "index-*.mjs";

// Function to find and replace the specific content in the file
const updateFile = (filePath) => {
// Read the file content
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error(`Error reading file ${filePath}:`, err);
return;
}

// Define the original and replacement content
const originalContent = `initialValues: {
email: "",
password: "",
rememberMe: false
},`;

const newContent = `initialValues: {
email: "[email protected]",
password: "welcomeToStrapi123",
rememberMe: false
},`;

// Check if the content exists and replace it
if (data.includes(originalContent)) {
const updatedData = data.replace(originalContent, newContent);

// Write the updated content back to the file
fs.writeFile(filePath, updatedData, "utf8", (err) => {
if (err) {
console.error(`Error writing to file ${filePath}:`, err);
return;
}
console.log(`Successfully updated the content in file: ${filePath}`);
});
} else {
console.log(`Original content not found in file: ${filePath}`);
}
});
};

// Find the file using glob pattern matching
glob(path.join(directoryPath, filePattern), (err, files) => {
if (err) {
console.error("Error finding files:", err);
return;
}

// Process the first file found (since index-*.mjs may match multiple files)
if (files.length > 0) {
const filePath = files[0];
updateFile(filePath);
} else {
console.log("No matching files found.");
}
});
File renamed without changes.

0 comments on commit 02b268a

Please sign in to comment.