Skip to content

Commit

Permalink
feat: add dynamic path resolving for template directories for npm and…
Browse files Browse the repository at this point in the history
… local environments
  • Loading branch information
maneike committed Oct 30, 2024
1 parent ece8497 commit 6908dba
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"short-waves-flow",
"silent-rocks-design",
"small-ghosts-listen",
"ten-swans-ring",
"thirty-clocks-move",
"warm-gorillas-yawn",
"warm-peas-behave",
Expand Down
6 changes: 6 additions & 0 deletions .changeset/ten-swans-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tonik/create-stapler-app-core': minor
'@tonik/create-stapler-app': minor
---

Add dynamic handling for template files directories
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tonik/create-stapler-app

## 0.1.0-alpha.17

### Minor Changes

- Add dynamic handling for template files directories

## 0.1.0-alpha.16

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonik/create-stapler-app",
"version": "0.1.0-alpha.16",
"version": "0.1.0-alpha.17",
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"bin": {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tonik/create-stapler-app-core

## 0.2.0-alpha.1

### Minor Changes

- Add dynamic handling for template files directories

## 0.2.0-alpha.0

### Minor Changes
Expand Down
6 changes: 5 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "@tonik/create-stapler-app-core",
"version": "0.2.0-alpha.0",
"version": "0.2.0-alpha.1",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"templates"
],
"scripts": {
"build": "tsup index.ts --out-dir ./dist --format esm",
"dev": "tsc -w"
Expand Down
8 changes: 2 additions & 6 deletions packages/core/utils/docs/create.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import path from 'path';
import { fileURLToPath } from 'node:url';
import { docFiles } from '../../templates/docs/installConfig';
import { templateGenerator } from '../generator/generator';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { getTemplateDirectory } from '../shared/getTemplateDirectory';

export const createDocFiles = () => {
console.log('🖇️ Writing docs...');
const templateDirectory = path.join(__dirname, '../../core/templates/docs/files');
const templateDirectory = getTemplateDirectory(`/templates/docs/files`);
const destinationDirectory = process.cwd();

templateGenerator(docFiles, templateDirectory, destinationDirectory);
Expand Down
28 changes: 28 additions & 0 deletions packages/core/utils/shared/getTemplateDirectory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export const getTemplateDirectory = (directory: string) => {
// Function to determine the environment
const getEnvironment = () => {
if (__dirname.includes('/.npm/')) {
return 'npx';
} else if (__dirname.includes('/.pnpm/')) {
return 'pnpm';
}
return 'local';
};

let templateDirectory;
switch (getEnvironment()) {
case 'local':
templateDirectory = path.join(__dirname, '../../core/', directory);
break;
default:
templateDirectory = path.join(__dirname, '../', directory);
}

return templateDirectory;
};
7 changes: 2 additions & 5 deletions packages/core/utils/supabase/install.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'node:url';
import { supabaseFiles } from '../../templates/supabase/installConfig';
import { templateGenerator } from '../generator/generator';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { getTemplateDirectory } from '../shared/getTemplateDirectory';

const supabaseLogin = () => {
console.log('🖇️ Logging into Supabase...');
Expand Down Expand Up @@ -59,7 +56,7 @@ export const installSupabase = async (destinationDirectory: string) => {

console.log('🖇️ Adding Supabase Files...');

const templateDirectory = path.join(__dirname, '../../core/templates/supabase/files');
const templateDirectory = getTemplateDirectory(`/templates/supabase/files/`);

templateGenerator(supabaseFiles, templateDirectory, destinationDirectory);
// add "supabase/**" to pnpm-workspace.yaml
Expand Down

0 comments on commit 6908dba

Please sign in to comment.