Socket
Socket
Sign inDemoInstall

@talend/i18n-scripts

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@talend/i18n-scripts - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

150

generators/mvn/pom.generator.js

@@ -9,3 +9,3 @@ const fs = require('fs');

const pomTemplate = template(
const rootPomTemplate = template(
`<?xml version="1.0" encoding="UTF-8"?>

@@ -17,5 +17,5 @@ <project xmlns="http://maven.apache.org/POM/4.0.0"

<groupId>org.talend.locales</groupId>
<artifactId><%= projectName %></artifactId>
<version><%= nextVersion %></version>
<groupId><%= groupId %></groupId>
<artifactId><%= artifactId %></artifactId>
<version><%= version %></version>

@@ -29,10 +29,55 @@ <distributionManagement>

</project>
`,
);
`);
const parentPomTemplate = template(
`<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId><%= groupId %></groupId>
<artifactId><%= artifactId %></artifactId>
<version><%= version %></version>
<modules>
<% modules.forEach(function(module) { %><module><%- module %></module><% }); %>
</modules>
<distributionManagement>
<repository>
<id><%= repository.id %></id>
<url><%= repository.url %></url>
</repository>
</distributionManagement>
</project>
`);
const childPomTemplate = template(
`<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId><%= parentGroupId %></groupId>
<artifactId><%= parentArtifactId %></artifactId>
<version><%= version %></version>
</parent>
<artifactId><%= artifactId %></artifactId>
</project>
`);
/**
* Increment last version in pom.xml
*/
function getNextVersion(pomXmlPath) {
const { version } = getXmlAsJson(pomXmlPath).project;
function getNextVersion(options) {
const rootPomPath = path.join(options.localesRepoPath, 'pom.xml');
if (!fs.existsSync(rootPomPath)) {
return `${options.version}.0`;
}
const { version } = getXmlAsJson(rootPomPath).project;
return incrementVersion(version);

@@ -42,2 +87,59 @@ }

/**
* Get modules definitions.
* Modules are found via src folders.
*
* - unique module : we only specify a root module
* - multiple modules : we specify each modules, and add a parent pom specification
*/
function getModules(options) {
const BASE_GROUP_ID = 'org.talend.locales';
const PARENT_GROUP_ID = `${BASE_GROUP_ID}.${options.normalizedName}`;
const PARENT_ARTIFACT_ID = options.normalizedName;
const nextVersion = getNextVersion(options);
// find all src folders, that indicates the path of each maven modules
const srcFolders = fsFind(options.localesRepoPath, 'd', 'src');
// specify each module info
let hasChildModule = false;
const modules = srcFolders.map(srcPath => {
const modulePath = path.dirname(srcPath);
const isRootModule = modulePath === options.localesRepoPath;
if (isRootModule) {
return {
path: modulePath,
groupId: BASE_GROUP_ID,
artifactId: options.normalizedName,
version: nextVersion,
isRoot: true,
};
}
hasChildModule = true;
return {
path: modulePath,
parentGroupId: PARENT_GROUP_ID,
parentArtifactId: PARENT_ARTIFACT_ID,
artifactId: path.basename(modulePath),
version: nextVersion,
};
});
// 2 cases :
// - only 1 module at root folder, only 1 pom will be generated
// - at least 1 module in a subdirectory : each module is a submodule. We will generate 1 pom per submodule, and we need to add a parent pom
if (hasChildModule) {
modules.push({
path: options.localesRepoPath,
groupId: PARENT_GROUP_ID,
artifactId: PARENT_ARTIFACT_ID,
version: nextVersion,
isParent: true,
});
}
return modules;
}
/**
* Generate pom.xml.

@@ -47,18 +149,20 @@ * If it exists, the version is incremented

function generatePomXml(options) {
const srcFolders = fsFind(options.localesRepoPath, 'd', 'src');
const modules = getModules(options);
srcFolders.forEach(srcPath => {
const parentPath = path.dirname(srcPath);
const projectName =
parentPath === options.localesRepoPath ? options.normalizedName : path.basename(parentPath);
const pomXmlPath = path.join(parentPath, 'pom.xml');
const nextVersion = fs.existsSync(pomXmlPath)
? getNextVersion(pomXmlPath)
: `${options.version}.0`;
printRunning(`Generating pom.xml for project ${projectName}`);
const pomXml = pomTemplate({ ...options, nextVersion, projectName });
fs.writeFileSync(pomXmlPath, pomXml);
printSuccess(`Pom.xml saved to ${pomXmlPath}`);
modules.forEach(module => {
const pomPath = path.join(module.path, 'pom.xml');
let pomXml;
if (module.isParent) {
printRunning(`Generating parent pom ${module.artifactId}`);
const childModules = modules.filter(mod => !mod.isParent).map(mod => mod.artifactId);
pomXml = parentPomTemplate({...options, ...module, modules: childModules});
} else if (module.isRoot) {
printRunning(`Generating pom for unique module ${module.artifactId}`);
pomXml = rootPomTemplate({ ...options.repository, ...module });
} else {
printRunning(`Generating pom for child module ${module.artifactId}`);
pomXml = childPomTemplate({ ...options.repository, ...module });
}
fs.writeFileSync(pomPath, pomXml);
printSuccess(`Pom.xml saved to ${pomPath}`);
});

@@ -65,0 +169,0 @@ }

2

package.json
{
"name": "@talend/i18n-scripts",
"description": "Set of scripts to ease i18n workflow",
"version": "0.1.2",
"version": "0.2.0",
"license": "Apache-2.0",

@@ -6,0 +6,0 @@ "main": "index.js",

@@ -118,4 +118,4 @@ # Talend i18n scripts

| method | `expression` |
| rootPath | The folder to start the search. |
| expression | Expression describing the files name. You can use `*` as wildcard. `message*.json` means every files that start with `message` and end with `.json` (ex: message-errors.json, message.json, ...), whereas `message.json` matches only the `message.json` files. |
| rootPath | The folder to start the search.<br /><br/>Note that `mvnModules` is a special value, that will get the folders from pom.xml modules definition. |
| expression | Expression describing the files name.<br /><br />It accepts glob format, you can use `*` as wildcard. `message*.json` means every files that start with `message` and end with `.json` (ex: message-errors.json, message.json, ...), whereas `message.json` matches only the `message.json` files. |
| target | The folder where the script will gather the translation files. This is used to create the zip file. Note that the files folder hierarchy is preserved. |

@@ -122,0 +122,0 @@

@@ -12,2 +12,3 @@ const fs = require('fs');

const { getVersion } = require('../common/version');
const { getXmlAsJson } = require('../common/files');

@@ -20,3 +21,3 @@ /**

function listFiles(path) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
find.file(path, resolve)

@@ -32,3 +33,3 @@ });

function listDirs(path) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
find.dir(path, resolve)

@@ -93,4 +94,55 @@ });

function extractByExpression({ expression, rootPath, target }) {
const child = spawn.sync('find', [rootPath, '-iname', `${expression}`]);
function getMvnChildModulesFolders({ expression, target }) {
const pomXmlPath = path.join(process.cwd(), 'pom.xml');
if (!fs.existsSync(pomXmlPath)) {
error(`
You used mvnModules to extract from modules folders, but no pom.xml was found in project root.
{
"extract": {
"method": "expression",
"root": "mvnModules",
"expression": "${expression}",
"target": "${target}"
}
}
`);
}
const { modules } = getXmlAsJson(pomXmlPath).project;
if (!modules) {
error(`
You used mvnModules to extract from modules folders, but your pom.xml does not contain any <modules> definition.
talend-i18n.json
{
"extract": {
"method": "expression",
"root": "mvnModules",
"expression": "${expression}",
"target": "${target}"
}
}
pom.xml
<project>
<modules>
<module>folder1</module>
<module>folder2</module>
</modules>
</project>
`);
}
return modules.module;
}
function extractByExpression(options) {
const { expression, rootPath, target } = options;
let searchFolders;
if (rootPath === 'mvnModules') {
searchFolders = [].concat(getMvnChildModulesFolders(options));
} else {
searchFolders = [rootPath];
}
const child = spawn.sync('find', [...searchFolders, '-iname', `${expression}`]);
if (child.status !== 0) {

@@ -103,3 +155,3 @@ error(child.stderr.toString());

.split('\n')
.filter(filePath => filePath);
.filter(Boolean);
if (!files.length) {

@@ -106,0 +158,0 @@ error(`No file matches the expression "${expression}" from ${rootPath}`);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc