@cerema/cadriciel 1.5.5 → 1.5.7
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/cli/global/upgrade.js +59 -68
- package/package.json +1 -1
package/cli/global/upgrade.js
CHANGED
|
@@ -8,92 +8,74 @@ module.exports = (args) => {
|
|
|
8
8
|
const log = require('log-beautify');
|
|
9
9
|
const sep = path.sep;
|
|
10
10
|
const { nanoid } = require('nanoid');
|
|
11
|
-
const
|
|
11
|
+
const AdmZip = require('adm-zip');
|
|
12
12
|
const UID = nanoid();
|
|
13
13
|
const fse = require('fs-extra');
|
|
14
14
|
const chalk = require('chalk-v2');
|
|
15
|
-
const mkdirp = require('mkdirp');
|
|
15
|
+
const { mkdirp } = require('mkdirp');
|
|
16
|
+
const { exec } = require('child_process');
|
|
16
17
|
|
|
17
18
|
var DEFAULT_TEMPLATE = '';
|
|
18
19
|
const unzipFile = (zipFilePath, outputPath, callback) => {
|
|
19
|
-
|
|
20
|
+
const zip = new AdmZip(zipFilePath);
|
|
21
|
+
try {
|
|
22
|
+
zip.extractAllTo(outputPath, true);
|
|
23
|
+
callback();
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error(
|
|
26
|
+
"Une erreur s'est produite lors de la décompression :",
|
|
27
|
+
err
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function unzip2File(zipPath, outputPath, callback) {
|
|
32
|
+
// Ensure the output directory exists
|
|
33
|
+
if (!fs.existsSync(outputPath)) {
|
|
34
|
+
fs.mkdirSync(outputPath, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Use exec to run the unzip command
|
|
38
|
+
exec(`unzip -o ${zipPath} -d ${outputPath}`, (err, stdout, stderr) => {
|
|
20
39
|
if (err) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
err
|
|
24
|
-
);
|
|
40
|
+
console.error(`Error unzipping file: ${stderr}`);
|
|
41
|
+
return;
|
|
25
42
|
}
|
|
26
43
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const entryPath = path.join(outputPath, entry.fileName);
|
|
31
|
-
|
|
32
|
-
if (/\/$/.test(entry.fileName)) {
|
|
33
|
-
// Directory file names end with '/'.
|
|
34
|
-
mkdirp(entryPath, (err) => {
|
|
35
|
-
if (err) {
|
|
36
|
-
return console.error(
|
|
37
|
-
"Une erreur s'est produite lors de la création du répertoire :",
|
|
38
|
-
err
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
zipfile.readEntry();
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
// Ensure the parent directory exists.
|
|
45
|
-
mkdirp(path.dirname(entryPath), (err) => {
|
|
46
|
-
if (err) {
|
|
47
|
-
return console.error(
|
|
48
|
-
"Une erreur s'est produite lors de la création du répertoire parent :",
|
|
49
|
-
err
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
zipfile.openReadStream(entry, (err, readStream) => {
|
|
54
|
-
if (err) {
|
|
55
|
-
return console.error(
|
|
56
|
-
"Une erreur s'est produite lors de la lecture de l'entrée ZIP :",
|
|
57
|
-
err
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const writeStream = fs.createWriteStream(entryPath);
|
|
62
|
-
|
|
63
|
-
readStream.on('end', () => {
|
|
64
|
-
zipfile.readEntry();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
readStream.pipe(writeStream);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
44
|
+
fs.unlink(zipPath, (unlinkErr) => {
|
|
45
|
+
if (unlinkErr) {
|
|
46
|
+
console.error(`Error deleting zip file: ${unlinkErr}`);
|
|
70
47
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
zipfile.on('end', () => {
|
|
48
|
+
// Call the callback function
|
|
74
49
|
callback();
|
|
75
50
|
});
|
|
76
|
-
|
|
77
|
-
zipfile.on('error', (err) => {
|
|
78
|
-
console.error("Une erreur s'est produite lors de l'extraction :", err);
|
|
79
|
-
});
|
|
80
51
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const download = async (kind, name, cb) => {
|
|
83
55
|
const CadricielAPI = require(path.join('..', '..', 'lib', 'cadriciel'));
|
|
84
56
|
const cadriciel = new CadricielAPI();
|
|
85
57
|
await cadriciel.downloadFile(
|
|
86
58
|
'/template?key=' + name + '.zip',
|
|
87
59
|
`${os.tmpdir()}${sep}${name}.zip`
|
|
88
60
|
);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
61
|
+
if (kind == 'DEVBOX')
|
|
62
|
+
unzip2File(
|
|
63
|
+
`${os.tmpdir()}${sep}${name}.zip`,
|
|
64
|
+
`${os.tmpdir()}${sep}${UID}`,
|
|
65
|
+
() => {
|
|
66
|
+
DEFAULT_TEMPLATE = name;
|
|
67
|
+
fs.unlink(`${os.tmpdir()}${sep}${name}.zip`, cb);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
else
|
|
71
|
+
unzipFile(
|
|
72
|
+
`${os.tmpdir()}${sep}${name}.zip`,
|
|
73
|
+
`${os.tmpdir()}${sep}${UID}`,
|
|
74
|
+
() => {
|
|
75
|
+
DEFAULT_TEMPLATE = name;
|
|
76
|
+
fs.unlink(`${os.tmpdir()}${sep}${name}.zip`, cb);
|
|
77
|
+
}
|
|
78
|
+
);
|
|
97
79
|
};
|
|
98
80
|
async function updateCadriciel(srcDir, destDir) {
|
|
99
81
|
try {
|
|
@@ -152,8 +134,17 @@ module.exports = (args) => {
|
|
|
152
134
|
return;
|
|
153
135
|
}
|
|
154
136
|
}
|
|
137
|
+
try {
|
|
138
|
+
var run = fs.readFileSync(
|
|
139
|
+
path.join(process.cwd(), '.cadriciel', '.store', '.run'),
|
|
140
|
+
'utf-8'
|
|
141
|
+
);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
run = '-';
|
|
144
|
+
}
|
|
145
|
+
|
|
155
146
|
const title = 'cadriciel-' + info.name;
|
|
156
|
-
download(title, async () => {
|
|
147
|
+
download(run, title, async () => {
|
|
157
148
|
spinner.succeed(chalk.bold('Téléchargement OK.'));
|
|
158
149
|
spinner = ora('📥 Application du patch...').start();
|
|
159
150
|
const dir1 = `${os.tmpdir()}${sep}${UID}/§§project§§/.cadriciel`;
|