-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmanager.js
129 lines (106 loc) · 4.72 KB
/
manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//--------------------------------------------------------
//-- Manager
//--------------------------------------------------------
"use strict";
/* eslint-disable node/no-unpublished-require */
const fss = require("@absolunet/fss");
const fsp = require("@absolunet/fsp");
const manager = require("@absolunet/manager");
const ROOT = ".";
const PACKAGES = `${ROOT}/packages`;
const CLI_BINARY = `${PACKAGES}/cli/bin/nwayo`;
const BOILER = `${PACKAGES}/grow-project/boilerplate`;
const EXTENSION_BOILER = `${PACKAGES}/grow-extension/boilerplate`;
const TOOLBOX = `${PACKAGES}/toolbox`;
const WORKFLOW = `${PACKAGES}/workflow`;
const DOCUMENTATION_BUILDER = `${ROOT}/ressources/docs-builder`;
const BOILER_PACKAGE = `${BOILER}/package.json`;
const BOILER_VENDOR = `${BOILER}/vendor`;
const BOILER_VENDOR_PACKAGE = `${BOILER_VENDOR}/package.json`;
const BOILER_INDEX = `${BOILER}/SAMPLE-HTML/index.html`;
manager.multiScriptsRunner({
tasks: {
postinstall: {
postRun: async ({ terminal }) => {
// Install grow-project boilerplate from current workflow
terminal.print("Install static current version of workflow to grow-project boilerplate").spacer();
await terminal.runPromise(`npm pack ${WORKFLOW} --pack-destination=${ROOT}`);
const [workflowPackage] = await fsp.scandir(ROOT, "file", {
fullPath: true,
pattern: "absolunet-nwayo-workflow-*.tgz",
});
terminal.print("npm install").spacer();
await terminal.runPromise(`cd ${BOILER}; npm install ${workflowPackage} --save=false`);
await fsp.remove(workflowPackage);
// Install grow-project boilerplate toolbox from current toolbox
terminal.print("Install static current version of toolbox to grow-project boilerplate").spacer();
await terminal.runPromise(`npm pack ${TOOLBOX} --pack-destination=${ROOT}`);
const [toolboxPackage] = await fsp.scandir(ROOT, "file", {
fullPath: true,
pattern: "absolunet-nwayo-toolbox-*.tgz",
});
terminal.print("npm install").spacer();
await terminal.runPromise(`cd ${BOILER_VENDOR}; npm install ${toolboxPackage} --save=false`);
await fsp.remove(toolboxPackage);
await manager.installPackage(BOILER_VENDOR);
// Install grow-extension boilerplate
await manager.installPackage(EXTENSION_BOILER);
// Install documentation builder
await manager.installPackage(DOCUMENTATION_BUILDER);
// Make sure CLI binary is executable
await terminal.runPromise(`chmod +x ${CLI_BINARY}`);
},
},
outdated: {
postRun: async () => {
// Check grow-project boilerplate vendors / grow-extension boilerplate / documentation
for (const path of [BOILER_VENDOR, EXTENSION_BOILER, DOCUMENTATION_BUILDER]) {
await manager.testOutdated(path); // eslint-disable-line no-await-in-loop
}
},
},
build: {
postRun: async ({ terminal }) => {
//-- Version bump
terminal.print(`Version bump: grow-project boilerplate 'package.json'`).spacer();
const boilerPackage = await fsp.readJson(BOILER_PACKAGE);
boilerPackage.dependencies["@absolunet/nwayo-workflow"] = manager.version;
await fsp.writeJson(BOILER_PACKAGE, boilerPackage, { space: 2 });
terminal.print(`Version bump: grow-project boilerplate vendor 'package.json'`).spacer();
const boilerVendor = await fsp.readJson(BOILER_VENDOR_PACKAGE);
boilerVendor.dependencies["@absolunet/nwayo-toolbox"] = manager.version;
await fsp.writeJson(BOILER_VENDOR_PACKAGE, boilerVendor, { space: 2 });
terminal.print(`Version bump: grow-project boilerplate 'SAMPLE-HTML/index.html'`).spacer();
const boilerIndex = await fsp.readFile(BOILER_INDEX, "utf8");
await fsp.writeFile(
BOILER_INDEX,
boilerIndex.replace(
/nwayo (v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?)/gu, // eslint-disable-line prefer-named-capture-group
`nwayo ${manager.version}`
)
);
//-- Update grow-extension
await manager.updatePackageMeta(EXTENSION_BOILER);
//-- Counter old manager
const packages = await fsp.scandir(PACKAGES, "dir", {
fullPath: true,
pattern: "*",
});
packages.shift();
packages.push(EXTENSION_BOILER);
packages.forEach((directory) => {
const content = fss.readJson(`${directory}/package.json`);
content.engines.node = ">= 14.17.0";
fss.writeJson(`${directory}/package.json`, content, { space: 2 });
});
//-- grow-project boilerplate 'nwayo rebuild'
terminal.print(`grow-project boilerplate 'nwayo rebuild'`).spacer();
terminal.run(`cd ${BOILER} && ../../cli/bin/nwayo rebuild`);
terminal.spacer();
//-- Documentation rebuild
terminal.print(`Documentation rebuild`).spacer();
terminal.run(`cd ${DOCUMENTATION_BUILDER} && npm run build`);
},
},
},
});