create-analog 0.1.6 → 0.1.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 CHANGED
@@ -1,27 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // @ts-check
4
- import fs from 'node:fs'
5
- import path from 'node:path'
6
- import { fileURLToPath } from 'node:url'
7
- import minimist from 'minimist'
8
- import prompts from 'prompts'
9
- import {
10
- blue,
11
- cyan,
12
- green,
13
- lightRed,
14
- magenta,
15
- red,
16
- reset,
17
- yellow
18
- } from 'kolorist'
19
- import { execSync } from 'node:child_process'
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import minimist from 'minimist';
8
+ import prompts from 'prompts';
9
+ import { red, reset, yellow } from 'kolorist';
10
+ import { execSync } from 'node:child_process';
20
11
 
21
12
  // Avoids autoconversion to number of the project name by defining that the args
22
13
  // non associated with an option ( _ ) needs to be parsed as a string. See #4606
23
- const argv = minimist(process.argv.slice(2), { string: ['_'] })
24
- const cwd = process.cwd()
14
+ const argv = minimist(process.argv.slice(2), { string: ['_'] });
15
+ const cwd = process.cwd();
25
16
 
26
17
  const APPS = [
27
18
  {
@@ -31,29 +22,29 @@ const APPS = [
31
22
  {
32
23
  name: 'angular-v14',
33
24
  display: 'TypeScript',
34
- color: yellow
35
- }
36
- ]
37
- }
38
- ]
25
+ color: yellow,
26
+ },
27
+ ],
28
+ },
29
+ ];
39
30
 
40
31
  const TEMPLATES = APPS.map(
41
32
  (f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
42
- ).reduce((a, b) => a.concat(b), [])
33
+ ).reduce((a, b) => a.concat(b), []);
43
34
 
44
35
  const renameFiles = {
45
- _gitignore: '.gitignore'
46
- }
36
+ _gitignore: '.gitignore',
37
+ };
47
38
 
48
39
  async function init() {
49
- let targetDir = formatTargetDir(argv._[0])
50
- let template = argv.template || argv.t
40
+ let targetDir = formatTargetDir(argv._[0]);
41
+ let template = argv.template || argv.t;
51
42
 
52
- const defaultTargetDir = 'analog-project'
43
+ const defaultTargetDir = 'analog-project';
53
44
  const getProjectName = () =>
54
- targetDir === '.' ? path.basename(path.resolve()) : targetDir
45
+ targetDir === '.' ? path.basename(path.resolve()) : targetDir;
55
46
 
56
- let result = {}
47
+ let result = {};
57
48
 
58
49
  try {
59
50
  result = await prompts(
@@ -64,8 +55,8 @@ async function init() {
64
55
  message: reset('Project name:'),
65
56
  initial: defaultTargetDir,
66
57
  onState: (state) => {
67
- targetDir = formatTargetDir(state.value) || defaultTargetDir
68
- }
58
+ targetDir = formatTargetDir(state.value) || defaultTargetDir;
59
+ },
69
60
  },
70
61
  {
71
62
  type: () =>
@@ -75,16 +66,16 @@ async function init() {
75
66
  (targetDir === '.'
76
67
  ? 'Current directory'
77
68
  : `Target directory "${targetDir}"`) +
78
- ` is not empty. Remove existing files and continue?`
69
+ ` is not empty. Remove existing files and continue?`,
79
70
  },
80
71
  {
81
72
  type: (_, { overwrite } = {}) => {
82
73
  if (overwrite === false) {
83
- throw new Error(red('✖') + ' Operation cancelled')
74
+ throw new Error(red('✖') + ' Operation cancelled');
84
75
  }
85
- return null
76
+ return null;
86
77
  },
87
- name: 'overwriteChecker'
78
+ name: 'overwriteChecker',
88
79
  },
89
80
  {
90
81
  type: () => (isValidPackageName(getProjectName()) ? null : 'text'),
@@ -92,7 +83,7 @@ async function init() {
92
83
  message: reset('Package name:'),
93
84
  initial: () => toValidPackageName(getProjectName()),
94
85
  validate: (dir) =>
95
- isValidPackageName(dir) || 'Invalid package.json name'
86
+ isValidPackageName(dir) || 'Invalid package.json name',
96
87
  },
97
88
  {
98
89
  type: template && TEMPLATES.includes(template) ? null : 'select',
@@ -105,12 +96,12 @@ async function init() {
105
96
  : reset('Select a template:'),
106
97
  initial: 0,
107
98
  choices: APPS.map((framework) => {
108
- const frameworkColor = framework.color
99
+ const frameworkColor = framework.color;
109
100
  return {
110
101
  title: frameworkColor(framework.name),
111
- value: framework
112
- }
113
- })
102
+ value: framework,
103
+ };
104
+ }),
114
105
  },
115
106
  {
116
107
  type: (framework) =>
@@ -120,107 +111,101 @@ async function init() {
120
111
  // @ts-ignore
121
112
  choices: (framework) =>
122
113
  framework.variants.map((variant) => {
123
- const variantColor = variant.color
114
+ const variantColor = variant.color;
124
115
  return {
125
116
  title: variantColor(variant.name),
126
- value: variant.name
127
- }
128
- })
129
- }
117
+ value: variant.name,
118
+ };
119
+ }),
120
+ },
130
121
  ],
