@tishlang/create-tish-app 1.0.7
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/index.js +101 -0
- package/package.json +25 -0
package/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const projectName = process.argv[2] || getProjectNameFromCwd();
|
|
8
|
+
|
|
9
|
+
function getProjectNameFromCwd() {
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const base = path.basename(cwd);
|
|
12
|
+
if (base && base !== '.' && !fs.existsSync(path.join(cwd, 'src'))) {
|
|
13
|
+
return base;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function prompt(question) {
|
|
19
|
+
const readline = require('readline');
|
|
20
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
21
|
+
return new Promise(resolve => {
|
|
22
|
+
rl.question(question, answer => {
|
|
23
|
+
rl.close();
|
|
24
|
+
resolve(answer.trim());
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function main() {
|
|
30
|
+
let name = projectName;
|
|
31
|
+
if (!name) {
|
|
32
|
+
name = await prompt('Project name: ');
|
|
33
|
+
if (!name) {
|
|
34
|
+
console.error('Please provide a project name: npx @tishlang/create-tish-app my-app');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const dir = path.resolve(process.cwd(), name);
|
|
40
|
+
if (fs.existsSync(dir)) {
|
|
41
|
+
console.error(`Directory already exists: ${dir}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
46
|
+
fs.mkdirSync(path.join(dir, 'src'), { recursive: true });
|
|
47
|
+
|
|
48
|
+
const safeName = name.replace(/[^a-z0-9-]/gi, '-').replace(/-+/g, '-').toLowerCase() || 'tish-app';
|
|
49
|
+
const files = {
|
|
50
|
+
'src/main.tish': `// ${name} - Tish app
|
|
51
|
+
let message = "Hello, Tish!"
|
|
52
|
+
console.log(message)
|
|
53
|
+
`,
|
|
54
|
+
'tish.yaml': `name: ${safeName}
|
|
55
|
+
`,
|
|
56
|
+
'package.json': JSON.stringify({
|
|
57
|
+
name: safeName,
|
|
58
|
+
version: '0.1.0',
|
|
59
|
+
private: true,
|
|
60
|
+
tish: { source: './src/main.tish' },
|
|
61
|
+
}, null, 2),
|
|
62
|
+
'.gitignore': `# Build output
|
|
63
|
+
/tish_out
|
|
64
|
+
*.exe
|
|
65
|
+
`,
|
|
66
|
+
'README.md': `# ${name}
|
|
67
|
+
|
|
68
|
+
A [Tish](https://github.com/tishlang/tish) project.
|
|
69
|
+
|
|
70
|
+
## Run (interpret)
|
|
71
|
+
|
|
72
|
+
\`\`\`bash
|
|
73
|
+
npx @tishlang/tish run src/main.tish
|
|
74
|
+
# or after installing: tish run src/main.tish
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
## Compile to native
|
|
78
|
+
|
|
79
|
+
\`\`\`bash
|
|
80
|
+
npx @tishlang/tish compile src/main.tish -o app
|
|
81
|
+
./app
|
|
82
|
+
\`\`\`
|
|
83
|
+
`,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
for (const [file, content] of Object.entries(files)) {
|
|
87
|
+
fs.writeFileSync(path.join(dir, file), content, 'utf8');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log(`Created ${name} at ${dir}`);
|
|
91
|
+
console.log('');
|
|
92
|
+
console.log('Next steps:');
|
|
93
|
+
console.log(` cd ${name}`);
|
|
94
|
+
console.log(' npx @tishlang/tish run src/main.tish');
|
|
95
|
+
console.log(' # or: npx @tishlang/tish compile src/main.tish -o app && ./app');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main().catch(err => {
|
|
99
|
+
console.error(err);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tishlang/create-tish-app",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Scaffold a new Tish project",
|
|
5
|
+
"license": "SEE LICENSE IN ../../../LICENSE",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/tishlang/tish.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"create-tish-app": "index.js"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=14"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"tish",
|
|
21
|
+
"create",
|
|
22
|
+
"scaffold",
|
|
23
|
+
"template"
|
|
24
|
+
]
|
|
25
|
+
}
|