@kopynator/cli 1.0.0
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/index.d.ts +1 -0
- package/dist/index.js +133 -0
- package/package.json +38 -0
- package/src/commands/check.ts +43 -0
- package/src/commands/init.ts +51 -0
- package/src/commands/sync.ts +10 -0
- package/src/index.ts +35 -0
- package/tsconfig.json +17 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_commander = require("commander");
|
|
28
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
29
|
+
|
|
30
|
+
// src/commands/init.ts
|
|
31
|
+
var import_inquirer = __toESM(require("inquirer"));
|
|
32
|
+
var import_chalk = __toESM(require("chalk"));
|
|
33
|
+
var import_fs = __toESM(require("fs"));
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
async function initCommand() {
|
|
36
|
+
console.log(import_chalk.default.bold.blue("\n\u{1F680} Initializing Kopynator...\n"));
|
|
37
|
+
const answers = await import_inquirer.default.prompt([
|
|
38
|
+
{
|
|
39
|
+
type: "list",
|
|
40
|
+
name: "framework",
|
|
41
|
+
message: "What framework are you using?",
|
|
42
|
+
choices: ["Angular", "React", "Vue", "Other"]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "input",
|
|
46
|
+
name: "defaultLocale",
|
|
47
|
+
message: "What is your default locale?",
|
|
48
|
+
default: "en"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "checkbox",
|
|
52
|
+
name: "languages",
|
|
53
|
+
message: "Select supported languages:",
|
|
54
|
+
choices: ["en", "es", "fr", "de", "it", "pt"],
|
|
55
|
+
default: ["en", "es"]
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
console.log(import_chalk.default.green(`
|
|
59
|
+
\u2705 Setting up for ${answers.framework}...`));
|
|
60
|
+
const configContent = {
|
|
61
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
62
|
+
defaultLocale: answers.defaultLocale,
|
|
63
|
+
languages: answers.languages,
|
|
64
|
+
mode: "local"
|
|
65
|
+
};
|
|
66
|
+
import_fs.default.writeFileSync(
|
|
67
|
+
import_path.default.join(process.cwd(), "kopynator.config.json"),
|
|
68
|
+
JSON.stringify(configContent, null, 2)
|
|
69
|
+
);
|
|
70
|
+
console.log(import_chalk.default.green("\u2705 Created kopynator.config.json"));
|
|
71
|
+
console.log(import_chalk.default.yellow("\nNext steps:"));
|
|
72
|
+
console.log("1. Get your API Key from https://www.kopynator.com");
|
|
73
|
+
console.log("2. Update your kopynator.config.json");
|
|
74
|
+
console.log("3. Run `npx kopynator check` to validate your files.\n");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/commands/check.ts
|
|
78
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
79
|
+
var import_fs2 = __toESM(require("fs"));
|
|
80
|
+
var import_path2 = __toESM(require("path"));
|
|
81
|
+
async function checkCommand() {
|
|
82
|
+
console.log(import_chalk2.default.bold.blue("\n\u{1F50D} Validating JSON translation files...\n"));
|
|
83
|
+
const assetsDir = import_path2.default.join(process.cwd(), "src/assets/i18n");
|
|
84
|
+
if (!import_fs2.default.existsSync(assetsDir)) {
|
|
85
|
+
console.log(import_chalk2.default.red(`\u274C Could not find directory: ${assetsDir}`));
|
|
86
|
+
console.log(import_chalk2.default.yellow("Make sure you are running this from your project root."));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const files = import_fs2.default.readdirSync(assetsDir).filter((f) => f.endsWith(".json"));
|
|
90
|
+
if (files.length === 0) {
|
|
91
|
+
console.log(import_chalk2.default.yellow("\u26A0\uFE0F No JSON files found in assets/i18n."));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
let hasErrors = false;
|
|
95
|
+
files.forEach((file) => {
|
|
96
|
+
try {
|
|
97
|
+
const content = import_fs2.default.readFileSync(import_path2.default.join(assetsDir, file), "utf-8");
|
|
98
|
+
JSON.parse(content);
|
|
99
|
+
console.log(import_chalk2.default.green(`\u2713 ${file} is valid JSON.`));
|
|
100
|
+
} catch (e) {
|
|
101
|
+
hasErrors = true;
|
|
102
|
+
console.log(import_chalk2.default.red(`\u274C ${file} has syntax errors:`));
|
|
103
|
+
console.log(import_chalk2.default.red(` ${e.message}`));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (hasErrors) {
|
|
107
|
+
console.log(import_chalk2.default.red("\n\u{1F4A5} Validation failed. Please fix the errors above."));
|
|
108
|
+
process.exit(1);
|
|
109
|
+
} else {
|
|
110
|
+
console.log(import_chalk2.default.bold.green("\n\u2728 All files are valid! You are ready to go."));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/commands/sync.ts
|
|
115
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
116
|
+
async function syncCommand() {
|
|
117
|
+
console.log(import_chalk3.default.bold.blue("\n\u2601\uFE0F Syncing with Kopynator Cloud...\n"));
|
|
118
|
+
console.log(import_chalk3.default.yellow("\u{1F512} This feature is available in the Starter and Growth plans."));
|
|
119
|
+
console.log(import_chalk3.default.white("Upgrade your plan at https://www.kopynator.com/pricing to enable cloud synchronization."));
|
|
120
|
+
console.log(import_chalk3.default.gray("\n(In a real implementation, this would push local keys and pull remote translations)"));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/index.ts
|
|
124
|
+
var program = new import_commander.Command();
|
|
125
|
+
program.name("kopynator").description("Kopynator CLI - Manage your i18n workflow").version("1.0.0");
|
|
126
|
+
program.command("init").description("Initialize Kopynator in your project").action(initCommand);
|
|
127
|
+
program.command("check").description("Validate your local JSON translation files").action(checkCommand);
|
|
128
|
+
program.command("sync").description("Sync your translations with the Kopynator Cloud").action(syncCommand);
|
|
129
|
+
program.parse(process.argv);
|
|
130
|
+
if (!process.argv.slice(2).length) {
|
|
131
|
+
console.log(import_chalk4.default.blue("\u{1F44B} Welcome to Kopynator CLI!"));
|
|
132
|
+
program.outputHelp();
|
|
133
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kopynator/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool for Kopynator - The i18n management solution",
|
|
5
|
+
"bin": {
|
|
6
|
+
"kopynator": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup src/index.ts --format cjs --dts --clean",
|
|
11
|
+
"dev": "tsup src/index.ts --format cjs --dts --watch",
|
|
12
|
+
"release:patch": "npm version patch",
|
|
13
|
+
"release:minor": "npm version minor",
|
|
14
|
+
"release:major": "npm version major"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"i18n",
|
|
18
|
+
"cli",
|
|
19
|
+
"kopynator",
|
|
20
|
+
"localization"
|
|
21
|
+
],
|
|
22
|
+
"author": "Carlos Florio",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"chalk": "^4.1.2",
|
|
26
|
+
"commander": "^11.1.0",
|
|
27
|
+
"inquirer": "^8.2.6"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/inquirer": "^9.0.7",
|
|
31
|
+
"@types/node": "^20.10.0",
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"typescript": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export async function checkCommand() {
|
|
6
|
+
console.log(chalk.bold.blue('\n🔍 Validating JSON translation files...\n'));
|
|
7
|
+
|
|
8
|
+
const assetsDir = path.join(process.cwd(), 'src/assets/i18n'); // Default angular structural assumption for demo
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(assetsDir)) {
|
|
11
|
+
console.log(chalk.red(`❌ Could not find directory: ${assetsDir}`));
|
|
12
|
+
console.log(chalk.yellow('Make sure you are running this from your project root.'));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const files = fs.readdirSync(assetsDir).filter(f => f.endsWith('.json'));
|
|
17
|
+
|
|
18
|
+
if (files.length === 0) {
|
|
19
|
+
console.log(chalk.yellow('⚠️ No JSON files found in assets/i18n.'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let hasErrors = false;
|
|
24
|
+
|
|
25
|
+
files.forEach(file => {
|
|
26
|
+
try {
|
|
27
|
+
const content = fs.readFileSync(path.join(assetsDir, file), 'utf-8');
|
|
28
|
+
JSON.parse(content);
|
|
29
|
+
console.log(chalk.green(`✓ ${file} is valid JSON.`));
|
|
30
|
+
} catch (e: any) {
|
|
31
|
+
hasErrors = true;
|
|
32
|
+
console.log(chalk.red(`❌ ${file} has syntax errors:`));
|
|
33
|
+
console.log(chalk.red(` ${e.message}`));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (hasErrors) {
|
|
38
|
+
console.log(chalk.red('\n💥 Validation failed. Please fix the errors above.'));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
} else {
|
|
41
|
+
console.log(chalk.bold.green('\n✨ All files are valid! You are ready to go.'));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
export async function initCommand() {
|
|
7
|
+
console.log(chalk.bold.blue('\n🚀 Initializing Kopynator...\n'));
|
|
8
|
+
|
|
9
|
+
const answers = await inquirer.prompt([
|
|
10
|
+
{
|
|
11
|
+
type: 'list',
|
|
12
|
+
name: 'framework',
|
|
13
|
+
message: 'What framework are you using?',
|
|
14
|
+
choices: ['Angular', 'React', 'Vue', 'Other']
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: 'input',
|
|
18
|
+
name: 'defaultLocale',
|
|
19
|
+
message: 'What is your default locale?',
|
|
20
|
+
default: 'en'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'checkbox',
|
|
24
|
+
name: 'languages',
|
|
25
|
+
message: 'Select supported languages:',
|
|
26
|
+
choices: ['en', 'es', 'fr', 'de', 'it', 'pt'],
|
|
27
|
+
default: ['en', 'es']
|
|
28
|
+
}
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
console.log(chalk.green(`\n✅ Setting up for ${answers.framework}...`));
|
|
32
|
+
|
|
33
|
+
// Creates a basic config file
|
|
34
|
+
const configContent = {
|
|
35
|
+
apiKey: "YOUR_API_KEY_HERE",
|
|
36
|
+
defaultLocale: answers.defaultLocale,
|
|
37
|
+
languages: answers.languages,
|
|
38
|
+
mode: "local"
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
fs.writeFileSync(
|
|
42
|
+
path.join(process.cwd(), 'kopynator.config.json'),
|
|
43
|
+
JSON.stringify(configContent, null, 2)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
console.log(chalk.green('✅ Created kopynator.config.json'));
|
|
47
|
+
console.log(chalk.yellow('\nNext steps:'));
|
|
48
|
+
console.log('1. Get your API Key from https://www.kopynator.com');
|
|
49
|
+
console.log('2. Update your kopynator.config.json');
|
|
50
|
+
console.log('3. Run `npx kopynator check` to validate your files.\n');
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
export async function syncCommand() {
|
|
4
|
+
console.log(chalk.bold.blue('\n☁️ Syncing with Kopynator Cloud...\n'));
|
|
5
|
+
|
|
6
|
+
// Placeholder for paid/backend feature
|
|
7
|
+
console.log(chalk.yellow('🔒 This feature is available in the Starter and Growth plans.'));
|
|
8
|
+
console.log(chalk.white('Upgrade your plan at https://www.kopynator.com/pricing to enable cloud synchronization.'));
|
|
9
|
+
console.log(chalk.gray('\n(In a real implementation, this would push local keys and pull remote translations)'));
|
|
10
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { initCommand } from './commands/init';
|
|
5
|
+
import { checkCommand } from './commands/check';
|
|
6
|
+
import { syncCommand } from './commands/sync';
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name('kopynator')
|
|
12
|
+
.description('Kopynator CLI - Manage your i18n workflow')
|
|
13
|
+
.version('1.0.0');
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.command('init')
|
|
17
|
+
.description('Initialize Kopynator in your project')
|
|
18
|
+
.action(initCommand);
|
|
19
|
+
|
|
20
|
+
program
|
|
21
|
+
.command('check')
|
|
22
|
+
.description('Validate your local JSON translation files')
|
|
23
|
+
.action(checkCommand);
|
|
24
|
+
|
|
25
|
+
program
|
|
26
|
+
.command('sync')
|
|
27
|
+
.description('Sync your translations with the Kopynator Cloud')
|
|
28
|
+
.action(syncCommand);
|
|
29
|
+
|
|
30
|
+
program.parse(process.argv);
|
|
31
|
+
|
|
32
|
+
if (!process.argv.slice(2).length) {
|
|
33
|
+
console.log(chalk.blue('👋 Welcome to Kopynator CLI!'));
|
|
34
|
+
program.outputHelp();
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"],
|
|
16
|
+
"exclude": ["node_modules", "dist"]
|
|
17
|
+
}
|