131
122
  {
132
123
  onCancel: () => {
133
- throw new Error(red('✖') + ' Operation cancelled')
134
- }
124
+ throw new Error(red('✖') + ' Operation cancelled');
125
+ },
135
126
  }
136
- )
127
+ );
137
128
  } catch (cancelled) {
138
- console.log(cancelled.message)
139
- return
129
+ console.log(cancelled.message);
130
+ return;
140
131
  }
141
132
 
142
133
  // user choice associated with prompts
143
- const { framework, overwrite, packageName, variant } = result
134
+ const { framework, overwrite, packageName, variant } = result;
144
135
 
145
- const root = path.join(cwd, targetDir)
136
+ const root = path.join(cwd, targetDir);
146
137
 
147
138
  if (overwrite) {
148
- emptyDir(root)
139
+ emptyDir(root);
149
140
  } else if (!fs.existsSync(root)) {
150
- fs.mkdirSync(root, { recursive: true })
141
+ fs.mkdirSync(root, { recursive: true });
151
142
  }
152
143
 
153
144
  // determine template
154
- template = variant || framework || template
145
+ template = variant || framework || template;
155
146
 
156
- console.log(`\nScaffolding project in ${root}...`)
147
+ console.log(`\nScaffolding project in ${root}...`);
157
148
 
158
149
  const templateDir = path.resolve(
159
150
  fileURLToPath(import.meta.url),
160
151
  '..',
161
152
  `template-${template}`
162
- )
153
+ );
163
154
 
164
155
  const write = (file, content) => {
165
156
  const targetPath = renameFiles[file]
166
157
  ? path.join(root, renameFiles[file])
167
- : path.join(root, file)
158
+ : path.join(root, file);
168
159
  if (content) {
169
- fs.writeFileSync(targetPath, content)
160
+ fs.writeFileSync(targetPath, content);
170
161
  } else {
171
- copy(path.join(templateDir, file), targetPath)
162
+ copy(path.join(templateDir, file), targetPath);
172
163
  }
173
- }
164
+ };
174
165
 
175
- const files = fs.readdirSync(templateDir)
166
+ const files = fs.readdirSync(templateDir);
176
167
  for (const file of files.filter((f) => f !== 'package.json')) {
177
- write(file)
168
+ write(file);
178
169
  }
179
170
 
171
+ const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
172
+ const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
180
173
  const pkg = JSON.parse(
181
174
  fs.readFileSync(path.join(templateDir, `package.json`), 'utf-8')
182
- )
175
+ );
183
176
 
184
- pkg.name = packageName || getProjectName()
177
+ pkg.name = packageName || getProjectName();
178
+ pkg.scripts.start = getStartCommand(pkgManager);
185
179
 
186
- write('package.json', JSON.stringify(pkg, null, 2))
180
+ write('package.json', JSON.stringify(pkg, null, 2));
187
181
 
188
182
  console.log(`\nInitializing git repository:`);
189
- execSync(`git init ${targetDir} && cd ${targetDir} && git add . && git commit -m "initial commit"`);
183
+ execSync(
184
+ `git init ${targetDir} && cd ${targetDir} && git add . && git commit -m "initial commit"`
185
+ );
190
186
 
191
- const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent)
192
- const pkgManager = pkgInfo ? pkgInfo.name : 'npm'
193
-
194
- console.log(`\nDone. Now run:\n`)
187
+ console.log(`\nDone. Now run:\n`);
195
188
  if (root !== cwd) {
196
- console.log(` cd ${path.relative(cwd, root)}`)
197
- }
198
- switch (pkgManager) {
199
- case 'yarn':
200
- console.log(' yarn')
201
- console.log(' yarn dev')
202
- break
203
- default:
204
- console.log(` ${pkgManager} install`)
205
- console.log(` ${pkgManager} run dev`)
206
- break
189
+ console.log(` cd ${path.relative(cwd, root)}`);
207
190
  }
