Skip to content

Commit f265315

Browse files
committed
[#121] Update vite initialization to folder for easier updates
1 parent 92a0ec7 commit f265315

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

packages/cli-tool/src/template/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const initializeTemplate = async({
2222
await initializeViteApp({
2323
appName,
2424
dest,
25-
branch: templateReference,
25+
templateReference,
2626
});
2727

2828
return;

packages/cli-tool/src/template/initialize-vite-app.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const replaceAppNameInFiles = ['package.json', 'index.html'];
1010

1111
type InitViteOptions = {
1212
dest: string;
13+
templateReference: string; // Git branch name or path to a local template folder
1314
appName: string;
14-
branch: string;
1515
};
1616

1717
const downloadTemplateRepository = (
@@ -23,7 +23,7 @@ const downloadTemplateRepository = (
2323
{
2424
gitHubAccount: TEMPLATE_OWNER,
2525
repositoryName: TEMPLATE_REPO,
26-
branch: options.branch,
26+
branch: options.templateReference,
2727
},
2828
options.appName,
2929
options.dest,
@@ -40,9 +40,20 @@ const extractViteTemplateFolder = (options: InitViteOptions): Promise<void> => {
4040
);
4141
};
4242

43+
const copyTemplateFiles = (options: InitViteOptions): Promise<void> => {
44+
CliUx.ux.info('Copying template source files...');
45+
const branchPath = options.templateReference.replace('/', '-');
46+
47+
return runCommand(
48+
'cp',
49+
['-r', `${TEMPLATE_REPO}-${branchPath}/vite-template/`, options.appName],
50+
options.dest,
51+
);
52+
};
53+
4354
const renameFolder = (options: InitViteOptions): Promise<void> => {
4455
CliUx.ux.info('Rename your app folder...');
45-
const branchPath = options.branch.replace('/', '-');
56+
const branchPath = options.templateReference.replace('/', '-');
4657

4758
return runCommand(
4859
'mv',
@@ -69,7 +80,7 @@ const npmInstall = (options: InitViteOptions): Promise<void> => {
6980

7081
const cleanTemporaryFiles = (options: InitViteOptions): Promise<void> => {
7182
CliUx.ux.info('Remove zip and unwanted files...');
72-
const branchPath = options.branch.replace('/', '-');
83+
const branchPath = options.templateReference.replace('/', '-');
7384

7485
// Remove the archive
7586
return runCommand('rm', [`${options.appName}.gz`], options.dest).then(() => {
@@ -83,8 +94,10 @@ const cleanTemporaryFiles = (options: InitViteOptions): Promise<void> => {
8394
};
8495

8596
const initializeViteApp = async(options: InitViteOptions): Promise<void> => {
86-
return downloadTemplateRepository(options)
87-
.then(() => extractViteTemplateFolder(options))
97+
// If given a branch name, use
98+
// return downloadTemplateRepository(options)
99+
// .then(()=> extractViteTemplateFolder(options))
100+
return copyTemplateFiles(options)
88101
.then(() => renameFolder(options))
89102
.then(() => replaceAppName(options))
90103
.then(() => npmInstall(options))

packages/cli-tool/test/commands/generate/index.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import { tailwindCssTestData } from '../../add-ons/ui-framework/tailwind-css';
88
import { gitHubTestData, gitLabTestData, noVersionControlTestData } from '../../add-ons/version-control';
99
import { TestScenario } from '../../helpers/test-scenario';
1010

11-
const craTemplateReference = `file:./react-templates/packages/cra-template`;
12-
// TODO: Adjust viteTemplateReference to use commit hash of development branch for vite template
13-
// https://github.com/nimblehq/react-templates/commit/52288d1e5e560bcc717f760f1fd19f7cb1b0085e
14-
const viteTemplateReference = '52288d1e5e560bcc717f760f1fd19f7cb1b0085e';
11+
const craTemplateReference = 'file:./react-templates/packages/cra-template';
12+
const viteTemplateReference = 'file:./react-templates/packages/vite-template';
1513
const projectName = 'test-app';
1614
const testFolderPath = '../../../';
1715

0 commit comments

Comments
 (0)