Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dist
/public/build
tsconfig.tsbuildinfo
data-mocks/
*.tgz

# Debug
npm-debug.log*
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ To get started, run the following command:
```bash
npm create tinker-stack
```

### Local testing

To verify the generator before publishing:

1. Run `npm pack` in this repository to produce a tarball (for example `create-tinker-stack-0.2.2.tgz`).
2. In a temporary directory, execute `npx --yes create-tinker-stack@file:/absolute/path/to/create-tinker-stack-0.2.2.tgz`.
- Replace the path with the absolute path to the tarball from step 1 (npm `create` does not currently support `file:` specifiers).
24 changes: 17 additions & 7 deletions create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const cwd = path.dirname(path.dirname(__filename));
const templateDir = path.join(cwd, 'template');
const packageRoot = path.dirname(path.dirname(__filename));
const templateDir = path.join(packageRoot, 'template');

function targetFromArgv() {
const argv = process.argv.slice(2);
Expand All @@ -29,13 +29,23 @@ function normalizeOptions(input = {}) {
opts.project ||
targetFromArgv();

const resolvedCwd =
typeof opts.cwd === 'string' && opts.cwd.length > 0
? path.resolve(process.cwd(), opts.cwd)
: process.cwd();

const resolvedTargetDir =
typeof targetDir === 'string' && targetDir.length > 0
? path.resolve(resolvedCwd, targetDir)
: undefined;

return {
cwd,
templateDir: templateDir, // always use the built-in template
targetDir,
...opts,
targetDir: resolvedTargetDir,
debug: !!opts.debug,
install: opts.install ?? true,
...opts
cwd: resolvedCwd,
templateDir // always use the built-in template
};
}

Expand All @@ -56,4 +66,4 @@ async function main(...args) {
await createMain(opts);
}

main().catch(console.error.bind(console));
main().catch(console.error.bind(console));
34 changes: 31 additions & 3 deletions tests/generator.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ describe('create-tinker-stack generator', () => {
'scaffolds project and passes build checks',
async () => {
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'tinker-stack-'));
const projectDir = path.join(tempRoot, 'demo-app');
const appFolder = 'demo-app';
const projectDir = path.join(tempRoot, appFolder);

try {
await runCommand('node', [CLI_ENTRY, projectDir], {
await runCommand('node', [CLI_ENTRY, appFolder], {
env: {
...process.env,
CI: '1',
SKIP_SETUP: '1',
SKIP_FORMAT: '1'
}
},
cwd: tempRoot
});

const packageJson = JSON.parse(await readFile(path.join(projectDir, 'package.json'), 'utf8'));
Expand All @@ -55,4 +57,30 @@ describe('create-tinker-stack generator', () => {
},
10 * 60 * 1000
);

test(
'scaffolds into the current working directory when no target is provided',
async () => {
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'tinker-stack-'));
const expectedDir = path.join(tempRoot, 'demo-title');

try {
await runCommand('node', [CLI_ENTRY], {
env: {
...process.env,
CI: '1',
SKIP_SETUP: '1',
SKIP_FORMAT: '1'
},
cwd: tempRoot
});

const packageJson = JSON.parse(await readFile(path.join(expectedDir, 'package.json'), 'utf8'));
expect(packageJson.name).toBe('demo-title');
} finally {
await rm(tempRoot, { recursive: true, force: true });
}
},
2 * 60 * 1000
);
});