@envsafes-org/cli 0.0.10 → 0.1.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/README.md +117 -251
- package/dist/commands/create.d.ts +1 -0
- package/dist/commands/create.js +84 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +166 -0
- package/dist/commands/link.d.ts +1 -0
- package/dist/commands/link.js +102 -0
- package/dist/commands/list.d.ts +1 -0
- package/dist/commands/list.js +60 -0
- package/dist/commands/pull.d.ts +11 -3
- package/dist/commands/pull.js +20 -4
- package/dist/commands/push.d.ts +11 -3
- package/dist/commands/push.js +20 -4
- package/dist/commands/run.d.ts +11 -3
- package/dist/commands/run.js +50 -17
- package/dist/commands/select.d.ts +1 -0
- package/dist/commands/select.js +63 -0
- package/dist/index.js +52 -16
- package/dist/utils/config.d.ts +44 -0
- package/dist/utils/config.js +90 -0
- package/package.json +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const ora_1 = __importDefault(require("ora"));
|
|
10
|
+
const index_js_1 = require("../index.js");
|
|
11
|
+
const api_js_1 = require("../utils/api.js");
|
|
12
|
+
const config_js_1 = require("../utils/config.js");
|
|
13
|
+
async function init() {
|
|
14
|
+
const token = index_js_1.config.get("token");
|
|
15
|
+
if (!token) {
|
|
16
|
+
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Check if already configured
|
|
20
|
+
const existingConfig = (0, config_js_1.readConfig)();
|
|
21
|
+
if (existingConfig?.project) {
|
|
22
|
+
const { confirm } = await inquirer_1.default.prompt([
|
|
23
|
+
{
|
|
24
|
+
type: "confirm",
|
|
25
|
+
name: "confirm",
|
|
26
|
+
message: `Projet déjà configuré (${existingConfig.project}). Reconfigurer ?`,
|
|
27
|
+
default: false,
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
if (!confirm) {
|
|
31
|
+
console.log(chalk_1.default.yellow("Opération annulée."));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// If no workspace is linked, ask to link first
|
|
36
|
+
if (!existingConfig?.workspace) {
|
|
37
|
+
console.log(chalk_1.default.yellow("⚠ Aucun workspace lié."));
|
|
38
|
+
// Get workspaces
|
|
39
|
+
const spinner = (0, ora_1.default)("Chargement des workspaces...").start();
|
|
40
|
+
try {
|
|
41
|
+
const response = await (0, api_js_1.apiRequest)("/api/v1/workspaces", {
|
|
42
|
+
method: "GET",
|
|
43
|
+
token,
|
|
44
|
+
});
|
|
45
|
+
if (response.error) {
|
|
46
|
+
spinner.fail(chalk_1.default.red(response.error));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (response.workspaces.length === 0) {
|
|
50
|
+
spinner.fail(chalk_1.default.yellow("Aucun workspace trouvé."));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
spinner.stop();
|
|
54
|
+
const { workspace } = await inquirer_1.default.prompt([
|
|
55
|
+
{
|
|
56
|
+
type: "list",
|
|
57
|
+
name: "workspace",
|
|
58
|
+
message: "Sélectionnez un workspace:",
|
|
59
|
+
choices: response.workspaces.map((ws) => ({
|
|
60
|
+
name: `${ws.name} (${ws.slug}) - ${ws.projectCount} projet(s)`,
|
|
61
|
+
value: ws.slug,
|
|
62
|
+
})),
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
65
|
+
// Save workspace
|
|
66
|
+
(0, config_js_1.writeConfig)({ workspace });
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Re-read config after potential workspace selection
|
|
74
|
+
const currentConfig = (0, config_js_1.readConfig)();
|
|
75
|
+
if (!currentConfig?.workspace) {
|
|
76
|
+
console.log(chalk_1.default.red("✗ Workspace non configuré."));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Get projects from workspace
|
|
80
|
+
const spinner = (0, ora_1.default)(`Chargement des projets de "${currentConfig.workspace}"...`).start();
|
|
81
|
+
try {
|
|
82
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/workspaces/${currentConfig.workspace}/projects`, {
|
|
83
|
+
method: "GET",
|
|
84
|
+
token,
|
|
85
|
+
});
|
|
86
|
+
if (response.error) {
|
|
87
|
+
spinner.fail(chalk_1.default.red(response.error));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (response.projects.length === 0) {
|
|
91
|
+
spinner.stop();
|
|
92
|
+
console.log(chalk_1.default.yellow("\nAucun projet trouvé dans ce workspace."));
|
|
93
|
+
const { createNew } = await inquirer_1.default.prompt([
|
|
94
|
+
{
|
|
95
|
+
type: "confirm",
|
|
96
|
+
name: "createNew",
|
|
97
|
+
message: "Voulez-vous créer un nouveau projet ?",
|
|
98
|
+
default: true,
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
101
|
+
if (createNew) {
|
|
102
|
+
const { name, description } = await inquirer_1.default.prompt([
|
|
103
|
+
{
|
|
104
|
+
type: "input",
|
|
105
|
+
name: "name",
|
|
106
|
+
message: "Nom du projet:",
|
|
107
|
+
validate: (input) => input.trim().length > 0 || "Le nom est requis",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: "input",
|
|
111
|
+
name: "description",
|
|
112
|
+
message: "Description (optionnel):",
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
const createSpinner = (0, ora_1.default)("Création du projet...").start();
|
|
116
|
+
const createResponse = await (0, api_js_1.apiRequest)(`/api/v1/workspaces/${currentConfig.workspace}/projects`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
token,
|
|
119
|
+
body: { name: name.trim(), description: description?.trim() || undefined },
|
|
120
|
+
});
|
|
121
|
+
if (createResponse.error) {
|
|
122
|
+
createSpinner.fail(chalk_1.default.red(createResponse.error));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
createSpinner.succeed(chalk_1.default.green(`Projet "${createResponse.project.name}" créé`));
|
|
126
|
+
// Update config with new project
|
|
127
|
+
(0, config_js_1.writeConfig)({
|
|
128
|
+
...currentConfig,
|
|
129
|
+
project: createResponse.project.slug,
|
|
130
|
+
});
|
|
131
|
+
console.log(chalk_1.default.green(`\n✓ Projet "${createResponse.project.slug}" sélectionné`));
|
|
132
|
+
console.log(chalk_1.default.dim(` Configuration sauvegardée dans .envsafe`));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
spinner.stop();
|
|
138
|
+
// Let user select a project
|
|
139
|
+
const { project } = await inquirer_1.default.prompt([
|
|
140
|
+
{
|
|
141
|
+
type: "list",
|
|
142
|
+
name: "project",
|
|
143
|
+
message: "Sélectionnez un projet:",
|
|
144
|
+
choices: response.projects.map((p) => ({
|
|
145
|
+
name: `${p.name} (${p.slug}) - ${p.environments.join(", ")}`,
|
|
146
|
+
value: p.slug,
|
|
147
|
+
})),
|
|
148
|
+
},
|
|
149
|
+
]);
|
|
150
|
+
// Update config
|
|
151
|
+
(0, config_js_1.writeConfig)({
|
|
152
|
+
...currentConfig,
|
|
153
|
+
project,
|
|
154
|
+
});
|
|
155
|
+
console.log(chalk_1.default.green(`\n✓ Projet "${project}" sélectionné`));
|
|
156
|
+
console.log(chalk_1.default.dim(` Configuration sauvegardée dans .envsafe`));
|
|
157
|
+
console.log(chalk_1.default.cyan("\n Commandes disponibles:"));
|
|
158
|
+
console.log(chalk_1.default.dim(" envsafe pull -d - Récupérer les variables (development)"));
|
|
159
|
+
console.log(chalk_1.default.dim(" envsafe pull -s - Récupérer les variables (staging)"));
|
|
160
|
+
console.log(chalk_1.default.dim(" envsafe pull -p - Récupérer les variables (production)"));
|
|
161
|
+
console.log(chalk_1.default.dim(" envsafe push - Envoyer les variables"));
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function link(workspaceSlug?: string): Promise<void>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.link = link;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const ora_1 = __importDefault(require("ora"));
|
|
10
|
+
const index_js_1 = require("../index.js");
|
|
11
|
+
const api_js_1 = require("../utils/api.js");
|
|
12
|
+
const config_js_1 = require("../utils/config.js");
|
|
13
|
+
async function link(workspaceSlug) {
|
|
14
|
+
const token = index_js_1.config.get("token");
|
|
15
|
+
if (!token) {
|
|
16
|
+
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// If config already exists, warn user
|
|
20
|
+
if ((0, config_js_1.configExists)()) {
|
|
21
|
+
const existingConfig = (0, config_js_1.readConfig)();
|
|
22
|
+
const { confirm } = await inquirer_1.default.prompt([
|
|
23
|
+
{
|
|
24
|
+
type: "confirm",
|
|
25
|
+
name: "confirm",
|
|
26
|
+
message: `Un fichier .envsafe existe déjà (workspace: ${existingConfig?.workspace}). Écraser ?`,
|
|
27
|
+
default: false,
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
if (!confirm) {
|
|
31
|
+
console.log(chalk_1.default.yellow("Opération annulée."));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let selectedWorkspace;
|
|
36
|
+
if (workspaceSlug) {
|
|
37
|
+
// Verify workspace exists and user has access
|
|
38
|
+
const spinner = (0, ora_1.default)("Vérification du workspace...").start();
|
|
39
|
+
try {
|
|
40
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/workspaces/${workspaceSlug}`, {
|
|
41
|
+
method: "GET",
|
|
42
|
+
token,
|
|
43
|
+
});
|
|
44
|
+
if (response.error) {
|
|
45
|
+
spinner.fail(chalk_1.default.red(response.error));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
spinner.succeed(chalk_1.default.green(`Workspace "${response.workspace.name}" trouvé`));
|
|
49
|
+
selectedWorkspace = workspaceSlug;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// List workspaces and let user choose
|
|
58
|
+
const spinner = (0, ora_1.default)("Chargement des workspaces...").start();
|
|
59
|
+
try {
|
|
60
|
+
const response = await (0, api_js_1.apiRequest)("/api/v1/workspaces", {
|
|
61
|
+
method: "GET",
|
|
62
|
+
token,
|
|
63
|
+
});
|
|
64
|
+
if (response.error) {
|
|
65
|
+
spinner.fail(chalk_1.default.red(response.error));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (response.workspaces.length === 0) {
|
|
69
|
+
spinner.fail(chalk_1.default.yellow("Aucun workspace trouvé."));
|
|
70
|
+
console.log(chalk_1.default.dim("Créez un workspace sur le dashboard EnvSafe."));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
spinner.stop();
|
|
74
|
+
const { workspace } = await inquirer_1.default.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: "list",
|
|
77
|
+
name: "workspace",
|
|
78
|
+
message: "Sélectionnez un workspace:",
|
|
79
|
+
choices: response.workspaces.map((ws) => ({
|
|
80
|
+
name: `${ws.name} (${ws.slug}) - ${ws.projectCount} projet(s) [${ws.role}]`,
|
|
81
|
+
value: ws.slug,
|
|
82
|
+
})),
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
selectedWorkspace = workspace;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Create .envsafe file
|
|
93
|
+
(0, config_js_1.writeConfig)({
|
|
94
|
+
workspace: selectedWorkspace,
|
|
95
|
+
});
|
|
96
|
+
console.log(chalk_1.default.green(`\n✓ Lié au workspace "${selectedWorkspace}"`));
|
|
97
|
+
console.log(chalk_1.default.dim(` Fichier .envsafe créé dans ${process.cwd()}`));
|
|
98
|
+
console.log(chalk_1.default.cyan("\n Prochaines étapes:"));
|
|
99
|
+
console.log(chalk_1.default.dim(" envsafe list - Voir les projets disponibles"));
|
|
100
|
+
console.log(chalk_1.default.dim(" envsafe select - Sélectionner un projet"));
|
|
101
|
+
console.log(chalk_1.default.dim(" envsafe create - Créer un nouveau projet"));
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function list(): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.list = list;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const index_js_1 = require("../index.js");
|
|
10
|
+
const api_js_1 = require("../utils/api.js");
|
|
11
|
+
const config_js_1 = require("../utils/config.js");
|
|
12
|
+
async function list() {
|
|
13
|
+
const token = index_js_1.config.get("token");
|
|
14
|
+
if (!token) {
|
|
15
|
+
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const localConfig = (0, config_js_1.readConfig)();
|
|
19
|
+
if (!localConfig?.workspace) {
|
|
20
|
+
console.log(chalk_1.default.yellow("⚠ Aucun workspace lié."));
|
|
21
|
+
console.log(chalk_1.default.dim(" Utilisez 'envsafe link <workspace>' ou 'envsafe init' d'abord."));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const spinner = (0, ora_1.default)(`Chargement des projets de "${localConfig.workspace}"...`).start();
|
|
25
|
+
try {
|
|
26
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/workspaces/${localConfig.workspace}/projects`, {
|
|
27
|
+
method: "GET",
|
|
28
|
+
token,
|
|
29
|
+
});
|
|
30
|
+
if (response.error) {
|
|
31
|
+
spinner.fail(chalk_1.default.red(response.error));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
spinner.stop();
|
|
35
|
+
console.log(chalk_1.default.cyan(`\n📁 Projets dans "${response.workspace.name}"\n`));
|
|
36
|
+
if (response.projects.length === 0) {
|
|
37
|
+
console.log(chalk_1.default.dim(" Aucun projet trouvé."));
|
|
38
|
+
console.log(chalk_1.default.dim("\n Créez un projet avec: envsafe create <nom>"));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
for (const project of response.projects) {
|
|
42
|
+
const isSelected = localConfig.project === project.slug;
|
|
43
|
+
const prefix = isSelected ? chalk_1.default.green("● ") : " ";
|
|
44
|
+
const suffix = isSelected ? chalk_1.default.green(" (sélectionné)") : "";
|
|
45
|
+
console.log(`${prefix}${chalk_1.default.bold(project.name)}${suffix}`);
|
|
46
|
+
console.log(chalk_1.default.dim(` slug: ${project.slug}`));
|
|
47
|
+
console.log(chalk_1.default.dim(` envs: ${project.environments.join(", ")}`));
|
|
48
|
+
if (project.description) {
|
|
49
|
+
console.log(chalk_1.default.dim(` desc: ${project.description}`));
|
|
50
|
+
}
|
|
51
|
+
console.log("");
|
|
52
|
+
}
|
|
53
|
+
if (!localConfig.project) {
|
|
54
|
+
console.log(chalk_1.default.dim("Sélectionnez un projet avec: envsafe select <slug>"));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/commands/pull.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
env
|
|
1
|
+
interface PullOptions {
|
|
2
|
+
env?: string;
|
|
3
3
|
output: string;
|
|
4
|
-
|
|
4
|
+
d?: boolean;
|
|
5
|
+
dev?: boolean;
|
|
6
|
+
s?: boolean;
|
|
7
|
+
staging?: boolean;
|
|
8
|
+
p?: boolean;
|
|
9
|
+
prod?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function pull(projectArg: string | undefined, options: PullOptions): Promise<void>;
|
|
12
|
+
export {};
|
package/dist/commands/pull.js
CHANGED
|
@@ -9,15 +9,31 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const index_js_1 = require("../index.js");
|
|
11
11
|
const api_js_1 = require("../utils/api.js");
|
|
12
|
-
|
|
12
|
+
const config_js_1 = require("../utils/config.js");
|
|
13
|
+
async function pull(projectArg, options) {
|
|
13
14
|
const token = index_js_1.config.get("token");
|
|
14
15
|
if (!token) {
|
|
15
16
|
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
// Resolve project from argument or config
|
|
20
|
+
let project = projectArg;
|
|
21
|
+
if (!project) {
|
|
22
|
+
const localConfig = (0, config_js_1.readConfig)();
|
|
23
|
+
if (localConfig?.project) {
|
|
24
|
+
project = localConfig.project;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
console.log(chalk_1.default.red("✗ Aucun projet spécifié."));
|
|
28
|
+
console.log(chalk_1.default.dim(" Usage: envsafe pull <projet> ou configurez avec 'envsafe init'"));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Resolve environment from flags
|
|
33
|
+
const environment = (0, config_js_1.resolveEnvironment)(options);
|
|
34
|
+
const spinner = (0, ora_1.default)(`Téléchargement des variables pour ${project} (${environment})...`).start();
|
|
19
35
|
try {
|
|
20
|
-
const response = await (0, api_js_1.apiRequest)(`/api/v1/projects/${project}/${
|
|
36
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/projects/${project}/${environment}`, {
|
|
21
37
|
method: "GET",
|
|
22
38
|
token,
|
|
23
39
|
});
|
|
@@ -28,7 +44,7 @@ async function pull(project, options) {
|
|
|
28
44
|
if (commonEnvs.includes(project.toLowerCase()) || response.error.includes("trouvé")) {
|
|
29
45
|
console.log(chalk_1.default.yellow("\n💡 Astuce : La syntaxe est 'envsafe pull <MON_PROJET>'"));
|
|
30
46
|
console.log(chalk_1.default.yellow(` Vous avez essayé de pull le projet "${project}".`));
|
|
31
|
-
console.log(chalk_1.default.yellow(` Utilisez 'envsafe
|
|
47
|
+
console.log(chalk_1.default.yellow(` Utilisez 'envsafe list' pour voir la liste de vos projets.`));
|
|
32
48
|
}
|
|
33
49
|
return;
|
|
34
50
|
}
|
package/dist/commands/push.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
env
|
|
1
|
+
interface PushOptions {
|
|
2
|
+
env?: string;
|
|
3
3
|
file: string;
|
|
4
|
-
|
|
4
|
+
d?: boolean;
|
|
5
|
+
dev?: boolean;
|
|
6
|
+
s?: boolean;
|
|
7
|
+
staging?: boolean;
|
|
8
|
+
p?: boolean;
|
|
9
|
+
prod?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function push(projectArg: string | undefined, options: PushOptions): Promise<void>;
|
|
12
|
+
export {};
|
package/dist/commands/push.js
CHANGED
|
@@ -10,23 +10,39 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
11
11
|
const index_js_1 = require("../index.js");
|
|
12
12
|
const api_js_1 = require("../utils/api.js");
|
|
13
|
-
|
|
13
|
+
const config_js_1 = require("../utils/config.js");
|
|
14
|
+
async function push(projectArg, options) {
|
|
14
15
|
const token = index_js_1.config.get("token");
|
|
15
16
|
if (!token) {
|
|
16
17
|
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
20
|
+
// Resolve project from argument or config
|
|
21
|
+
let project = projectArg;
|
|
22
|
+
if (!project) {
|
|
23
|
+
const localConfig = (0, config_js_1.readConfig)();
|
|
24
|
+
if (localConfig?.project) {
|
|
25
|
+
project = localConfig.project;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log(chalk_1.default.red("✗ Aucun projet spécifié."));
|
|
29
|
+
console.log(chalk_1.default.dim(" Usage: envsafe push <projet> ou configurez avec 'envsafe init'"));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
19
33
|
// Check if file exists
|
|
20
34
|
if (!fs_1.default.existsSync(options.file)) {
|
|
21
35
|
console.log(chalk_1.default.red(`✗ Fichier non trouvé: ${options.file}`));
|
|
22
36
|
return;
|
|
23
37
|
}
|
|
24
|
-
|
|
38
|
+
// Resolve environment from flags
|
|
39
|
+
const environment = (0, config_js_1.resolveEnvironment)(options);
|
|
40
|
+
const spinner = (0, ora_1.default)(`Envoi des variables vers ${project} (${environment})...`).start();
|
|
25
41
|
try {
|
|
26
42
|
// Parse .env file
|
|
27
43
|
const envContent = fs_1.default.readFileSync(options.file, "utf-8");
|
|
28
44
|
const parsed = dotenv_1.default.parse(envContent);
|
|
29
|
-
const response = await (0, api_js_1.apiRequest)(`/api/v1/projects/${project}/${
|
|
45
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/projects/${project}/${environment}`, {
|
|
30
46
|
method: "POST",
|
|
31
47
|
token,
|
|
32
48
|
body: { variables: parsed },
|
|
@@ -38,7 +54,7 @@ async function push(project, options) {
|
|
|
38
54
|
if (commonEnvs.includes(project.toLowerCase()) || response.error.includes("trouvé")) {
|
|
39
55
|
console.log(chalk_1.default.yellow("\n💡 Astuce : La syntaxe est 'envsafe push <MON_PROJET>'"));
|
|
40
56
|
console.log(chalk_1.default.yellow(` Vous avez essayé de push vers le projet "${project}".`));
|
|
41
|
-
console.log(chalk_1.default.yellow(` Utilisez 'envsafe
|
|
57
|
+
console.log(chalk_1.default.yellow(` Utilisez 'envsafe list' pour voir la liste de vos projets.`));
|
|
42
58
|
}
|
|
43
59
|
return;
|
|
44
60
|
}
|
package/dist/commands/run.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
env
|
|
3
|
-
|
|
1
|
+
interface RunOptions {
|
|
2
|
+
env?: string;
|
|
3
|
+
d?: boolean;
|
|
4
|
+
dev?: boolean;
|
|
5
|
+
s?: boolean;
|
|
6
|
+
staging?: boolean;
|
|
7
|
+
p?: boolean;
|
|
8
|
+
prod?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function run(projectArg: string | undefined, commandParts: string[], options: RunOptions): Promise<void>;
|
|
11
|
+
export {};
|
package/dist/commands/run.js
CHANGED
|
@@ -8,42 +8,75 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const index_js_1 = require("../index.js");
|
|
10
10
|
const api_js_1 = require("../utils/api.js");
|
|
11
|
-
|
|
11
|
+
const config_js_1 = require("../utils/config.js");
|
|
12
|
+
async function run(projectArg, commandParts, options) {
|
|
12
13
|
const token = index_js_1.config.get("token");
|
|
13
14
|
if (!token) {
|
|
14
15
|
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
15
|
-
|
|
16
|
+
return;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
// Resolve project from argument or config
|
|
19
|
+
let project = projectArg;
|
|
20
|
+
let command = commandParts;
|
|
21
|
+
// If projectArg looks like a command (starts with common command prefixes), use config project
|
|
22
|
+
const commonCommands = ["npm", "yarn", "pnpm", "node", "npx", "python", "go", "cargo", "deno", "bun"];
|
|
23
|
+
if (project && commonCommands.some(cmd => project.startsWith(cmd))) {
|
|
24
|
+
// User didn't specify project, projectArg is actually a command
|
|
25
|
+
const localConfig = (0, config_js_1.readConfig)();
|
|
26
|
+
if (localConfig?.project) {
|
|
27
|
+
command = [project, ...commandParts];
|
|
28
|
+
project = localConfig.project;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
console.log(chalk_1.default.red("✗ Aucun projet configuré."));
|
|
32
|
+
console.log(chalk_1.default.dim(" Usage: envsafe run <projet> <commande> ou configurez avec 'envsafe init'"));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (!project) {
|
|
37
|
+
const localConfig = (0, config_js_1.readConfig)();
|
|
38
|
+
if (localConfig?.project) {
|
|
39
|
+
project = localConfig.project;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(chalk_1.default.red("✗ Aucun projet spécifié."));
|
|
43
|
+
console.log(chalk_1.default.dim(" Usage: envsafe run <projet> <commande> ou configurez avec 'envsafe init'"));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (command.length === 0) {
|
|
48
|
+
console.log(chalk_1.default.red("✗ Commande requise."));
|
|
49
|
+
console.log(chalk_1.default.dim(" Usage: envsafe run [projet] <commande>"));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Resolve environment from flags
|
|
53
|
+
const environment = (0, config_js_1.resolveEnvironment)(options);
|
|
54
|
+
console.log(chalk_1.default.dim(`Chargement des variables pour ${project} (${environment})...`));
|
|
18
55
|
try {
|
|
19
|
-
const response = await (0, api_js_1.apiRequest)(`/api/v1/projects/${project}/${
|
|
56
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/projects/${project}/${environment}`, {
|
|
20
57
|
method: "GET",
|
|
21
58
|
token,
|
|
22
59
|
});
|
|
23
60
|
if (response.error) {
|
|
24
61
|
console.log(chalk_1.default.red(`✗ ${response.error}`));
|
|
25
|
-
|
|
62
|
+
return;
|
|
26
63
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(chalk_1.default.dim(`Exécution: ${command.join(" ")}\n`));
|
|
30
|
-
// Spawn the command with injected env vars
|
|
64
|
+
console.log(chalk_1.default.dim(`${response.count} variable(s) chargée(s)\n`));
|
|
65
|
+
// Spawn the command with environment variables
|
|
31
66
|
const [cmd, ...args] = command;
|
|
32
67
|
const child = (0, child_process_1.spawn)(cmd, args, {
|
|
33
|
-
env: { ...process.env, ...variables },
|
|
34
68
|
stdio: "inherit",
|
|
69
|
+
env: {
|
|
70
|
+
...process.env,
|
|
71
|
+
...response.variables,
|
|
72
|
+
},
|
|
35
73
|
shell: true,
|
|
36
74
|
});
|
|
37
|
-
child.on("
|
|
38
|
-
process.exit(code
|
|
39
|
-
});
|
|
40
|
-
child.on("error", (err) => {
|
|
41
|
-
console.error(chalk_1.default.red(`Erreur d'exécution: ${err.message}`));
|
|
42
|
-
process.exit(1);
|
|
75
|
+
child.on("exit", (code) => {
|
|
76
|
+
process.exit(code || 0);
|
|
43
77
|
});
|
|
44
78
|
}
|
|
45
79
|
catch (error) {
|
|
46
80
|
console.log(chalk_1.default.red(`✗ Erreur: ${error.message}`));
|
|
47
|
-
process.exit(1);
|
|
48
81
|
}
|
|
49
82
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function select(projectSlug?: string): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.select = select;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const index_js_1 = require("../index.js");
|
|
10
|
+
const api_js_1 = require("../utils/api.js");
|
|
11
|
+
const config_js_1 = require("../utils/config.js");
|
|
12
|
+
async function select(projectSlug) {
|
|
13
|
+
const token = index_js_1.config.get("token");
|
|
14
|
+
if (!token) {
|
|
15
|
+
console.log(chalk_1.default.red("✗ Non connecté. Utilisez 'envsafe login' d'abord."));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const localConfig = (0, config_js_1.readConfig)();
|
|
19
|
+
if (!localConfig?.workspace) {
|
|
20
|
+
console.log(chalk_1.default.yellow("⚠ Aucun workspace lié."));
|
|
21
|
+
console.log(chalk_1.default.dim(" Utilisez 'envsafe link <workspace>' d'abord."));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!projectSlug) {
|
|
25
|
+
console.log(chalk_1.default.yellow("⚠ Spécifiez un projet: envsafe select <projet>"));
|
|
26
|
+
console.log(chalk_1.default.dim(" Utilisez 'envsafe list' pour voir les projets disponibles."));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const spinner = (0, ora_1.default)(`Vérification du projet "${projectSlug}"...`).start();
|
|
30
|
+
try {
|
|
31
|
+
// Get projects to verify the slug exists
|
|
32
|
+
const response = await (0, api_js_1.apiRequest)(`/api/v1/workspaces/${localConfig.workspace}/projects`, {
|
|
33
|
+
method: "GET",
|
|
34
|
+
token,
|
|
35
|
+
});
|
|
36
|
+
if (response.error) {
|
|
37
|
+
spinner.fail(chalk_1.default.red(response.error));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const project = response.projects.find((p) => p.slug === projectSlug || p.name.toLowerCase() === projectSlug.toLowerCase());
|
|
41
|
+
if (!project) {
|
|
42
|
+
spinner.fail(chalk_1.default.red(`Projet "${projectSlug}" non trouvé.`));
|
|
43
|
+
console.log(chalk_1.default.dim("\n Projets disponibles:"));
|
|
44
|
+
response.projects.forEach((p) => {
|
|
45
|
+
console.log(chalk_1.default.dim(` - ${p.name} (${p.slug})`));
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Update config
|
|
50
|
+
(0, config_js_1.writeConfig)({
|
|
51
|
+
...localConfig,
|
|
52
|
+
project: project.slug,
|
|
53
|
+
});
|
|
54
|
+
spinner.succeed(chalk_1.default.green(`Projet "${project.name}" (${project.slug}) sélectionné`));
|
|
55
|
+
console.log(chalk_1.default.cyan("\n Commandes disponibles:"));
|
|
56
|
+
console.log(chalk_1.default.dim(" envsafe pull -d - Récupérer les variables (development)"));
|
|
57
|
+
console.log(chalk_1.default.dim(" envsafe pull -s - Récupérer les variables (staging)"));
|
|
58
|
+
console.log(chalk_1.default.dim(" envsafe pull -p - Récupérer les variables (production)"));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
spinner.fail(chalk_1.default.red(`Erreur: ${error.message}`));
|
|
62
|
+
}
|
|
63
|
+
}
|