208
- console.log()
191
+ console.log(` ${getInstallCommand(pkgManager)}`);
192
+ console.log(` ${getStartCommand(pkgManager)}`);
193
+ console.log();
209
194
  }
210
195
 
211
196
  /**
212
197
  * @param {string | undefined} targetDir
213
198
  */
214
199
  function formatTargetDir(targetDir) {
215
- return targetDir?.trim().replace(/\/+$/g, '')
200
+ return targetDir?.trim().replace(/\/+$/g, '');
216
201
  }
217
202
 
218
203
  function copy(src, dest) {
219
- const stat = fs.statSync(src)
204
+ const stat = fs.statSync(src);
220
205
  if (stat.isDirectory()) {
221
- copyDir(src, dest)
206
+ copyDir(src, dest);
222
207
  } else {
223
- fs.copyFileSync(src, dest)
208
+ fs.copyFileSync(src, dest);
224
209
  }
225
210
  }
226
211
 
@@ -230,7 +215,7 @@ function copy(src, dest) {
230
215
  function isValidPackageName(projectName) {
231
216
  return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
232
217
  projectName
233
- )
218
+ );
234
219
  }
235
220
 
236
221
  /**
@@ -242,7 +227,7 @@ function toValidPackageName(projectName) {
242
227
  .toLowerCase()
243
228
  .replace(/\s+/g, '-')
244
229
  .replace(/^[._]/, '')
245
- .replace(/[^a-z0-9-~]+/g, '-')
230
+ .replace(/[^a-z0-9-~]+/g, '-');
246
231
  }
247
232
 
248
233
  /**
@@ -250,11 +235,11 @@ function toValidPackageName(projectName) {
250
235
  * @param {string} destDir
251
236
  */
252
237
  function copyDir(srcDir, destDir) {
253
- fs.mkdirSync(destDir, { recursive: true })
238
+ fs.mkdirSync(destDir, { recursive: true });
254
239
  for (const file of fs.readdirSync(srcDir)) {
255
- const srcFile = path.resolve(srcDir, file)
256
- const destFile = path.resolve(destDir, file)
257
- copy(srcFile, destFile)
240
+ const srcFile = path.resolve(srcDir, file);
241
+ const destFile = path.resolve(destDir, file);
242
+ copy(srcFile, destFile);
258
243
  }
259
244
  }
260
245
 
@@ -262,8 +247,8 @@ function copyDir(srcDir, destDir) {
262
247
  * @param {string} path
263
248
  */
264
249
  function isEmpty(path) {
265
- const files = fs.readdirSync(path)
266
- return files.length === 0 || (files.length === 1 && files[0] === '.git')
250
+ const files = fs.readdirSync(path);
251
+ return files.length === 0 || (files.length === 1 && files[0] === '.git');
267
252
  }
268
253
 
269
254
  /**
@@ -271,10 +256,10 @@ function isEmpty(path) {
271
256
  */
272
257
  function emptyDir(dir) {
273
258
  if (!fs.existsSync(dir)) {
274
- return
259
+ return;
275
260
  }
276
261
  for (const file of fs.readdirSync(dir)) {
277
- fs.rmSync(path.resolve(dir, file), { recursive: true, force: true })
262
+ fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
278
263
  }
279
264
  }
280
265
 
@@ -283,15 +268,31 @@ function emptyDir(dir) {
283
268
  * @returns object | undefined
284
269
  */
285
270
  function pkgFromUserAgent(userAgent) {
286
- if (!userAgent) return undefined
287
- const pkgSpec = userAgent.split(' ')[0]
288
- const pkgSpecArr = pkgSpec.split('/')
271
+ if (!userAgent) return undefined;
272
+ const pkgSpec = userAgent.split(' ')[0];
273
+ const pkgSpecArr = pkgSpec.split('/');
289
274
  return {
290
275
  name: pkgSpecArr[0],
291
- version: pkgSpecArr[1]
292
- }
276
+ version: pkgSpecArr[1],
277
+ };
278
+ }
279
+
280
+ /**
281
+ * @param {string} pkgManager
282
+ * @returns string
283
+ */
284
+ function getInstallCommand(pkgManager) {
285
+ return pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install`;
286
+ }
287
+
288
+ /**
289
+ * @param {string} pkgManager
290
+ * @returns string
291
+ */
292
+ function getStartCommand(pkgManager) {
293
+ return pkgManager === 'yarn' ? 'yarn dev' : `${pkgManager} run dev`;
293
294
  }
294
295
 
295
296
  init().catch((e) => {
296
- console.error(e)
297
- })
297
+ console.error(e);
298
+ });
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "create-analog",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Brandon Roberts",
7
- "scripts": {
8
-
9
- },
7
+ "scripts": {},
10
8
  "bin": {
11
9
  "create-analog": "index.js"
12
10
  },
@@ -8,7 +8,7 @@ Run `yarn` to install the application dependencies.
8
8
 
9
9
  ## Development
10
10
 
11
- Run `yarn dev` for a dev server. Navigate to `http://localhost:3000/`. The application will automatically reload if you change any of the source files.
11
+ Run `yarn dev` for a dev server. Navigate to `http://localhost:5173/`. The application will automatically reload if you change any of the source files.
12
12
 
13
13
  ## Build
14
14
 
@@ -22,3 +22,5 @@ Run `yarn test` to run unit tests with [Vitest](https://vitest.dev).
22
22
 
23
23
  - Join the [Discord](https://discord.gg/mKC2Ec48U5)
24
24
  - Visit and Star the [GitHub Repo](https://github.com/analogjs/analog)
25
+ - Visit the [Website](https://analogjs.org/)
26
+ - Follow us on [Twitter](https://twitter.com/analogjs)
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "my-app",
3
3
  "version": "0.0.0",
4
+ "private": true,
5
+ "engines": {
6
+ "node": ">=16.0.0"
7
+ },
4
8
  "scripts": {
5
9
  "dev": "vite",
6
10
  "ng": "ng",
@@ -10,7 +14,6 @@
10
14
  "test": "vitest",
11
15
  "postinstall": "vite optimize"
12
16
  },
13
- "private": true,
14
17
  "dependencies": {
15
18
  "@angular/animations": "^14.0.0",
16
19
  "@angular/common": "^14.0.0",
@@ -20,9 +23,9 @@
20
23
  "@angular/platform-browser": "^14.0.0",
21
24
  "@angular/platform-browser-dynamic": "^14.0.0",
22
25
  "@angular/router": "^14.0.0",
23
- "rxjs": "~7.5.0",
24
- "tslib": "^2.3.0",
25
- "zone.js": "~0.11.4"
26
+ "rxjs": "~7.5.6",
27
+ "tslib": "^2.4.0",
28
+ "zone.js": "~0.11.8"
26
29
  },
27
30
  "devDependencies": {
28
31
  "@analogjs/vite-plugin-angular": "latest",
@@ -30,8 +33,8 @@
30
33
  "@angular/cli": "~14.0.3",
31
34
  "@angular/compiler-cli": "^14.0.0",
32
35
  "jsdom": "^20.0.0",
33
- "typescript": "~4.7.2",
34
- "vite": "^2.9.13",
35
- "vitest": "^0.17.0"
36
+ "typescript": "~4.7.4",
37
+ "vite": "^3.0.9",
38
+ "vitest": "^0.22.1"
36
39
  }
37
40
  }
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
1
- <a name="0.0.1"></a>
2
- ## 0.0.1 (2022-06-25)
3
-
4
-
5
- ### Features
6
-
7
- * add v14 templates, README, docs updates ([300de6e](https://github.com/brandonroberts/create-vite/commit/300de6e))
8
-
9
-
10
-
@@ -1,42 +0,0 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
-
3
- # Compiled output
4
- /dist
5
- /tmp
6
- /out-tsc
7
- /bazel-out
8
-
9
- # Node
10
- /node_modules
11
- npm-debug.log
12
- yarn-error.log
13
-
14
- # IDEs and editors
15
- .idea/
16
- .project
17
- .classpath
18
- .c9/
19
- *.launch
20
- .settings/
21
- *.sublime-workspace
22
-
23
- # Visual Studio Code
24
- .vscode/*
25
- !.vscode/settings.json
26
- !.vscode/tasks.json
27
- !.vscode/launch.json
28
- !.vscode/extensions.json
29
- .history/*
30
-
31
- # Miscellaneous
32
- /.angular/cache
33
- .sass-cache/
34
- /connect.lock
35
- /coverage
36
- /libpeerconnection.log
37
- testem.log
38
- /typings
39
-
40
- # System files
41
- .DS_Store
42
- Thumbs.db