@haxtheweb/create 9.0.7 → 9.0.9
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 +40 -7
- package/dist/create.js +140 -350
- package/dist/lib/programs/site.js +517 -0
- package/dist/lib/programs/webcomponent.js +184 -0
- package/dist/lib/utils.js +19 -2
- package/dist/templates/webcomponent/hax/package.json +2 -2
- package/package.json +6 -3
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.webcomponentCommandDetected = webcomponentCommandDetected;
|
|
8
|
+
exports.webcomponentProcess = webcomponentProcess;
|
|
9
|
+
var fs = _interopRequireWildcard(require("node:fs"));
|
|
10
|
+
var _promises = require("node:timers/promises");
|
|
11
|
+
var ejs = _interopRequireWildcard(require("ejs"));
|
|
12
|
+
var p = _interopRequireWildcard(require("@clack/prompts"));
|
|
13
|
+
var _picocolors = _interopRequireDefault(require("picocolors"));
|
|
14
|
+
var _statements = require("../statements.js");
|
|
15
|
+
var _utils = require("../utils.js");
|
|
16
|
+
var hax = _interopRequireWildcard(require("@haxtheweb/haxcms-nodejs"));
|
|
17
|
+
var child_process = _interopRequireWildcard(require("child_process"));
|
|
18
|
+
var util = _interopRequireWildcard(require("node:util"));
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
|
+
const HAXCMS = hax.HAXCMS;
|
|
23
|
+
const exec = util.promisify(child_process.exec);
|
|
24
|
+
let sysGit = true;
|
|
25
|
+
exec('git --version', error => {
|
|
26
|
+
if (error) {
|
|
27
|
+
sysGit = false;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// processing an element
|
|
32
|
+
async function webcomponentProcess(commandRun, project, port = "8000") {
|
|
33
|
+
// auto select operations to perform if requested
|
|
34
|
+
if (!project.extras) {
|
|
35
|
+
let extras = ['launch', 'install', 'git'];
|
|
36
|
+
if (!sysGit || project.isMonorepo) {
|
|
37
|
+
extras.pop();
|
|
38
|
+
}
|
|
39
|
+
project.extras = extras;
|
|
40
|
+
}
|
|
41
|
+
// values not set by user but used in templating
|
|
42
|
+
project.className = (0, _utils.dashToCamel)(project.name);
|
|
43
|
+
// option to build github repo link for the user
|
|
44
|
+
if (project.extras.includes('git')) {
|
|
45
|
+
// @todo need to support git@ and https methods
|
|
46
|
+
if (commandRun.options.auto) {
|
|
47
|
+
project.gitRepo = `https://github.com/${project.author}/${project.name}.git`;
|
|
48
|
+
} else {
|
|
49
|
+
project.gitRepo = await p.text({
|
|
50
|
+
message: 'Git Repo location:',
|
|
51
|
+
placeholder: `https://github.com/${project.author}/${project.name}.git`
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// if they supplied one and it has github in it, build a link automatically for ejs index
|
|
55
|
+
if (project.gitRepo && project.gitRepo.includes('github.com')) {
|
|
56
|
+
project.githubLink = project.gitRepo.replace('git@github.com:', 'https://github.com/').replace('.git', '');
|
|
57
|
+
} else {
|
|
58
|
+
project.githubLink = null;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
project.githubLink = null;
|
|
62
|
+
}
|
|
63
|
+
// if we have an org, add a / at the end so file name is written correctly
|
|
64
|
+
if (project.org) {
|
|
65
|
+
project.org += '/';
|
|
66
|
+
} else {
|
|
67
|
+
project.org = '';
|
|
68
|
+
}
|
|
69
|
+
let s = p.spinner();
|
|
70
|
+
s.start((0, _statements.merlinSays)('Copying project files'));
|
|
71
|
+
// leverage this little helper from HAXcms
|
|
72
|
+
await HAXCMS.recurseCopy(`${process.mainModule.path}/templates/${project.type}/hax/`, `${project.path}/${project.name}`);
|
|
73
|
+
// rename paths that are of the element name in question
|
|
74
|
+
await fs.renameSync(`${project.path}/${project.name}/lib/webcomponent.haxProperties.json`, `${project.path}/${project.name}/lib/${project.name}.haxProperties.json`);
|
|
75
|
+
// loop through and rename all the localization files
|
|
76
|
+
fs.readdir(`${project.path}/${project.name}/locales/`, function (err, files) {
|
|
77
|
+
if (err) {
|
|
78
|
+
console.error("Could not list the directory.", err);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
files.forEach(async function (file, index) {
|
|
82
|
+
await fs.renameSync(`${project.path}/${project.name}/locales/${file}`, `${project.path}/${project.name}/locales/${file.replace('webcomponent', project.name)}`);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
await fs.renameSync(`${project.path}/${project.name}/webcomponent.js`, `${project.path}/${project.name}/${project.name}.js`);
|
|
86
|
+
await fs.renameSync(`${project.path}/${project.name}/test/webcomponent.test.js`, `${project.path}/${project.name}/test/${project.name}.test.js`);
|
|
87
|
+
s.stop((0, _statements.merlinSays)('Files copied'));
|
|
88
|
+
await (0, _promises.setTimeout)(500);
|
|
89
|
+
s.start((0, _statements.merlinSays)('Making files awesome'));
|
|
90
|
+
for (const filePath of (0, _utils.readAllFiles)(`${project.path}/${project.name}`)) {
|
|
91
|
+
try {
|
|
92
|
+
// ensure we don't try to pattern rewrite image files
|
|
93
|
+
if (!filePath.endsWith('.jpg') && !filePath.endsWith('.png')) {
|
|
94
|
+
const ejsString = ejs.fileLoader(filePath, 'utf8');
|
|
95
|
+
let content = ejs.render(ejsString, project);
|
|
96
|
+
// file written successfully
|
|
97
|
+
fs.writeFileSync(filePath, content);
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.error(filePath);
|
|
101
|
+
console.error(err);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
s.stop('Files are now awesome!');
|
|
105
|
+
if (project.gitRepo && !commandRun.options.isMonorepo) {
|
|
106
|
+
try {
|
|
107
|
+
await exec(`cd ${project.path}/${project.name} && git init && git add -A && git commit -m "first commit" && git branch -M main${project.gitRepo ? ` && git remote add origin ${project.gitRepo}` : ''}`);
|
|
108
|
+
} catch (e) {}
|
|
109
|
+
}
|
|
110
|
+
// options for install, git and other extras
|
|
111
|
+
// can't launch if we didn't install first so launch implies installation
|
|
112
|
+
if (project.extras.includes('launch') || project.extras.includes('install')) {
|
|
113
|
+
s.start((0, _statements.merlinSays)(`Installation magic (${commandRun.options.npmClient} install)`));
|
|
114
|
+
try {
|
|
115
|
+
// monorepos install from top but then still need to launch from local location
|
|
116
|
+
if (!commandRun.options.isMonorepo) {
|
|
117
|
+
await exec(`cd ${project.path}/${project.name} && ${commandRun.options.npmClient} install`);
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.log(e);
|
|
121
|
+
}
|
|
122
|
+
s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
|
|
123
|
+
}
|
|
124
|
+
// autolaunch if default was selected
|
|
125
|
+
if (project.extras.includes('launch')) {
|
|
126
|
+
let optionPath = `${project.path}/${project.name}`;
|
|
127
|
+
let command = `${commandRun.options.npmClient} start`;
|
|
128
|
+
p.note(`${(0, _statements.merlinSays)(`I have summoned a sub-process daemon 👹`)}
|
|
129
|
+
|
|
130
|
+
🚀 Running your ${_picocolors.default.bold(project.type)} ${_picocolors.default.bold(project.name)}:
|
|
131
|
+
${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
|
|
132
|
+
|
|
133
|
+
🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${optionPath}`))))}
|
|
134
|
+
💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${optionPath}`)))}
|
|
135
|
+
📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${optionPath}`)))}
|
|
136
|
+
📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${optionPath}`)))}
|
|
137
|
+
🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${command}`)))}
|
|
138
|
+
|
|
139
|
+
⌨️ To resume 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
|
|
140
|
+
`);
|
|
141
|
+
// at least a second to see the message print at all
|
|
142
|
+
await (0, _promises.setTimeout)(1000);
|
|
143
|
+
try {
|
|
144
|
+
await exec(`cd ${optionPath} && ${command}`);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
// don't log bc output is weird
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
let nextSteps = `cd ${project.path}/${project.name} && ${project.extras.includes('install') ? '' : `${commandRun.options.npmClient} install && `}${commandRun.options.npmClient} start`;
|
|
150
|
+
p.note(`${project.name} is ready to go. Run the following to start development:`);
|
|
151
|
+
p.outro(nextSteps);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// autodetect webcomponent
|
|
156
|
+
async function webcomponentCommandDetected(commandRun, packageData = {}, port = "8000") {
|
|
157
|
+
p.intro(`${_picocolors.default.bgBlack(_picocolors.default.white(` HAXTheWeb : Webcomponent detected `))}`);
|
|
158
|
+
p.intro(`${_picocolors.default.bgBlue(_picocolors.default.white(` Name: ${packageData.name} `))}`);
|
|
159
|
+
p.note(`${(0, _statements.merlinSays)(`I have summoned a sub-process daemon 👹`)}
|
|
160
|
+
|
|
161
|
+
🚀 Running your ${_picocolors.default.bold('webcomponent')} ${_picocolors.default.bold(packageData.name)}:
|
|
162
|
+
${_picocolors.default.underline(_picocolors.default.cyan(`http://localhost:${port}`))}
|
|
163
|
+
|
|
164
|
+
🏠 Launched: ${_picocolors.default.underline(_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${process.cwd()}`))))}
|
|
165
|
+
💻 Folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`cd ${process.cwd()}`)))}
|
|
166
|
+
📂 Open folder: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`open ${process.cwd()}`)))}
|
|
167
|
+
📘 VS Code Project: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`code ${process.cwd()}`)))}
|
|
168
|
+
🚧 Launch later: ${_picocolors.default.bold(_picocolors.default.yellow(_picocolors.default.bgBlack(`${commandRun.options.npmClient} start`)))}
|
|
169
|
+
|
|
170
|
+
⌨️ To exit 🧙 Merlin press: ${_picocolors.default.bold(_picocolors.default.black(_picocolors.default.bgRed(` CTRL + C `)))}
|
|
171
|
+
`);
|
|
172
|
+
try {
|
|
173
|
+
// ensure it's installed first, unless it's a monorepo
|
|
174
|
+
if (!commandRun.options.isMonorepo) {
|
|
175
|
+
let s = p.spinner();
|
|
176
|
+
s.start((0, _statements.merlinSays)(`Installation magic (${commandRun.options.npmClient} install)`));
|
|
177
|
+
await exec(`${commandRun.options.npmClient} install`);
|
|
178
|
+
s.stop((0, _statements.merlinSays)(`Everything is installed. It's go time`));
|
|
179
|
+
}
|
|
180
|
+
await exec(`${commandRun.options.npmClient} start`);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
// don't log bc output is odd
|
|
183
|
+
}
|
|
184
|
+
}
|
package/dist/lib/utils.js
CHANGED
|
@@ -4,26 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SITE_FILE_NAME = void 0;
|
|
7
|
+
exports.camelToDash = camelToDash;
|
|
8
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
7
9
|
exports.dashToCamel = dashToCamel;
|
|
8
10
|
exports.generateUUID = generateUUID;
|
|
9
11
|
exports.readAllFiles = readAllFiles;
|
|
10
12
|
var fs = _interopRequireWildcard(require("node:fs"));
|
|
11
13
|
var path = _interopRequireWildcard(require("node:path"));
|
|
14
|
+
var child_process = _interopRequireWildcard(require("child_process"));
|
|
15
|
+
var util = _interopRequireWildcard(require("node:util"));
|
|
12
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
const exec = util.promisify(child_process.exec);
|
|
14
19
|
const SITE_FILE_NAME = exports.SITE_FILE_NAME = "site.json";
|
|
15
20
|
/**
|
|
16
21
|
* Helper to convert dash to camel; important when reading attributes.
|
|
17
22
|
*/
|
|
18
23
|
function dashToCamel(str) {
|
|
19
|
-
return str.replace(/-([a-z0-9])/g, function (g) {
|
|
24
|
+
return capitalizeFirstLetter(str.replace(/-([a-z0-9])/g, function (g) {
|
|
20
25
|
return g[1].toUpperCase();
|
|
21
|
-
});
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//capitalize only the first letter of the string.
|
|
30
|
+
function capitalizeFirstLetter(string) {
|
|
31
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
22
32
|
}
|
|
23
33
|
// generate unique-enough id
|
|
24
34
|
function generateUUID() {
|
|
25
35
|
return "ss-s-s-s-sss".replace(/s/g, _uuidPart);
|
|
26
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Helper to convert camel case to dash; important when setting attributes.
|
|
40
|
+
*/
|
|
41
|
+
function camelToDash(str) {
|
|
42
|
+
return str.replace(/\W+/g, "-").replace(/([a-z\d])([A-Z])/g, "$1-$2").toLowerCase();
|
|
43
|
+
}
|
|
27
44
|
function _uuidPart() {
|
|
28
45
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
|
29
46
|
}
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"lit": "^3.2.0",
|
|
31
|
-
"@haxtheweb/d-d-d": "
|
|
32
|
-
"@haxtheweb/i18n-manager": "
|
|
31
|
+
"@haxtheweb/d-d-d": "^9.0.13",
|
|
32
|
+
"@haxtheweb/i18n-manager": "^9.0.13"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@babel/preset-env": "^7.16.4",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haxtheweb/create",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"build": "rm -rf dist && babel src --out-dir dist --copy-files --include-dotfiles && chmod 774 dist/create.js",
|
|
23
23
|
"start": "npm run build && node ./dist/create.js && chmod 774 dist/create.js",
|
|
24
24
|
"release": "npm run build && commit-and-tag-version && git push --follow-tags origin main && npm publish",
|
|
25
|
-
"
|
|
25
|
+
"hax": "hax",
|
|
26
|
+
"dev": "nodemon --watch src",
|
|
27
|
+
"haxcms-nodejs-cli": "haxcms-nodejs-cli"
|
|
26
28
|
},
|
|
27
29
|
"bin": {
|
|
28
30
|
"create-haxtheweb": "./dist/create.js",
|
|
@@ -40,12 +42,13 @@
|
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"@clack/core": "0.3.4",
|
|
42
44
|
"@clack/prompts": "0.7.0",
|
|
43
|
-
"@haxtheweb/haxcms-nodejs": "^9.0.
|
|
45
|
+
"@haxtheweb/haxcms-nodejs": "^9.0.14",
|
|
44
46
|
"ejs": "3.1.10",
|
|
45
47
|
"picocolors": "1.0.1",
|
|
46
48
|
"commander": "12.1.0"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
51
|
+
"nodemon": "^3.1.7",
|
|
49
52
|
"@babel/cli": "^7.24.6",
|
|
50
53
|
"@babel/core": "^7.24.6",
|
|
51
54
|
"@babel/preset-env": "7.24.6",
|