Skip to content

Commit

Permalink
[#121] Update vite initialization to folder for easier updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bterone committed Aug 11, 2023
1 parent 92a0ec7 commit 36f3d09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
25 changes: 19 additions & 6 deletions packages/cli-tool/src/template/initialize-vite-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const replaceAppNameInFiles = ['package.json', 'index.html'];

type InitViteOptions = {
dest: string;
templateReference: string; // Git branch name or path to a local template folder
appName: string;
branch: string;
};

const downloadTemplateRepository = (
Expand All @@ -23,7 +23,7 @@ const downloadTemplateRepository = (
{
gitHubAccount: TEMPLATE_OWNER,
repositoryName: TEMPLATE_REPO,
branch: options.branch,
branch: options.templateReference,
},
options.appName,
options.dest,
Expand All @@ -40,9 +40,20 @@ const extractViteTemplateFolder = (options: InitViteOptions): Promise<void> => {
);
};

const copyTemplateFiles = (options: InitViteOptions): Promise<void> => {
CliUx.ux.info('Copying template source files...');
const branchPath = options.templateReference.replace('/', '-');

return runCommand(
'cp',
['-r', `${TEMPLATE_REPO}-${branchPath}/vite-template/`, options.appName],
options.dest,
);
};

const renameFolder = (options: InitViteOptions): Promise<void> => {
CliUx.ux.info('Rename your app folder...');
const branchPath = options.branch.replace('/', '-');
const branchPath = options.templateReference.replace('/', '-');

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

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

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

const initializeViteApp = async(options: InitViteOptions): Promise<void> => {
return downloadTemplateRepository(options)
.then(() => extractViteTemplateFolder(options))
// If given a branch name, use
// return downloadTemplateRepository(options)
// .then(()=> extractViteTemplateFolder(options))
return copyTemplateFiles(options)
.then(() => renameFolder(options))
.then(() => replaceAppName(options))
.then(() => npmInstall(options))
Expand Down
6 changes: 2 additions & 4 deletions packages/cli-tool/test/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import { tailwindCssTestData } from '../../add-ons/ui-framework/tailwind-css';
import { gitHubTestData, gitLabTestData, noVersionControlTestData } from '../../add-ons/version-control';
import { TestScenario } from '../../helpers/test-scenario';

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

Expand Down

0 comments on commit 36f3d09

Please sign in to comment.