@vendure-platform/create 0.3.0 → 0.5.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/CHANGELOG.md +8 -0
- package/README.md +7 -7
- package/dist/add-to-existing.js +1 -583
- package/dist/assets/storefront/messages/de.json +2 -0
- package/dist/assets/storefront/messages/en.json +2 -0
- package/dist/assets/storefront/package.json +1 -1
- package/dist/assets/storefront/src/app/[locale]/(catalog)/product/[slug]/page.tsx +7 -2
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/activity-feed.tsx +152 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/add-item-search.tsx +130 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/add-member-form.tsx +124 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/members-panel.tsx +240 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/page.tsx +47 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/rename-dialog.tsx +96 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/[id]/shared-cart-detail-client.tsx +555 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/actions.ts +260 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/new/new-shared-cart-form.tsx +77 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/new/page.tsx +47 -0
- package/dist/assets/storefront/src/app/[locale]/account/shared-carts/page.tsx +263 -0
- package/dist/assets/storefront/src/app/[locale]/cart/cart.tsx +12 -1
- package/dist/assets/storefront/src/app/[locale]/cart/order-summary.tsx +23 -0
- package/dist/assets/storefront/src/components/commerce/account-nav-items.ts +2 -0
- package/dist/assets/storefront/src/components/commerce/add-to-shared-cart.tsx +225 -0
- package/dist/assets/storefront/src/components/commerce/product-info.tsx +14 -1
- package/dist/assets/storefront/src/components/commerce/shared-cart-role.ts +39 -0
- package/dist/assets/storefront/src/components/commerce/shared-cart-status-badge.tsx +24 -0
- package/dist/assets/storefront/src/graphql-env.d.ts +28 -15
- package/dist/assets/storefront/src/lib/vendure/api.ts +8 -4
- package/dist/assets/storefront/src/lib/vendure/mutations.ts +96 -0
- package/dist/assets/storefront/src/lib/vendure/queries.ts +142 -0
- package/dist/assets/storefront/src/schema.graphql +321 -61
- package/dist/bin/run.js +1 -119
- package/dist/cli.js +1 -309
- package/dist/git-init.js +1 -60
- package/dist/index.js +1 -19
- package/dist/plugin-registry.js +1 -203
- package/dist/registry.js +1 -29
- package/dist/scaffold-shared.js +1 -124
- package/dist/scaffold-storefront-only.js +1 -101
- package/dist/scaffolder.js +1 -203
- package/dist/sort-package-json.js +1 -26
- package/dist/storefront-copier.js +1 -149
- package/dist/template-renderer.js +1 -221
- package/dist/types.js +1 -3
- package/package.json +5 -4
- package/dist/add-to-existing.js.map +0 -1
- package/dist/assets/storefront/src/lib/quantity.test.js +0 -20
- package/dist/bin/run.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/git-init.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plugin-registry.js.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/scaffold-shared.js.map +0 -1
- package/dist/scaffold-storefront-only.js.map +0 -1
- package/dist/scaffolder.js.map +0 -1
- package/dist/sort-package-json.js.map +0 -1
- package/dist/storefront-copier.js.map +0 -1
- package/dist/template-renderer.js.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/scaffold-shared.js
CHANGED
|
@@ -1,124 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.installDependencies = installDependencies;
|
|
37
|
-
exports.initRepository = initRepository;
|
|
38
|
-
const p = __importStar(require("@clack/prompts"));
|
|
39
|
-
const child_process_1 = require("child_process");
|
|
40
|
-
const util_1 = require("util");
|
|
41
|
-
const git_init_1 = require("./git-init");
|
|
42
|
-
const registry_1 = require("./registry");
|
|
43
|
-
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
44
|
-
/**
|
|
45
|
-
* Run the package manager's install step inside the scaffolded project.
|
|
46
|
-
* Logs the last few lines of stderr on failure but never throws — install
|
|
47
|
-
* failures are reported as a warning so the customer can retry manually.
|
|
48
|
-
*
|
|
49
|
-
* Special-cases the private-registry 401 because that's the most common
|
|
50
|
-
* first-time failure and the generic "run install manually" message gives
|
|
51
|
-
* no clue about where to look.
|
|
52
|
-
*/
|
|
53
|
-
async function installDependencies(projectDir, packageManager, spinner) {
|
|
54
|
-
var _a;
|
|
55
|
-
spinner.message(`Installing dependencies with ${packageManager} (this may take a few minutes)...`);
|
|
56
|
-
try {
|
|
57
|
-
await execAsync(`${packageManager} install`, { cwd: projectDir });
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
spinner.stop(`${packageManager} install failed.`);
|
|
61
|
-
const stderr = err instanceof Error && 'stderr' in err
|
|
62
|
-
? (_a = err.stderr) === null || _a === void 0 ? void 0 : _a.trim()
|
|
63
|
-
: undefined;
|
|
64
|
-
if (stderr) {
|
|
65
|
-
p.log.error(stderr.split('\n').slice(-5).join('\n'));
|
|
66
|
-
}
|
|
67
|
-
if (stderr && isRegistryAuthFailure(stderr)) {
|
|
68
|
-
p.log.warn(registryAuthFailureMessage(packageManager, projectDir));
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
p.log.warn(`Dependency install failed — run \`${packageManager} install\` manually in the project directory.`);
|
|
72
|
-
}
|
|
73
|
-
spinner.start('Continuing...');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function isRegistryAuthFailure(stderr) {
|
|
77
|
-
const hostnamePattern = (0, registry_1.getRegistryHostname)().replace(/\./g, '\\.');
|
|
78
|
-
return new RegExp(`\\bE401\\b|401 Unauthorized|${hostnamePattern}`, 'i').test(stderr);
|
|
79
|
-
}
|
|
80
|
-
function registryAuthFailureMessage(packageManager, projectDir) {
|
|
81
|
-
// `npm login` accepts the URL with or without a trailing slash; strip it
|
|
82
|
-
// for the user-facing copy so the command looks tidy.
|
|
83
|
-
const loginUrl = (0, registry_1.getRegistryUrl)().replace(/\/+$/, '');
|
|
84
|
-
return [
|
|
85
|
-
'Install failed: not authenticated to the Vendure private registry',
|
|
86
|
-
'(or your existing registry token has expired).',
|
|
87
|
-
'',
|
|
88
|
-
'Get a registry token from the Vendure Enterprise Portal:',
|
|
89
|
-
' https://enterprise.vendure.io',
|
|
90
|
-
'',
|
|
91
|
-
'(This is the npm auth token, used by `npm install`. It is distinct',
|
|
92
|
-
' from the server-side license token that goes into .env.)',
|
|
93
|
-
'',
|
|
94
|
-
'Then either:',
|
|
95
|
-
' - paste the registry token into the project .npmrc next to the scope line:',
|
|
96
|
-
` ${projectDir}/.npmrc`,
|
|
97
|
-
' //registry.platform.vendure.io/:_authToken=<registry-token>',
|
|
98
|
-
` then re-run \`${packageManager} install\` in ${projectDir}.`,
|
|
99
|
-
' - or authenticate interactively (writes to ~/.npmrc):',
|
|
100
|
-
` npm login --auth-type=web --registry=${loginUrl}`,
|
|
101
|
-
` then re-run \`${packageManager} install\` in ${projectDir}.`,
|
|
102
|
-
'',
|
|
103
|
-
'Docs: https://docs.platform.vendure.io',
|
|
104
|
-
].join('\n');
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Initialise a git repo in the scaffolded project, optionally pushing to a
|
|
108
|
-
* fresh GitHub repo. Never throws — git/gh failures are reported as a warning.
|
|
109
|
-
*/
|
|
110
|
-
async function initRepository(projectDir, createGithubRepo, githubOrg, spinner) {
|
|
111
|
-
spinner.message('Initializing git...');
|
|
112
|
-
try {
|
|
113
|
-
await (0, git_init_1.initGit)(projectDir, createGithubRepo, githubOrg);
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
spinner.stop('Git setup had issues.');
|
|
117
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
118
|
-
p.log.warn(createGithubRepo
|
|
119
|
-
? `Git/GitHub setup had issues — make sure the gh CLI is installed and authenticated. (${message})`
|
|
120
|
-
: `Git init had issues — initialise the repo manually if needed. (${message})`);
|
|
121
|
-
spinner.start('Continuing...');
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=scaffold-shared.js.map
|
|
1
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||function(){var n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},n(e)};return function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var s=n(i),o=0;o<s.length;o++)"default"!==s[o]&&e(r,i,s[o]);return t(r,i),r}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.installDependencies=u,exports.initRepository=d;const i=n(require("@clack/prompts")),r=require("child_process"),s=require("util"),o=require("./git-init"),a=require("./registry"),l=(0,s.promisify)(r.exec);async function u(e,t,n){var r;n.message(`Installing dependencies with ${t} (this may take a few minutes)...`);try{await l(`${t} install`,{cwd:e})}catch(s){n.stop(`${t} install failed.`);const o=s instanceof Error&&"stderr"in s?null===(r=s.stderr)||void 0===r?void 0:r.trim():void 0;o&&i.log.error(o.split("\n").slice(-5).join("\n")),o&&c(o)?i.log.warn(p(t,e)):i.log.warn(`Dependency install failed \u2014 run \`${t} install\` manually in the project directory.`),n.start("Continuing...")}}function c(e){const t=(0,a.getRegistryHostname)().replace(/\./g,"\\.");return new RegExp(`\\bE401\\b|401 Unauthorized|${t}`,"i").test(e)}function p(e,t){return["Install failed: not authenticated to the Vendure private registry","(or your existing registry token has expired).","","Get a registry token from the Vendure Enterprise Portal:"," https://enterprise.vendure.io","","(This is the npm auth token, used by `npm install`. It is distinct"," from the server-side license token that goes into .env.)","","Then either:"," - paste the registry token into the project .npmrc next to the scope line:",` ${t}/.npmrc`," //registry.platform.vendure.io/:_authToken=<registry-token>",` then re-run \`${e} install\` in ${t}.`," - or authenticate interactively (writes to ~/.npmrc):",` npm login --auth-type=web --registry=${(0,a.getRegistryUrl)().replace(/\/+$/,"")}`,` then re-run \`${e} install\` in ${t}.`,"","Docs: https://docs.platform.vendure.io"].join("\n")}async function d(e,t,n,r){r.message("Initializing git...");try{await(0,o.initGit)(e,t,n)}catch(e){r.stop("Git setup had issues.");const n=e instanceof Error?e.message:String(e);i.log.warn(t?`Git/GitHub setup had issues \u2014 make sure the gh CLI is installed and authenticated. (${n})`:`Git init had issues \u2014 initialise the repo manually if needed. (${n})`),r.start("Continuing...")}}
|
|
@@ -1,101 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.scaffoldStorefrontOnly = scaffoldStorefrontOnly;
|
|
37
|
-
const fs = __importStar(require("fs-extra"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const p = __importStar(require("@clack/prompts"));
|
|
40
|
-
const storefront_copier_1 = require("./storefront-copier");
|
|
41
|
-
const scaffold_shared_1 = require("./scaffold-shared");
|
|
42
|
-
/**
|
|
43
|
-
* Scaffold a standalone Vendure storefront pointed at an external Shop API.
|
|
44
|
-
* No server, no plugins, no demo data — just the Next.js storefront.
|
|
45
|
-
*/
|
|
46
|
-
async function scaffoldStorefrontOnly(options) {
|
|
47
|
-
const { projectName, apiUrl, scenario, packageManager, skipInstall, skipGit, dryRun } = options;
|
|
48
|
-
const projectDir = path.resolve(process.cwd(), projectName);
|
|
49
|
-
if (await fs.pathExists(projectDir)) {
|
|
50
|
-
const entries = await fs.readdir(projectDir);
|
|
51
|
-
if (entries.length > 0) {
|
|
52
|
-
p.log.error(`Directory "${projectDir}" already exists and is not empty.`);
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (dryRun) {
|
|
57
|
-
const summary = [
|
|
58
|
-
`Project: ${projectName} → ${projectDir}`,
|
|
59
|
-
'',
|
|
60
|
-
`Mode: storefront-only`,
|
|
61
|
-
`Scenario: ${scenario}`,
|
|
62
|
-
`API URL: ${apiUrl !== null && apiUrl !== void 0 ? apiUrl : '(use default localhost)'}`,
|
|
63
|
-
`Package manager: ${packageManager}`,
|
|
64
|
-
`Install deps: ${skipInstall ? 'no' : 'yes'}`,
|
|
65
|
-
`Git init: ${skipGit ? 'no' : 'yes'}`,
|
|
66
|
-
].join('\n');
|
|
67
|
-
p.note(summary, 'Dry run');
|
|
68
|
-
p.outro('Dry run complete — no files written.');
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const s = p.spinner();
|
|
72
|
-
s.start('Creating project directory...');
|
|
73
|
-
await fs.ensureDir(projectDir);
|
|
74
|
-
s.message('Copying storefront...');
|
|
75
|
-
await (0, storefront_copier_1.copyStorefront)(projectDir, {
|
|
76
|
-
mode: 'storefront-only',
|
|
77
|
-
scenario,
|
|
78
|
-
apiUrl,
|
|
79
|
-
packageName: projectName,
|
|
80
|
-
});
|
|
81
|
-
if (!skipInstall) {
|
|
82
|
-
await (0, scaffold_shared_1.installDependencies)(projectDir, packageManager, s);
|
|
83
|
-
}
|
|
84
|
-
if (!skipGit) {
|
|
85
|
-
await (0, scaffold_shared_1.initRepository)(projectDir, false, undefined, s);
|
|
86
|
-
}
|
|
87
|
-
s.stop(`Project "${projectName}" created successfully!`);
|
|
88
|
-
const devCommand = packageManager === 'npm' ? 'npm run dev' : `${packageManager} run dev`;
|
|
89
|
-
const steps = [
|
|
90
|
-
`cd ${projectName}`,
|
|
91
|
-
apiUrl
|
|
92
|
-
? `# .env.local already points VENDURE_SHOP_API_URL at ${apiUrl}`
|
|
93
|
-
: '# Edit .env.local and set VENDURE_SHOP_API_URL to your Vendure server',
|
|
94
|
-
devCommand,
|
|
95
|
-
'',
|
|
96
|
-
'Storefront: http://localhost:${STOREFRONT_PORT:-3001}',
|
|
97
|
-
].join('\n');
|
|
98
|
-
p.note(steps, 'Next steps');
|
|
99
|
-
p.outro('Happy building!');
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=scaffold-storefront-only.js.map
|
|
1
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},r(e)};return function(n){if(n&&n.__esModule)return n;var o={};if(null!=n)for(var a=r(n),i=0;i<a.length;i++)"default"!==a[i]&&e(o,n,a[i]);return t(o,n),o}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.scaffoldStorefrontOnly=c;const n=r(require("fs-extra")),o=r(require("path")),a=r(require("@clack/prompts")),i=require("./storefront-copier"),s=require("./scaffold-shared");async function c(e){const{projectName:t,apiUrl:r,scenario:c,packageManager:l,skipInstall:u,skipGit:p,dryRun:d}=e,f=o.resolve(process.cwd(),t);if(await n.pathExists(f)&&(await n.readdir(f)).length>0&&(a.log.error(`Directory "${f}" already exists and is not empty.`),process.exit(1)),d){const e=[`Project: ${t} \u2192 ${f}`,"","Mode: storefront-only",`Scenario: ${c}`,`API URL: ${null!=r?r:"(use default localhost)"}`,`Package manager: ${l}`,"Install deps: "+(u?"no":"yes"),"Git init: "+(p?"no":"yes")].join("\n");return a.note(e,"Dry run"),void a.outro("Dry run complete \u2014 no files written.")}const y=a.spinner();y.start("Creating project directory..."),await n.ensureDir(f),y.message("Copying storefront..."),await(0,i.copyStorefront)(f,{mode:"storefront-only",scenario:c,apiUrl:r,packageName:t}),u||await(0,s.installDependencies)(f,l,y),p||await(0,s.initRepository)(f,!1,void 0,y),y.stop(`Project "${t}" created successfully!`);const g=[`cd ${t}`,r?`# .env.local already points VENDURE_SHOP_API_URL at ${r}`:"# Edit .env.local and set VENDURE_SHOP_API_URL to your Vendure server","npm"===l?"npm run dev":`${l} run dev`,"","Storefront: http://localhost:${STOREFRONT_PORT:-3001}"].join("\n");a.note(g,"Next steps"),a.outro("Happy building!")}
|
package/dist/scaffolder.js
CHANGED
|
@@ -1,203 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.TEMPLATE_FILES = void 0;
|
|
37
|
-
exports.scaffold = scaffold;
|
|
38
|
-
const fs = __importStar(require("fs-extra"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
const p = __importStar(require("@clack/prompts"));
|
|
41
|
-
const plugin_registry_1 = require("./plugin-registry");
|
|
42
|
-
const template_renderer_1 = require("./template-renderer");
|
|
43
|
-
const storefront_copier_1 = require("./storefront-copier");
|
|
44
|
-
const scaffold_shared_1 = require("./scaffold-shared");
|
|
45
|
-
/** Template-to-output mapping used by the scaffolder. */
|
|
46
|
-
exports.TEMPLATE_FILES = [
|
|
47
|
-
{ template: 'vendure-config.ts.hbs', output: 'server/src/vendure-config.ts' },
|
|
48
|
-
{ template: 'populate.ts.hbs', output: 'server/src/populate.ts' },
|
|
49
|
-
{ template: 'custom-populate.ts.hbs', output: 'server/src/custom-populate.ts' },
|
|
50
|
-
{ template: 'index.ts.hbs', output: 'server/src/index.ts' },
|
|
51
|
-
{ template: 'server-package.json.hbs', output: 'server/package.json' },
|
|
52
|
-
{ template: 'root-package.json.hbs', output: 'package.json' },
|
|
53
|
-
{ template: 'env.hbs', output: '.env' },
|
|
54
|
-
{ template: 'docker-compose.yml.hbs', output: 'docker-compose.yml' },
|
|
55
|
-
{ template: 'CLAUDE.md.hbs', output: 'CLAUDE.md' },
|
|
56
|
-
{ template: 'README.md.hbs', output: 'README.md' },
|
|
57
|
-
{ template: 'tsconfig.root.json.hbs', output: 'tsconfig.json' },
|
|
58
|
-
{ template: 'tsconfig.server.json.hbs', output: 'server/tsconfig.json' },
|
|
59
|
-
{ template: 'vite.config.mts.hbs', output: 'server/vite.config.mts' },
|
|
60
|
-
{ template: 'tsconfig.dashboard.json.hbs', output: 'server/tsconfig.dashboard.json' },
|
|
61
|
-
{ template: 'environment.d.ts.hbs', output: 'server/src/environment.d.ts' },
|
|
62
|
-
{ template: 'gitignore.hbs', output: '.gitignore' },
|
|
63
|
-
{ template: 'npmrc.hbs', output: '.npmrc' },
|
|
64
|
-
{ template: 'bunfig.toml.hbs', output: 'bunfig.toml' },
|
|
65
|
-
];
|
|
66
|
-
/**
|
|
67
|
-
* Scaffold a complete Vendure demo project.
|
|
68
|
-
*/
|
|
69
|
-
async function scaffold(options) {
|
|
70
|
-
const { projectName, companyName, selectedPlugins, includeStorefront, createGithubRepo, githubOrg, packageManager = 'bun', skipInstall, skipGit, dryRun, registryToken, licenseToken } = options;
|
|
71
|
-
const projectDir = path.resolve(process.cwd(), projectName);
|
|
72
|
-
// 1. Resolve active plugins (always-on core + user-selected)
|
|
73
|
-
const resolvedPluginKeys = (0, plugin_registry_1.resolveActivePluginKeys)(selectedPlugins);
|
|
74
|
-
const alwaysOnNames = plugin_registry_1.ALWAYS_ACTIVE_KEYS.map((k) => (0, plugin_registry_1.getPlugin)(k).displayName);
|
|
75
|
-
if (alwaysOnNames.length > 0) {
|
|
76
|
-
p.log.info(`Always-on core plugins: ${alwaysOnNames.join(', ')}`);
|
|
77
|
-
}
|
|
78
|
-
// 2. Create project directory (abort if it already has content)
|
|
79
|
-
if (await fs.pathExists(projectDir)) {
|
|
80
|
-
const entries = await fs.readdir(projectDir);
|
|
81
|
-
if (entries.length > 0) {
|
|
82
|
-
p.log.error(`Directory "${projectDir}" already exists and is not empty.`);
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// Dry-run: print summary and exit without writing anything
|
|
87
|
-
if (dryRun) {
|
|
88
|
-
const resolvedPlugins = resolvedPluginKeys.map((k) => (0, plugin_registry_1.getPlugin)(k).displayName);
|
|
89
|
-
const fileList = exports.TEMPLATE_FILES.map((f) => ` ${f.output}`).join('\n');
|
|
90
|
-
const demoDataFiles = [
|
|
91
|
-
' server/src/demo-data/products.csv',
|
|
92
|
-
' server/src/demo-data/initial-data.json',
|
|
93
|
-
' server/src/demo-data/images/.gitkeep',
|
|
94
|
-
].join('\n');
|
|
95
|
-
const summary = [
|
|
96
|
-
`Project: ${projectName} → ${projectDir}`,
|
|
97
|
-
'',
|
|
98
|
-
'Files to generate:',
|
|
99
|
-
fileList,
|
|
100
|
-
demoDataFiles,
|
|
101
|
-
' server/src/migrations/ (empty dir)',
|
|
102
|
-
'',
|
|
103
|
-
`Plugins (${resolvedPlugins.length}):`,
|
|
104
|
-
` ${resolvedPlugins.join(', ')}`,
|
|
105
|
-
'',
|
|
106
|
-
`Storefront: ${includeStorefront ? 'yes' : 'no'}`,
|
|
107
|
-
`Install deps with ${packageManager}: ${skipInstall ? 'no' : 'yes'}`,
|
|
108
|
-
`Git init: ${skipGit ? 'no' : 'yes'}`,
|
|
109
|
-
`GitHub repo: ${createGithubRepo ? 'yes' : 'no'}`,
|
|
110
|
-
].join('\n');
|
|
111
|
-
p.note(summary, 'Dry run');
|
|
112
|
-
p.outro('Dry run complete — no files written.');
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const s = p.spinner();
|
|
116
|
-
s.start('Creating project directory...');
|
|
117
|
-
await fs.ensureDir(projectDir);
|
|
118
|
-
// 3. Build template context
|
|
119
|
-
const { context, hbs } = (0, template_renderer_1.buildTemplateContext)(projectName, companyName, selectedPlugins, includeStorefront, {
|
|
120
|
-
registryToken,
|
|
121
|
-
licenseToken,
|
|
122
|
-
});
|
|
123
|
-
// 4. Render and write server files
|
|
124
|
-
s.message('Generating server files...');
|
|
125
|
-
const serverDir = path.join(projectDir, 'server');
|
|
126
|
-
const serverSrcDir = path.join(serverDir, 'src');
|
|
127
|
-
await fs.ensureDir(serverSrcDir);
|
|
128
|
-
for (const { template, output } of exports.TEMPLATE_FILES) {
|
|
129
|
-
const templatePath = (0, template_renderer_1.getTemplatePath)(template);
|
|
130
|
-
const rendered = (0, template_renderer_1.renderTemplate)(templatePath, context, hbs);
|
|
131
|
-
const outputPath = path.join(projectDir, output);
|
|
132
|
-
await fs.ensureDir(path.dirname(outputPath));
|
|
133
|
-
await fs.writeFile(outputPath, rendered);
|
|
134
|
-
}
|
|
135
|
-
// 5. Create demo-data skeleton
|
|
136
|
-
s.message('Creating demo data skeleton...');
|
|
137
|
-
await createDemoData(serverSrcDir);
|
|
138
|
-
// 6. Create migrations directory
|
|
139
|
-
await fs.ensureDir(path.join(serverSrcDir, 'migrations'));
|
|
140
|
-
// 7. Copy storefront (if selected)
|
|
141
|
-
if (includeStorefront) {
|
|
142
|
-
s.message('Copying storefront...');
|
|
143
|
-
try {
|
|
144
|
-
await (0, storefront_copier_1.copyStorefront)(projectDir, {
|
|
145
|
-
mode: 'full-project',
|
|
146
|
-
scenario: 'customer',
|
|
147
|
-
packageName: `${projectName}-storefront`,
|
|
148
|
-
registryToken,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
s.stop('Storefront copy failed.');
|
|
153
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
154
|
-
p.log.warn(`Storefront copy failed — you can set it up manually later. (${message})`);
|
|
155
|
-
s.start('Continuing...');
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
// 8. Install dependencies
|
|
159
|
-
if (!skipInstall) {
|
|
160
|
-
await (0, scaffold_shared_1.installDependencies)(projectDir, packageManager, s);
|
|
161
|
-
}
|
|
162
|
-
// 9. Git init + GitHub repo
|
|
163
|
-
if (!skipGit) {
|
|
164
|
-
await (0, scaffold_shared_1.initRepository)(projectDir, createGithubRepo, githubOrg, s);
|
|
165
|
-
}
|
|
166
|
-
s.stop(`Project "${projectName}" created successfully!`);
|
|
167
|
-
// 10. Print next steps
|
|
168
|
-
const runPrefix = packageManager === 'npm' ? 'npm run' : `${packageManager} run`;
|
|
169
|
-
const steps = [
|
|
170
|
-
`cd ${projectName}`,
|
|
171
|
-
'docker compose up -d',
|
|
172
|
-
`${runPrefix} populate`,
|
|
173
|
-
`${runPrefix} dev`,
|
|
174
|
-
'',
|
|
175
|
-
`Dashboard: http://localhost:3500/dashboard`,
|
|
176
|
-
includeStorefront ? `Storefront: http://localhost:3001` : '',
|
|
177
|
-
].filter(Boolean).join('\n');
|
|
178
|
-
p.note(steps, 'Next steps');
|
|
179
|
-
p.outro('Happy building!');
|
|
180
|
-
}
|
|
181
|
-
function getScenarioDefaultAssetsPath() {
|
|
182
|
-
const candidates = [
|
|
183
|
-
// In dev (monorepo): resolve relative to this file's source location
|
|
184
|
-
path.join(__dirname, '..', '..', 'scenario-default', 'assets'),
|
|
185
|
-
// In published package: bundled during build
|
|
186
|
-
path.join(__dirname, 'assets', 'demo-data'),
|
|
187
|
-
];
|
|
188
|
-
for (const candidate of candidates) {
|
|
189
|
-
if (fs.pathExistsSync(candidate)) {
|
|
190
|
-
return candidate;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
throw new Error('Could not find scenario-default assets. Tried:\n' + candidates.map(p => ` - ${p}`).join('\n'));
|
|
194
|
-
}
|
|
195
|
-
async function createDemoData(serverSrcDir) {
|
|
196
|
-
const assetsDir = getScenarioDefaultAssetsPath();
|
|
197
|
-
const demoDataDir = path.join(serverSrcDir, 'demo-data');
|
|
198
|
-
await fs.ensureDir(demoDataDir);
|
|
199
|
-
await fs.copy(path.join(assetsDir, 'initial-data.json'), path.join(demoDataDir, 'initial-data.json'));
|
|
200
|
-
await fs.copy(path.join(assetsDir, 'products.csv'), path.join(demoDataDir, 'products.csv'));
|
|
201
|
-
await fs.copy(path.join(assetsDir, 'images'), path.join(demoDataDir, 'images'));
|
|
202
|
-
}
|
|
203
|
-
//# sourceMappingURL=scaffolder.js.map
|
|
1
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,o,r){void 0===r&&(r=o);var n=Object.getOwnPropertyDescriptor(t,o);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,r,n)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(){var o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o);return t},o(e)};return function(r){if(r&&r.__esModule)return r;var n={};if(null!=r)for(var s=o(r),i=0;i<s.length;i++)"default"!==s[i]&&e(n,r,s[i]);return t(n,r),n}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.TEMPLATE_FILES=void 0,exports.scaffold=c;const r=o(require("fs-extra")),n=o(require("path")),s=o(require("@clack/prompts")),i=require("./plugin-registry"),a=require("./template-renderer"),u=require("./storefront-copier"),p=require("./scaffold-shared");async function c(e){const{projectName:t,companyName:o,selectedPlugins:c,includeStorefront:l,createGithubRepo:m,githubOrg:g,packageManager:f="bun",skipInstall:h,skipGit:j,dryRun:y,registryToken:v,licenseToken:b}=e,w=n.resolve(process.cwd(),t),E=(0,i.resolveActivePluginKeys)(c),_=i.ALWAYS_ACTIVE_KEYS.map(e=>(0,i.getPlugin)(e).displayName);if(_.length>0&&s.log.info(`Always-on core plugins: ${_.join(", ")}`),await r.pathExists(w)&&(await r.readdir(w)).length>0&&(s.log.error(`Directory "${w}" already exists and is not empty.`),process.exit(1)),y){const e=E.map(e=>(0,i.getPlugin)(e).displayName),o=[`Project: ${t} \u2192 ${w}`,"","Files to generate:",exports.TEMPLATE_FILES.map(e=>` ${e.output}`).join("\n"),[" server/src/demo-data/products.csv"," server/src/demo-data/initial-data.json"," server/src/demo-data/images/.gitkeep"].join("\n")," server/src/migrations/ (empty dir)","",`Plugins (${e.length}):`,` ${e.join(", ")}`,"","Storefront: "+(l?"yes":"no"),`Install deps with ${f}: ${h?"no":"yes"}`,"Git init: "+(j?"no":"yes"),"GitHub repo: "+(m?"yes":"no")].join("\n");return s.note(o,"Dry run"),void s.outro("Dry run complete \u2014 no files written.")}const k=s.spinner();k.start("Creating project directory..."),await r.ensureDir(w);const{context:P,hbs:T}=(0,a.buildTemplateContext)(t,o,c,l,{registryToken:v,licenseToken:b});k.message("Generating server files...");const $=n.join(w,"server"),x=n.join($,"src");await r.ensureDir(x);for(const{template:e,output:t}of exports.TEMPLATE_FILES){const o=(0,a.getTemplatePath)(e),s=(0,a.renderTemplate)(o,P,T),i=n.join(w,t);await r.ensureDir(n.dirname(i)),await r.writeFile(i,s)}if(k.message("Creating demo data skeleton..."),await d(x),await r.ensureDir(n.join(x,"migrations")),l){k.message("Copying storefront...");try{await(0,u.copyStorefront)(w,{mode:"full-project",scenario:"customer",packageName:`${t}-storefront`,registryToken:v})}catch(e){k.stop("Storefront copy failed.");const t=e instanceof Error?e.message:String(e);s.log.warn(`Storefront copy failed \u2014 you can set it up manually later. (${t})`),k.start("Continuing...")}}h||await(0,p.installDependencies)(w,f,k),j||await(0,p.initRepository)(w,m,g,k),k.stop(`Project "${t}" created successfully!`);const D="npm"===f?"npm run":`${f} run`,S=[`cd ${t}`,"docker compose up -d",`${D} populate`,`${D} dev`,"","Dashboard: http://localhost:3500/dashboard",l?"Storefront: http://localhost:3001":""].filter(Boolean).join("\n");s.note(S,"Next steps"),s.outro("Happy building!")}function l(){const e=[n.join(__dirname,"..","..","scenario-default","assets"),n.join(__dirname,"assets","demo-data")];for(const t of e)if(r.pathExistsSync(t))return t;throw new Error("Could not find scenario-default assets. Tried:\n"+e.map(e=>` - ${e}`).join("\n"))}async function d(e){const t=l(),o=n.join(e,"demo-data");await r.ensureDir(o),await r.copy(n.join(t,"initial-data.json"),n.join(o,"initial-data.json")),await r.copy(n.join(t,"products.csv"),n.join(o,"products.csv")),await r.copy(n.join(t,"images"),n.join(o,"images"))}exports.TEMPLATE_FILES=[{template:"vendure-config.ts.hbs",output:"server/src/vendure-config.ts"},{template:"populate.ts.hbs",output:"server/src/populate.ts"},{template:"custom-populate.ts.hbs",output:"server/src/custom-populate.ts"},{template:"index.ts.hbs",output:"server/src/index.ts"},{template:"server-package.json.hbs",output:"server/package.json"},{template:"root-package.json.hbs",output:"package.json"},{template:"env.hbs",output:".env"},{template:"docker-compose.yml.hbs",output:"docker-compose.yml"},{template:"CLAUDE.md.hbs",output:"CLAUDE.md"},{template:"README.md.hbs",output:"README.md"},{template:"tsconfig.root.json.hbs",output:"tsconfig.json"},{template:"tsconfig.server.json.hbs",output:"server/tsconfig.json"},{template:"vite.config.mts.hbs",output:"server/vite.config.mts"},{template:"tsconfig.dashboard.json.hbs",output:"server/tsconfig.dashboard.json"},{template:"environment.d.ts.hbs",output:"server/src/environment.d.ts"},{template:"gitignore.hbs",output:".gitignore"},{template:"npmrc.hbs",output:".npmrc"},{template:"bunfig.toml.hbs",output:"bunfig.toml"}];
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortPackageJson = sortPackageJson;
|
|
4
|
-
/**
|
|
5
|
-
* Sort the dependency blocks of a rendered `package.json` string.
|
|
6
|
-
*
|
|
7
|
-
* The scaffold templates emit `@vendure-platform/*` entries in
|
|
8
|
-
* `PLUGIN_ORDER` (strategy-wrapping order), which is meaningful for
|
|
9
|
-
* the runtime config but reads as random noise in `package.json`.
|
|
10
|
-
* Re-serialise with each `*dependencies` block sorted lexicographically
|
|
11
|
-
* so the generated file is tidy and stable between scaffolds.
|
|
12
|
-
*
|
|
13
|
-
* Top-level key order is preserved as authored in the template.
|
|
14
|
-
*/
|
|
15
|
-
function sortPackageJson(json) {
|
|
16
|
-
const pkg = JSON.parse(json);
|
|
17
|
-
const DEP_KEYS = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
18
|
-
for (const key of DEP_KEYS) {
|
|
19
|
-
const block = pkg[key];
|
|
20
|
-
if (block && typeof block === 'object') {
|
|
21
|
-
pkg[key] = Object.fromEntries(Object.entries(block).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return JSON.stringify(pkg, null, 2) + '\n';
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=sort-package-json.js.map
|
|
1
|
+
"use strict";function e(e){const n=JSON.parse(e),t=["dependencies","devDependencies","peerDependencies","optionalDependencies"];for(const e of t){const t=n[e];t&&"object"==typeof t&&(n[e]=Object.fromEntries(Object.entries(t).sort(([e],[n])=>e<n?-1:e>n?1:0)))}return JSON.stringify(n,null,2)+"\n"}Object.defineProperty(exports,"__esModule",{value:!0}),exports.sortPackageJson=e;
|
|
@@ -1,149 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.copyStorefront = copyStorefront;
|
|
37
|
-
const crypto = __importStar(require("crypto"));
|
|
38
|
-
const fs = __importStar(require("fs-extra"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
const registry_1 = require("./registry");
|
|
41
|
-
/**
|
|
42
|
-
* Copy the bundled storefront from dist/assets/storefront/ into the scaffolded project.
|
|
43
|
-
* Generates a project-scoped `.env.local` (random REVALIDATION_SECRET, optional
|
|
44
|
-
* API URL override, scenario selection) and patches `package.json` `name`.
|
|
45
|
-
*/
|
|
46
|
-
async function copyStorefront(projectDir, options) {
|
|
47
|
-
var _a;
|
|
48
|
-
const bundledStorefrontPath = getBundledStorefrontPath();
|
|
49
|
-
const destPath = options.mode === 'storefront-only'
|
|
50
|
-
? projectDir
|
|
51
|
-
: path.join(projectDir, 'storefront');
|
|
52
|
-
await fs.copy(bundledStorefrontPath, destPath);
|
|
53
|
-
await writeStorefrontEnv(destPath, options);
|
|
54
|
-
await writeStorefrontNpmrc(destPath, options.registryToken);
|
|
55
|
-
// Always ensure `.npmrc` is gitignored, even when no token is in play
|
|
56
|
-
// right now. In `storefront-only` mode the storefront IS the project
|
|
57
|
-
// root, so the only `.gitignore` that protects against committing a
|
|
58
|
-
// tokenised `.npmrc` is the storefront's own. Doing this unconditionally
|
|
59
|
-
// also future-proofs against any future code path that adds a token here.
|
|
60
|
-
await ensureNpmrcGitignored(destPath);
|
|
61
|
-
await patchPackageName(destPath, (_a = options.packageName) !== null && _a !== void 0 ? _a : path.basename(destPath));
|
|
62
|
-
}
|
|
63
|
-
async function ensureNpmrcGitignored(storefrontDir) {
|
|
64
|
-
const gitignorePath = path.join(storefrontDir, '.gitignore');
|
|
65
|
-
let existing = '';
|
|
66
|
-
if (await fs.pathExists(gitignorePath)) {
|
|
67
|
-
existing = await fs.readFile(gitignorePath, 'utf8');
|
|
68
|
-
}
|
|
69
|
-
const lines = existing.split('\n').map((l) => l.trim());
|
|
70
|
-
if (lines.includes('.npmrc') || lines.includes('/.npmrc')) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const trailing = existing === '' || existing.endsWith('\n') ? '' : '\n';
|
|
74
|
-
await fs.writeFile(gitignorePath, existing + trailing + '.npmrc\n');
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* `npm pack` hard-excludes any file named `.npmrc` from tarballs (regardless
|
|
78
|
-
* of `files`/`.npmignore`), so we cannot bundle it. The scope mapping must
|
|
79
|
-
* therefore be written at scaffold time — without it `${pm} install` 401s on
|
|
80
|
-
* `@vendure-platform/*` packages in the storefront subdir. If a registry
|
|
81
|
-
* token is supplied, we also write the `_authToken` line so the storefront
|
|
82
|
-
* install works without any pre-existing `~/.npmrc` setup. The project's
|
|
83
|
-
* `.gitignore` (see `gitignore.hbs`) covers `storefront/.npmrc`, and the
|
|
84
|
-
* storefront's own `.gitignore` (`ensureNpmrcGitignored`) covers the
|
|
85
|
-
* storefront-only layout.
|
|
86
|
-
*/
|
|
87
|
-
async function writeStorefrontNpmrc(storefrontDir, registryToken) {
|
|
88
|
-
const lines = [`@vendure-platform:registry=${(0, registry_1.getRegistryUrl)()}`];
|
|
89
|
-
if (registryToken) {
|
|
90
|
-
lines.push(`//${(0, registry_1.getRegistryHostname)()}/:_authToken=${registryToken}`);
|
|
91
|
-
}
|
|
92
|
-
await fs.writeFile(path.join(storefrontDir, '.npmrc'), lines.join('\n') + '\n');
|
|
93
|
-
}
|
|
94
|
-
async function writeStorefrontEnv(storefrontDir, options) {
|
|
95
|
-
var _a, _b;
|
|
96
|
-
const secret = crypto.randomBytes(32).toString('hex');
|
|
97
|
-
// Default to `customer` — that's the only scenario registered in the
|
|
98
|
-
// copied `src/config/scenario.ts`. Using `default` triggers a warning at
|
|
99
|
-
// boot and falls back to `customer` anyway, so just write the right value.
|
|
100
|
-
const scenario = (_a = options.scenario) !== null && _a !== void 0 ? _a : 'customer';
|
|
101
|
-
const apiUrl = (_b = options.apiUrl) !== null && _b !== void 0 ? _b : '';
|
|
102
|
-
const lines = [
|
|
103
|
-
'# Generated by @vendure-platform/create. Safe to edit.',
|
|
104
|
-
'',
|
|
105
|
-
'# Used to authenticate revalidation webhooks. Treat as a secret.',
|
|
106
|
-
`REVALIDATION_SECRET=${secret}`,
|
|
107
|
-
'',
|
|
108
|
-
`NEXT_PUBLIC_SCENARIO=${scenario}`,
|
|
109
|
-
'',
|
|
110
|
-
];
|
|
111
|
-
if (apiUrl) {
|
|
112
|
-
lines.push('# Vendure Shop API URL.', `VENDURE_SHOP_API_URL=${apiUrl}`, '');
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
lines.push('# Vendure Shop API URL. Defaults to http://localhost:3500/shop-api when unset.', '# VENDURE_SHOP_API_URL=https://shop.example.com/shop-api', '');
|
|
116
|
-
}
|
|
117
|
-
await fs.writeFile(path.join(storefrontDir, '.env.local'), lines.join('\n'));
|
|
118
|
-
}
|
|
119
|
-
async function patchPackageName(storefrontDir, name) {
|
|
120
|
-
const pkgPath = path.join(storefrontDir, 'package.json');
|
|
121
|
-
if (!(await fs.pathExists(pkgPath)))
|
|
122
|
-
return;
|
|
123
|
-
const pkg = await fs.readJson(pkgPath);
|
|
124
|
-
pkg.name = sanitizePackageName(name);
|
|
125
|
-
await fs.writeJson(pkgPath, pkg, { spaces: 4 });
|
|
126
|
-
}
|
|
127
|
-
function sanitizePackageName(name) {
|
|
128
|
-
return name
|
|
129
|
-
.toLowerCase()
|
|
130
|
-
.replace(/[^a-z0-9._-]/g, '-')
|
|
131
|
-
.replace(/^-+|-+$/g, '')
|
|
132
|
-
|| 'storefront';
|
|
133
|
-
}
|
|
134
|
-
function getBundledStorefrontPath() {
|
|
135
|
-
// Installed/published package: __dirname is dist/, bundled storefront at dist/assets/storefront/
|
|
136
|
-
// Local dev (running from src/): __dirname is src/, bundled storefront at dist/assets/storefront/
|
|
137
|
-
const candidates = [
|
|
138
|
-
path.join(__dirname, 'assets', 'storefront'),
|
|
139
|
-
path.join(__dirname, '..', 'dist', 'assets', 'storefront'),
|
|
140
|
-
];
|
|
141
|
-
for (const candidate of candidates) {
|
|
142
|
-
if (fs.existsSync(candidate)) {
|
|
143
|
-
return candidate;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
throw new Error('Bundled storefront not found. Build @vendure-platform/create first ' +
|
|
147
|
-
'(`bunx nx run @vendure-platform/create:build`).');
|
|
148
|
-
}
|
|
149
|
-
//# sourceMappingURL=storefront-copier.js.map
|
|
1
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||function(){var n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},n(e)};return function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var a=n(r),i=0;i<a.length;i++)"default"!==a[i]&&e(o,r,a[i]);return t(o,r),o}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.copyStorefront=s;const r=n(require("crypto")),o=n(require("fs-extra")),a=n(require("path")),i=require("./registry");async function s(e,t){var n;const r=d(),i="storefront-only"===t.mode?e:a.join(e,"storefront");await o.copy(r,i),await l(i,t),await u(i,t.registryToken),await c(i),await f(i,null!==(n=t.packageName)&&void 0!==n?n:a.basename(i))}async function c(e){const t=a.join(e,".gitignore");let n="";await o.pathExists(t)&&(n=await o.readFile(t,"utf8"));const r=n.split("\n").map(e=>e.trim());if(r.includes(".npmrc")||r.includes("/.npmrc"))return;const i=""===n||n.endsWith("\n")?"":"\n";await o.writeFile(t,n+i+".npmrc\n")}async function u(e,t){const n=[`@vendure-platform:registry=${(0,i.getRegistryUrl)()}`];t&&n.push(`//${(0,i.getRegistryHostname)()}/:_authToken=${t}`),await o.writeFile(a.join(e,".npmrc"),n.join("\n")+"\n")}async function l(e,t){var n,i;const s=r.randomBytes(32).toString("hex"),c=null!==(n=t.scenario)&&void 0!==n?n:"customer",u=null!==(i=t.apiUrl)&&void 0!==i?i:"",l=["# Generated by @vendure-platform/create. Safe to edit.","","# Used to authenticate revalidation webhooks. Treat as a secret.",`REVALIDATION_SECRET=${s}`,"",`NEXT_PUBLIC_SCENARIO=${c}`,""];u?l.push("# Vendure Shop API URL.",`VENDURE_SHOP_API_URL=${u}`,""):l.push("# Vendure Shop API URL. Defaults to http://localhost:3500/shop-api when unset.","# VENDURE_SHOP_API_URL=https://shop.example.com/shop-api",""),await o.writeFile(a.join(e,".env.local"),l.join("\n"))}async function f(e,t){const n=a.join(e,"package.json");if(!await o.pathExists(n))return;const r=await o.readJson(n);r.name=p(t),await o.writeJson(n,r,{spaces:4})}function p(e){return e.toLowerCase().replace(/[^a-z0-9._-]/g,"-").replace(/^-+|-+$/g,"")||"storefront"}function d(){const e=[a.join(__dirname,"assets","storefront"),a.join(__dirname,"..","dist","assets","storefront")];for(const t of e)if(o.existsSync(t))return t;throw new Error("Bundled storefront not found. Build @vendure-platform/create first (`bunx nx run @vendure-platform/create:build`).")}
|