nibula 1.6.0 → 1.6.2
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/.eleventy.js +82 -81
- package/CHANGELOG.md +395 -377
- package/LICENSE +169 -169
- package/NOTICE +4 -4
- package/README.md +110 -110
- package/bin/create.js +540 -505
- package/bin/delegate.js +58 -57
- package/bin/nibula.js +302 -302
- package/docs/Assistant CLI.md +65 -65
- package/docs/Backend.md +201 -201
- package/docs/Components.md +140 -140
- package/docs/Creating pages.md +69 -69
- package/docs/Deploy.md +210 -210
- package/docs/Head and SEO.md +139 -139
- package/docs/Javascript.md +126 -126
- package/docs/Styling with SCSS.md +141 -139
- package/nginx.conf +113 -113
- package/package.json +69 -69
- package/src/backend/.htaccess +6 -6
- package/src/backend/_core/composer.json +5 -5
- package/src/backend/_core/composer.lock +492 -492
- package/src/backend/_core/index.js +267 -267
- package/src/backend/_core/index.php +160 -160
- package/src/backend/_core/init.js +52 -52
- package/src/backend/_core/init.php +33 -33
- package/src/backend/_core/modules/RateLimiter.js +58 -58
- package/src/backend/_core/modules/RateLimiter.php +30 -30
- package/src/backend/_core/modules/Response.js +59 -59
- package/src/backend/_core/modules/Response.php +48 -48
- package/src/backend/api/protected/example-protected.js +23 -23
- package/src/backend/api/protected/example-protected.php +16 -16
- package/src/backend/api/public/example-public.js +24 -24
- package/src/backend/api/public/example-public.php +16 -16
- package/src/backend/database/Database.js +46 -46
- package/src/backend/database/Database.php +23 -23
- package/src/backend/example.config.js +37 -37
- package/src/backend/example.config.php +37 -37
- package/src/backend/package.json +17 -17
- package/src/backend/web.config +43 -43
- package/src/frontend/.htaccess +51 -51
- package/src/frontend/404.njk +17 -17
- package/src/frontend/assets/brand/favicon.svg +54 -54
- package/src/frontend/assets/brand/logo.svg +54 -54
- package/src/frontend/components/global/footer.njk +25 -25
- package/src/frontend/components/global/header.njk +6 -6
- package/src/frontend/components/welcome.njk +115 -115
- package/src/frontend/index.njk +8 -8
- package/src/frontend/js/global.js +10 -10
- package/src/frontend/js/modules/exampleModule.js +2 -2
- package/src/frontend/js/pages/404.js +8 -8
- package/src/frontend/js/pages/homepage.js +8 -8
- package/src/frontend/layouts/base.njk +135 -136
- package/src/frontend/layouts/page-components.njk +13 -13
- package/src/frontend/llms.njk +17 -17
- package/src/frontend/robots.njk +7 -7
- package/src/frontend/scss/_global.scss +46 -46
- package/src/frontend/scss/_root.scss +13 -13
- package/src/frontend/scss/modules/_animations.scss +24 -24
- package/src/frontend/scss/modules/_footer.scss +28 -28
- package/src/frontend/scss/modules/_header.scss +26 -26
- package/src/frontend/scss/modules/_mobile.scss +29 -29
- package/src/frontend/scss/modules/_typography.scss +18 -18
- package/src/frontend/scss/modules/frameworks/_bootstrap.scss +109 -109
- package/src/frontend/scss/modules/frameworks/_bulma.scss +108 -108
- package/src/frontend/scss/modules/frameworks/_foundation.scss +137 -137
- package/src/frontend/scss/modules/frameworks/_uikit.scss +109 -109
- package/src/frontend/scss/pages/404.scss +27 -27
- package/src/frontend/scss/pages/homepage.scss +22 -22
- package/src/frontend/sitemap.njk +17 -17
- package/src/frontend/ts/global.ts +11 -11
- package/src/frontend/ts/modules/exampleModule.ts +2 -2
- package/src/frontend/ts/pages/404.ts +8 -8
- package/src/frontend/ts/pages/homepage.ts +8 -8
- package/src/frontend/web.config +51 -51
- package/tools/assistant.js +122 -122
- package/tools/buildJs.js +39 -39
- package/tools/cleanOutput.js +23 -23
- package/tools/cli/prompt.js +40 -40
- package/tools/cli/ui.js +87 -87
- package/tools/config/messages.json +80 -80
- package/tools/config/settings.json +130 -130
- package/tools/lib/colors.js +17 -17
- package/tools/lib/files.js +75 -75
- package/tools/lib/logger.js +22 -22
- package/tools/lib/outputPath.js +141 -141
- package/tools/lib/pageActions.js +146 -146
- package/tools/lib/pageArtifacts.js +46 -46
- package/tools/lib/pageComponents.js +88 -88
- package/tools/lib/pagesData.js +87 -87
- package/tools/lib/paths.js +63 -63
- package/tools/lib/project.js +54 -54
- package/tools/lib/text.js +47 -47
- package/tools/lib/validation.js +40 -40
- package/tools/res/templates/template.js +7 -7
- package/tools/res/templates/template.njk +8 -8
- package/tools/res/templates/template.scss +22 -22
- package/tools/res/templates/template.ts +8 -8
- package/tsconfig.json +24 -24
- package/src/frontend/scss/pages/prova.scss +0 -23
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const settings = require('../config/settings.json');
|
|
3
|
-
const { PATHS } = require('./paths');
|
|
4
|
-
const { exists, readText, writeText } = require('./files');
|
|
5
|
-
const { log } = require('./logger');
|
|
6
|
-
const { toCamelCase, formatText } = require('./text');
|
|
7
|
-
|
|
8
|
-
const EXTRA_BLANK_LINES_PATTERN = /\n\s*\n\s*\n/g;
|
|
9
|
-
const BLANK_LINES = '\n\n';
|
|
10
|
-
const ANCHOR = settings.pageComponents.anchor;
|
|
11
|
-
|
|
12
|
-
function blockPattern(camelName) {
|
|
13
|
-
return new RegExp(
|
|
14
|
-
`[ \\t]*\\{%\\s*elif\\s+title\\s*==\\s*"${camelName}"\\s*%\\}[\\s\\S]*?(?=[ \\t]*\\{%\\s*(?:elif|else|endif))`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function conditionFor(camelName) {
|
|
19
|
-
return formatText(settings.pageComponents.condition, { camelName });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function readPageComponents() {
|
|
23
|
-
if (!exists(PATHS.pageComponents)) {
|
|
24
|
-
log('components.fileMissing', { path: PATHS.pageComponents });
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
return readText(PATHS.pageComponents);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function writePageComponents(content) {
|
|
31
|
-
writeText(PATHS.pageComponents, content);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function addPageBlock(pageName) {
|
|
35
|
-
const content = readPageComponents();
|
|
36
|
-
if (content === null) return;
|
|
37
|
-
|
|
38
|
-
const camelName = toCamelCase(pageName);
|
|
39
|
-
const condition = conditionFor(camelName);
|
|
40
|
-
if (content.includes(condition)) return;
|
|
41
|
-
|
|
42
|
-
if (!content.includes(ANCHOR)) {
|
|
43
|
-
log('components.anchorMissing', { anchor: ANCHOR, file: path.basename(PATHS.pageComponents) });
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const block = `${condition}\n${settings.pageComponents.include}\n\n`;
|
|
48
|
-
|
|
49
|
-
writePageComponents(content.replace(ANCHOR, `${block}${ANCHOR}`));
|
|
50
|
-
log('components.blockAdded', { name: camelName });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function removePageBlock(pageName) {
|
|
54
|
-
const content = readPageComponents();
|
|
55
|
-
if (content === null) return;
|
|
56
|
-
|
|
57
|
-
const camelName = toCamelCase(pageName);
|
|
58
|
-
if (!blockPattern(camelName).test(content)) {
|
|
59
|
-
log('components.blockMissing', { name: camelName });
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const updated = content
|
|
64
|
-
.replace(blockPattern(camelName), '')
|
|
65
|
-
.replace(EXTRA_BLANK_LINES_PATTERN, BLANK_LINES);
|
|
66
|
-
|
|
67
|
-
writePageComponents(updated);
|
|
68
|
-
log('components.blockRemoved', { name: camelName });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function renamePageBlock(oldName, newName) {
|
|
72
|
-
const content = readPageComponents();
|
|
73
|
-
if (content === null) return;
|
|
74
|
-
|
|
75
|
-
const oldCamelName = toCamelCase(oldName);
|
|
76
|
-
const newCamelName = toCamelCase(newName);
|
|
77
|
-
const oldCondition = conditionFor(oldCamelName);
|
|
78
|
-
|
|
79
|
-
if (!content.includes(oldCondition)) {
|
|
80
|
-
log('components.blockMissing', { name: oldCamelName });
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
writePageComponents(content.replace(oldCondition, conditionFor(newCamelName)));
|
|
85
|
-
log('components.blockRenamed', { source: oldCamelName, destination: newCamelName });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = { addPageBlock, removePageBlock, renamePageBlock };
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const settings = require('../config/settings.json');
|
|
3
|
+
const { PATHS } = require('./paths');
|
|
4
|
+
const { exists, readText, writeText } = require('./files');
|
|
5
|
+
const { log } = require('./logger');
|
|
6
|
+
const { toCamelCase, formatText } = require('./text');
|
|
7
|
+
|
|
8
|
+
const EXTRA_BLANK_LINES_PATTERN = /\n\s*\n\s*\n/g;
|
|
9
|
+
const BLANK_LINES = '\n\n';
|
|
10
|
+
const ANCHOR = settings.pageComponents.anchor;
|
|
11
|
+
|
|
12
|
+
function blockPattern(camelName) {
|
|
13
|
+
return new RegExp(
|
|
14
|
+
`[ \\t]*\\{%\\s*elif\\s+title\\s*==\\s*"${camelName}"\\s*%\\}[\\s\\S]*?(?=[ \\t]*\\{%\\s*(?:elif|else|endif))`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function conditionFor(camelName) {
|
|
19
|
+
return formatText(settings.pageComponents.condition, { camelName });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function readPageComponents() {
|
|
23
|
+
if (!exists(PATHS.pageComponents)) {
|
|
24
|
+
log('components.fileMissing', { path: PATHS.pageComponents });
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return readText(PATHS.pageComponents);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function writePageComponents(content) {
|
|
31
|
+
writeText(PATHS.pageComponents, content);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addPageBlock(pageName) {
|
|
35
|
+
const content = readPageComponents();
|
|
36
|
+
if (content === null) return;
|
|
37
|
+
|
|
38
|
+
const camelName = toCamelCase(pageName);
|
|
39
|
+
const condition = conditionFor(camelName);
|
|
40
|
+
if (content.includes(condition)) return;
|
|
41
|
+
|
|
42
|
+
if (!content.includes(ANCHOR)) {
|
|
43
|
+
log('components.anchorMissing', { anchor: ANCHOR, file: path.basename(PATHS.pageComponents) });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const block = `${condition}\n${settings.pageComponents.include}\n\n`;
|
|
48
|
+
|
|
49
|
+
writePageComponents(content.replace(ANCHOR, `${block}${ANCHOR}`));
|
|
50
|
+
log('components.blockAdded', { name: camelName });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function removePageBlock(pageName) {
|
|
54
|
+
const content = readPageComponents();
|
|
55
|
+
if (content === null) return;
|
|
56
|
+
|
|
57
|
+
const camelName = toCamelCase(pageName);
|
|
58
|
+
if (!blockPattern(camelName).test(content)) {
|
|
59
|
+
log('components.blockMissing', { name: camelName });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const updated = content
|
|
64
|
+
.replace(blockPattern(camelName), '')
|
|
65
|
+
.replace(EXTRA_BLANK_LINES_PATTERN, BLANK_LINES);
|
|
66
|
+
|
|
67
|
+
writePageComponents(updated);
|
|
68
|
+
log('components.blockRemoved', { name: camelName });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function renamePageBlock(oldName, newName) {
|
|
72
|
+
const content = readPageComponents();
|
|
73
|
+
if (content === null) return;
|
|
74
|
+
|
|
75
|
+
const oldCamelName = toCamelCase(oldName);
|
|
76
|
+
const newCamelName = toCamelCase(newName);
|
|
77
|
+
const oldCondition = conditionFor(oldCamelName);
|
|
78
|
+
|
|
79
|
+
if (!content.includes(oldCondition)) {
|
|
80
|
+
log('components.blockMissing', { name: oldCamelName });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
writePageComponents(content.replace(oldCondition, conditionFor(newCamelName)));
|
|
85
|
+
log('components.blockRenamed', { source: oldCamelName, destination: newCamelName });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { addPageBlock, removePageBlock, renamePageBlock };
|
package/tools/lib/pagesData.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const settings = require('../config/settings.json');
|
|
3
|
-
const { PATHS } = require('./paths');
|
|
4
|
-
const { exists, readText, writeJson } = require('./files');
|
|
5
|
-
const { log } = require('./logger');
|
|
6
|
-
const { toCamelCase, toTitleCase, formatValue } = require('./text');
|
|
7
|
-
|
|
8
|
-
function readPagesData() {
|
|
9
|
-
if (!exists(PATHS.pagesData)) {
|
|
10
|
-
log('pagesData.fileMissing', { path: PATHS.pagesData });
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const data = JSON.parse(readText(PATHS.pagesData));
|
|
15
|
-
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
16
|
-
log('pagesData.invalidStructure', { file: path.basename(PATHS.pagesData) });
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return data;
|
|
20
|
-
} catch (error) {
|
|
21
|
-
log('pagesData.parseFailed', { file: path.basename(PATHS.pagesData), error: error.message });
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function writePagesData(data) {
|
|
27
|
-
writeJson(PATHS.pagesData, data);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function createRecord(pageName) {
|
|
31
|
-
return formatValue(settings.page.defaultData, { title: toTitleCase(pageName) });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function addPageData(pageName) {
|
|
35
|
-
const data = readPagesData();
|
|
36
|
-
if (!data) return;
|
|
37
|
-
|
|
38
|
-
const camelName = toCamelCase(pageName);
|
|
39
|
-
if (data[camelName]) {
|
|
40
|
-
log('pagesData.recordExists', { name: camelName });
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
data[camelName] = createRecord(pageName);
|
|
45
|
-
|
|
46
|
-
writePagesData(data);
|
|
47
|
-
log('pagesData.recordAdded', { name: camelName });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function removePageData(pageName) {
|
|
51
|
-
const data = readPagesData();
|
|
52
|
-
if (!data) return;
|
|
53
|
-
|
|
54
|
-
const camelName = toCamelCase(pageName);
|
|
55
|
-
if (!data[camelName]) {
|
|
56
|
-
log('pagesData.recordMissing', { name: camelName });
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
delete data[camelName];
|
|
61
|
-
writePagesData(data);
|
|
62
|
-
log('pagesData.recordRemoved', { name: camelName });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function renamePageData(oldName, newName) {
|
|
66
|
-
const data = readPagesData();
|
|
67
|
-
if (!data) return;
|
|
68
|
-
|
|
69
|
-
const oldCamelName = toCamelCase(oldName);
|
|
70
|
-
const newCamelName = toCamelCase(newName);
|
|
71
|
-
|
|
72
|
-
if (!data[oldCamelName]) {
|
|
73
|
-
log('pagesData.recordMissing', { name: oldCamelName });
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (data[newCamelName]) {
|
|
77
|
-
log('pagesData.recordExists', { name: newCamelName });
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
data[newCamelName] = data[oldCamelName];
|
|
82
|
-
delete data[oldCamelName];
|
|
83
|
-
|
|
84
|
-
writePagesData(data);
|
|
85
|
-
log('pagesData.recordRenamed', { source: oldCamelName, destination: newCamelName });
|
|
86
|
-
}
|
|
87
|
-
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const settings = require('../config/settings.json');
|
|
3
|
+
const { PATHS } = require('./paths');
|
|
4
|
+
const { exists, readText, writeJson } = require('./files');
|
|
5
|
+
const { log } = require('./logger');
|
|
6
|
+
const { toCamelCase, toTitleCase, formatValue } = require('./text');
|
|
7
|
+
|
|
8
|
+
function readPagesData() {
|
|
9
|
+
if (!exists(PATHS.pagesData)) {
|
|
10
|
+
log('pagesData.fileMissing', { path: PATHS.pagesData });
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const data = JSON.parse(readText(PATHS.pagesData));
|
|
15
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
16
|
+
log('pagesData.invalidStructure', { file: path.basename(PATHS.pagesData) });
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return data;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
log('pagesData.parseFailed', { file: path.basename(PATHS.pagesData), error: error.message });
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function writePagesData(data) {
|
|
27
|
+
writeJson(PATHS.pagesData, data);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createRecord(pageName) {
|
|
31
|
+
return formatValue(settings.page.defaultData, { title: toTitleCase(pageName) });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addPageData(pageName) {
|
|
35
|
+
const data = readPagesData();
|
|
36
|
+
if (!data) return;
|
|
37
|
+
|
|
38
|
+
const camelName = toCamelCase(pageName);
|
|
39
|
+
if (data[camelName]) {
|
|
40
|
+
log('pagesData.recordExists', { name: camelName });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
data[camelName] = createRecord(pageName);
|
|
45
|
+
|
|
46
|
+
writePagesData(data);
|
|
47
|
+
log('pagesData.recordAdded', { name: camelName });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function removePageData(pageName) {
|
|
51
|
+
const data = readPagesData();
|
|
52
|
+
if (!data) return;
|
|
53
|
+
|
|
54
|
+
const camelName = toCamelCase(pageName);
|
|
55
|
+
if (!data[camelName]) {
|
|
56
|
+
log('pagesData.recordMissing', { name: camelName });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
delete data[camelName];
|
|
61
|
+
writePagesData(data);
|
|
62
|
+
log('pagesData.recordRemoved', { name: camelName });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function renamePageData(oldName, newName) {
|
|
66
|
+
const data = readPagesData();
|
|
67
|
+
if (!data) return;
|
|
68
|
+
|
|
69
|
+
const oldCamelName = toCamelCase(oldName);
|
|
70
|
+
const newCamelName = toCamelCase(newName);
|
|
71
|
+
|
|
72
|
+
if (!data[oldCamelName]) {
|
|
73
|
+
log('pagesData.recordMissing', { name: oldCamelName });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (data[newCamelName]) {
|
|
77
|
+
log('pagesData.recordExists', { name: newCamelName });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
data[newCamelName] = data[oldCamelName];
|
|
82
|
+
delete data[oldCamelName];
|
|
83
|
+
|
|
84
|
+
writePagesData(data);
|
|
85
|
+
log('pagesData.recordRenamed', { source: oldCamelName, destination: newCamelName });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
88
|
module.exports = { readPagesData, addPageData, removePageData, renamePageData };
|
package/tools/lib/paths.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const settings = require('../config/settings.json');
|
|
4
|
-
const { paint } = require('./colors');
|
|
5
|
-
|
|
6
|
-
const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
7
|
-
const PATH_SEPARATOR = '/';
|
|
8
|
-
|
|
9
|
-
let cachedProjectRoot = null;
|
|
10
|
-
|
|
11
|
-
function findProjectRoot(start) {
|
|
12
|
-
let directory = path.resolve(start ?? process.cwd());
|
|
13
|
-
while (true) {
|
|
14
|
-
if (fs.existsSync(path.join(directory, settings.project.marker))) return directory;
|
|
15
|
-
const parent = path.dirname(directory);
|
|
16
|
-
if (parent === directory) return null;
|
|
17
|
-
directory = parent;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function projectRoot() {
|
|
22
|
-
if (cachedProjectRoot) return cachedProjectRoot;
|
|
23
|
-
const root = findProjectRoot();
|
|
24
|
-
if (!root) {
|
|
25
|
-
console.error(paint('red', require('./logger').message('project.notInside')));
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
cachedProjectRoot = root;
|
|
29
|
-
return root;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function resolveFromProject(relativePath) {
|
|
33
|
-
return path.join(projectRoot(), ...relativePath.split(PATH_SEPARATOR));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function resolveFromPackage(relativePath) {
|
|
37
|
-
return path.join(PACKAGE_ROOT, ...relativePath.split(PATH_SEPARATOR));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const PATHS = Object.freeze({
|
|
41
|
-
get root() { return projectRoot(); },
|
|
42
|
-
get eleventyConfig() { return resolveFromProject(settings.paths.eleventyConfig); },
|
|
43
|
-
get packageJson() { return resolveFromProject(settings.paths.packageJson); },
|
|
44
|
-
get typescriptConfig() { return resolveFromProject(settings.paths.typescriptConfig); },
|
|
45
|
-
get routes() { return resolveFromProject(settings.paths.routes); },
|
|
46
|
-
get stylePages() { return resolveFromProject(settings.paths.stylePages); },
|
|
47
|
-
get siteData() { return resolveFromProject(settings.paths.siteData); },
|
|
48
|
-
get pagesData() { return resolveFromProject(settings.paths.pagesData); },
|
|
49
|
-
get pageComponents() { return resolveFromProject(settings.paths.pageComponents); },
|
|
50
|
-
get templates() { return resolveFromPackage(settings.paths.templates); },
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
function getNotInsideProjectMessage() {
|
|
54
|
-
return paint('red', require('./logger').message('project.notInside'));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = {
|
|
58
|
-
PATHS,
|
|
59
|
-
PACKAGE_ROOT,
|
|
60
|
-
getNotInsideProjectMessage,
|
|
61
|
-
findProjectRoot,
|
|
62
|
-
resolveFromProject,
|
|
63
|
-
resolveFromPackage,
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const settings = require('../config/settings.json');
|
|
4
|
+
const { paint } = require('./colors');
|
|
5
|
+
|
|
6
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
7
|
+
const PATH_SEPARATOR = '/';
|
|
8
|
+
|
|
9
|
+
let cachedProjectRoot = null;
|
|
10
|
+
|
|
11
|
+
function findProjectRoot(start) {
|
|
12
|
+
let directory = path.resolve(start ?? process.cwd());
|
|
13
|
+
while (true) {
|
|
14
|
+
if (fs.existsSync(path.join(directory, settings.project.marker))) return directory;
|
|
15
|
+
const parent = path.dirname(directory);
|
|
16
|
+
if (parent === directory) return null;
|
|
17
|
+
directory = parent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function projectRoot() {
|
|
22
|
+
if (cachedProjectRoot) return cachedProjectRoot;
|
|
23
|
+
const root = findProjectRoot();
|
|
24
|
+
if (!root) {
|
|
25
|
+
console.error(paint('red', require('./logger').message('project.notInside')));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
cachedProjectRoot = root;
|
|
29
|
+
return root;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveFromProject(relativePath) {
|
|
33
|
+
return path.join(projectRoot(), ...relativePath.split(PATH_SEPARATOR));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function resolveFromPackage(relativePath) {
|
|
37
|
+
return path.join(PACKAGE_ROOT, ...relativePath.split(PATH_SEPARATOR));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const PATHS = Object.freeze({
|
|
41
|
+
get root() { return projectRoot(); },
|
|
42
|
+
get eleventyConfig() { return resolveFromProject(settings.paths.eleventyConfig); },
|
|
43
|
+
get packageJson() { return resolveFromProject(settings.paths.packageJson); },
|
|
44
|
+
get typescriptConfig() { return resolveFromProject(settings.paths.typescriptConfig); },
|
|
45
|
+
get routes() { return resolveFromProject(settings.paths.routes); },
|
|
46
|
+
get stylePages() { return resolveFromProject(settings.paths.stylePages); },
|
|
47
|
+
get siteData() { return resolveFromProject(settings.paths.siteData); },
|
|
48
|
+
get pagesData() { return resolveFromProject(settings.paths.pagesData); },
|
|
49
|
+
get pageComponents() { return resolveFromProject(settings.paths.pageComponents); },
|
|
50
|
+
get templates() { return resolveFromPackage(settings.paths.templates); },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function getNotInsideProjectMessage() {
|
|
54
|
+
return paint('red', require('./logger').message('project.notInside'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
PATHS,
|
|
59
|
+
PACKAGE_ROOT,
|
|
60
|
+
getNotInsideProjectMessage,
|
|
61
|
+
findProjectRoot,
|
|
62
|
+
resolveFromProject,
|
|
63
|
+
resolveFromPackage,
|
|
64
64
|
};
|
package/tools/lib/project.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const settings = require('../config/settings.json');
|
|
3
|
-
const { PATHS, resolveFromProject } = require('./paths');
|
|
4
|
-
const { readJson, writeJson } = require('./files');
|
|
5
|
-
|
|
6
|
-
const JAVASCRIPT = 'javascript';
|
|
7
|
-
const TYPESCRIPT = 'typescript';
|
|
8
|
-
const ENTRY_WILDCARD = '*';
|
|
9
|
-
|
|
10
|
-
function isTypeScriptProject() {
|
|
11
|
-
return fs.existsSync(PATHS.typescriptConfig);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function currentLanguage() {
|
|
15
|
-
return isTypeScriptProject() ? TYPESCRIPT : JAVASCRIPT;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function languageSettings(language) {
|
|
19
|
-
return settings.languages[language ?? currentLanguage()];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function scriptPagesDirectory(language) {
|
|
23
|
-
return resolveFromProject(languageSettings(language).pages);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function scriptEntries(language) {
|
|
27
|
-
const { pages, extension } = languageSettings(language);
|
|
28
|
-
return `${pages}/${ENTRY_WILDCARD}.${extension}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function allScriptEntries() {
|
|
32
|
-
return Object.keys(settings.languages).map((language) => scriptEntries(language));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function readPackageJson() {
|
|
36
|
-
return readJson(PATHS.packageJson);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function writePackageJson(content) {
|
|
40
|
-
writeJson(PATHS.packageJson, content);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = {
|
|
44
|
-
JAVASCRIPT,
|
|
45
|
-
TYPESCRIPT,
|
|
46
|
-
isTypeScriptProject,
|
|
47
|
-
currentLanguage,
|
|
48
|
-
languageSettings,
|
|
49
|
-
scriptPagesDirectory,
|
|
50
|
-
scriptEntries,
|
|
51
|
-
allScriptEntries,
|
|
52
|
-
readPackageJson,
|
|
53
|
-
writePackageJson,
|
|
54
|
-
};
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const settings = require('../config/settings.json');
|
|
3
|
+
const { PATHS, resolveFromProject } = require('./paths');
|
|
4
|
+
const { readJson, writeJson } = require('./files');
|
|
5
|
+
|
|
6
|
+
const JAVASCRIPT = 'javascript';
|
|
7
|
+
const TYPESCRIPT = 'typescript';
|
|
8
|
+
const ENTRY_WILDCARD = '*';
|
|
9
|
+
|
|
10
|
+
function isTypeScriptProject() {
|
|
11
|
+
return fs.existsSync(PATHS.typescriptConfig);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function currentLanguage() {
|
|
15
|
+
return isTypeScriptProject() ? TYPESCRIPT : JAVASCRIPT;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function languageSettings(language) {
|
|
19
|
+
return settings.languages[language ?? currentLanguage()];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function scriptPagesDirectory(language) {
|
|
23
|
+
return resolveFromProject(languageSettings(language).pages);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function scriptEntries(language) {
|
|
27
|
+
const { pages, extension } = languageSettings(language);
|
|
28
|
+
return `${pages}/${ENTRY_WILDCARD}.${extension}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function allScriptEntries() {
|
|
32
|
+
return Object.keys(settings.languages).map((language) => scriptEntries(language));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function readPackageJson() {
|
|
36
|
+
return readJson(PATHS.packageJson);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function writePackageJson(content) {
|
|
40
|
+
writeJson(PATHS.packageJson, content);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
JAVASCRIPT,
|
|
45
|
+
TYPESCRIPT,
|
|
46
|
+
isTypeScriptProject,
|
|
47
|
+
currentLanguage,
|
|
48
|
+
languageSettings,
|
|
49
|
+
scriptPagesDirectory,
|
|
50
|
+
scriptEntries,
|
|
51
|
+
allScriptEntries,
|
|
52
|
+
readPackageJson,
|
|
53
|
+
writePackageJson,
|
|
54
|
+
};
|