Commit fe5e0ce2 authored by Rolf Forst's avatar Rolf Forst
Browse files

Fix directories to rename

parent 7ae2636b
......@@ -9,43 +9,43 @@ const replace = require('replace-in-file');
const packageJson = require('./package.json');
let projectType = 'plugin',
directoryName = '';
directoryName = '';
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('<projektart> <projektverzeichnis>')
.usage(`${chalk.green( '<projektart> <projektverzeichnis>' )} [options]`)
.action((type, name) => {
projectType = type.toLowerCase();
directoryName = name.toLowerCase();
})
.allowUnknownOption()
.parse(process.argv);
.version(packageJson.version)
.arguments('<projektart> <projektverzeichnis>')
.usage(`${chalk.green( '<projektart> <projektverzeichnis>' )} [options]`)
.action((type, name) => {
projectType = type.toLowerCase();
directoryName = name.toLowerCase();
})
.allowUnknownOption()
.parse(process.argv);
if ('undefined' === typeof projectType || undefined === packageJson.rrze.repos[projectType]) {
console.error('Bitte die Art des zu erstellenden Projekts angeben:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<projektart> <projektverzeichnis>')}`);
console.log(" Gültige Projektarten sind 'plugin' und 'theme'.");
console.log();
console.log('Beispielsweise:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('plugin rrze-projekt')}`);
console.log();
process.exit(1);
console.error('Bitte die Art des zu erstellenden Projekts angeben:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<projektart> <projektverzeichnis>')}`);
console.log(" Gültige Projektarten sind 'plugin' und 'theme'.");
console.log();
console.log('Beispielsweise:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('plugin rrze-projekt')}`);
console.log();
process.exit(1);
}
if ('undefined' === typeof directoryName || '' === directoryName) {
console.error('Bitte das Projektverzeichnis angeben:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<projektverzeichnis>')}`);
console.log();
console.log('Beispielsweise:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('rrze-projekt')}`);
console.log();
process.exit(1);
console.error('Bitte das Projektverzeichnis angeben:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<projektverzeichnis>')}`);
console.log();
console.log('Beispielsweise:');
console.log(` ${chalk.cyan(program.name())} ${chalk.green('rrze-projekt')}`);
console.log();
process.exit(1);
}
var sanitize,
sanitize2;
sanitize2;
sanitize = directoryName.replace(/-/g, ' ');
sanitize2 = sanitize.replace(/^([\w\-]+)/g, str => str.toUpperCase());
const pluginName = sanitize2.replace(/([\w\-]+)$/g, str => str[0].toUpperCase() + str.slice(1));
......@@ -58,11 +58,11 @@ const textDomain = directoryName.toLowerCase();
// Liste der Dateien, die entfernt werden müssen.
const filesToRemove = [
'README.md',
'languages/cms-basis-de_DE_formal.mo',
'languages/cms-basis-de_DE_formal.po',
'languages/cms-basis-de_DE.mo',
'languages/cms-basis-de_DE.po'
'README.md',
'languages/cms-basis-de_DE_formal.mo',
'languages/cms-basis-de_DE_formal.po',
'languages/cms-basis-de_DE.mo',
'languages/cms-basis-de_DE.po'
];
// Liste der Verzeichnisse, die entfernt werden müssen.
......@@ -70,96 +70,96 @@ const directoriesToRemove = ['.git'];
// Suchen und ersetzen.
const textToReplace = [{
from: /CMS Basis/g,
to: pluginName
},
{
from: /CMS\\Basis/g,
to: nameSpace
},
{
from: /cms-basis/g,
to: textDomain
}
from: /CMS Basis/g,
to: pluginName
},
{
from: /CMS\\Basis/g,
to: nameSpace
},
{
from: /cms-basis/g,
to: textDomain
}
];
// Verzeichnisse umbenennen.
const directoriesToRename = [{
from: 'cms-basis',
to: directoryName
},
{
from: 'languages/cms-basis.pot',
to: 'languages/' + directoryName + '.pot'
}
from: 'cms-basis.php',
to: directoryName + '.php'
},
{
from: 'languages/cms-basis.pot',
to: 'languages/' + directoryName + '.pot'
}
];
// Überprüfen, ob das Verzeichnis bereits vorhanden ist.
if (fs.existsSync('./' + directoryName)) {
console.log(chalk.yellow.bold('😱Aaahh!!! ') + 'Verzeichnis "' + directoryName + '" existiert bereits!');
process.exit(1);
console.log(chalk.yellow.bold('😱 Aaahh!!! ') + 'Verzeichnis "' + directoryName + '" existiert bereits!');
process.exit(1);
}
/**
* Das Git-repository klonen.
*/
clone(packageJson.rrze.repos[projectType], './' + directoryName,
function(err) {
if (err) {
console.log(err);
} else {
console.log(chalk.green('😎 Verzeichnis ' + directoryName + ' erfolgreich erstellt.'));
// Dateien entfernen.
if (filesToRemove.length) {
filesToRemove.forEach(function(file) {
if (fs.existsSync(directoryName + '/' + file)) {
deleteFile(directoryName, file, function() {
console.log(chalk.green(`Datei ${file} gelöscht.`));
});
}
});
}
// Verzeichnisse entfernen.
if (directoriesToRemove.length) {
directoriesToRemove.forEach(function(dir) {
if (fs.existsSync(directoryName + '/' + dir)) {
deleteDirectory(directoryName + '/' + dir, function() {
console.log(chalk.green(`Verzeichnis ${dir} gelöscht.`));
});
}
});
}
// Suchen und ersetzen.
textToReplace.forEach(function(text) {
try {
const changes = replace.sync({
files: directoryName + '/**/*.*',
from: text.from,
to: text.to,
encoding: 'utf8',
});
} catch (error) {
console.error('Fehler: ', error);
}
});
// Verzeichnisse umbenennen.
directoriesToRename.forEach(function(dir) {
if (fs.existsSync(directoryName + '/' + dir.from)) {
fs.rename(directoryName + '/' + dir.from, directoryName + '/' + dir.to, function(err) {
if (err) throw err;
console.log(chalk.green('Verzeichnis ' + dir.from + ' umbennant.'));
});
}
});
}
}
function(err) {
if (err) {
console.log(err);
} else {
console.log(chalk.green('😎 Verzeichnis ' + directoryName + ' erfolgreich erstellt.'));
// Dateien entfernen.
if (filesToRemove.length) {
filesToRemove.forEach(function(file) {
if (fs.existsSync(directoryName + '/' + file)) {
deleteFile(directoryName, file, function() {
console.log(chalk.green(`Datei ${file} gelöscht.`));
});
}
});
}
// Verzeichnisse entfernen.
if (directoriesToRemove.length) {
directoriesToRemove.forEach(function(dir) {
if (fs.existsSync(directoryName + '/' + dir)) {
deleteDirectory(directoryName + '/' + dir, function() {
console.log(chalk.green(`Verzeichnis ${dir} gelöscht.`));
});
}
});
}
// Suchen und ersetzen.
textToReplace.forEach(function(text) {
try {
const changes = replace.sync({
files: directoryName + '/**/*.*',
from: text.from,
to: text.to,
encoding: 'utf8',
});
} catch (error) {
console.error('Fehler: ', error);
}
});
// Verzeichnisse umbenennen.
directoriesToRename.forEach(function(dir) {
if (fs.existsSync(directoryName + '/' + dir.from)) {
fs.rename(directoryName + '/' + dir.from, directoryName + '/' + dir.to, function(err) {
if (err) throw err;
console.log(chalk.green('Verzeichnis ' + dir.from + ' umbennant.'));
});
}
});
}
}
);
/**
......@@ -167,29 +167,29 @@ clone(packageJson.rrze.repos[projectType], './' + directoryName,
*/
function deleteFile(dir, file, cb) {
return new Promise(function(resolve, reject) {
var filePath = path.join(dir, file);
fs.lstat(filePath, function(err, stats) {
if (err) {
return reject(err);
}
if (stats.isDirectory()) {
resolve(deleteDirectory(filePath));
} else {
fs.unlink(filePath, function(err) {
if (err) {
return reject(err);
}
resolve();
});
}
});
if ('function' === typeof cb) {
cb.call(this);
}
});
return new Promise(function(resolve, reject) {
var filePath = path.join(dir, file);
fs.lstat(filePath, function(err, stats) {
if (err) {
return reject(err);
}
if (stats.isDirectory()) {
resolve(deleteDirectory(filePath));
} else {
fs.unlink(filePath, function(err) {
if (err) {
return reject(err);
}
resolve();
});
}
});
if ('function' === typeof cb) {
cb.call(this);
}
});
}
......@@ -198,32 +198,32 @@ function deleteFile(dir, file, cb) {
*/
function deleteDirectory(dir, cb) {
return new Promise(function(resolve, reject) {
fs.access(dir, function(err) {
if (err) {
return reject(err);
}
fs.readdir(dir, function(err, files) {
if (err) {
return reject(err);
}
Promise.all(files.map(function(file) {
return deleteFile(dir, file);
})).then(function() {
fs.rmdir(dir, function(err) {
if (err) {
return reject(err);
}
resolve();
});
}).catch(reject);
});
});
if ('function' === typeof cb) {
cb.call(this);
}
});
};
return new Promise(function(resolve, reject) {
fs.access(dir, function(err) {
if (err) {
return reject(err);
}
fs.readdir(dir, function(err, files) {
if (err) {
return reject(err);
}
Promise.all(files.map(function(file) {
return deleteFile(dir, file);
})).then(function() {
fs.rmdir(dir, function(err) {
if (err) {
return reject(err);
}
resolve();
});
}).catch(reject);
});
});
if ('function' === typeof cb) {
cb.call(this);
}
});
};
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment