@revideo/create 0.1.0
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/LICENSE +21 -0
- package/index.js +270 -0
- package/package.json +33 -0
- package/template-2d-js/gitignore +15 -0
- package/template-2d-js/package.json +19 -0
- package/template-2d-js/public/.gitkeep +0 -0
- package/template-2d-js/src/project.js +7 -0
- package/template-2d-js/src/scenes/example.jsx +12 -0
- package/template-2d-ts/gitignore +15 -0
- package/template-2d-ts/package.json +20 -0
- package/template-2d-ts/public/.gitkeep +0 -0
- package/template-2d-ts/src/project.ts +7 -0
- package/template-2d-ts/src/revideo.d.ts +1 -0
- package/template-2d-ts/src/scenes/example.tsx +12 -0
- package/template-2d-ts/tsconfig.json +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 motion-canvas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//@ts-check
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import kleur from 'kleur';
|
|
5
|
+
import minimist from 'minimist';
|
|
6
|
+
import {fileURLToPath} from 'node:url';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import prompts from 'prompts';
|
|
9
|
+
|
|
10
|
+
const FILES_TO_MODIFY = {
|
|
11
|
+
gitignore: '.gitignore',
|
|
12
|
+
'.gitkeep': false,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const MANIFEST = JSON.parse(
|
|
16
|
+
fs.readFileSync(
|
|
17
|
+
path.resolve(fileURLToPath(import.meta.url), '../package.json'),
|
|
18
|
+
'utf-8',
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const PLUGINS = {
|
|
23
|
+
core: {
|
|
24
|
+
package: '@revideo/vite-plugin',
|
|
25
|
+
variable: 'motionCanvas',
|
|
26
|
+
options: response =>
|
|
27
|
+
response.language === 'js' ? `{project: './src/project.js'}` : '',
|
|
28
|
+
},
|
|
29
|
+
ffmpeg: {
|
|
30
|
+
package: '@revideo/ffmpeg',
|
|
31
|
+
variable: 'ffmpeg',
|
|
32
|
+
version: '^1.1.0',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
(async () => {
|
|
37
|
+
const options = minimist(process.argv.slice(2));
|
|
38
|
+
if (options.plugins !== undefined) {
|
|
39
|
+
if (typeof options.plugins === 'string') {
|
|
40
|
+
options.plugins = options.plugins.split(',');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!Array.isArray(options.plugins)) {
|
|
44
|
+
options.plugins = [options.plugins];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const plugins = ['core'];
|
|
48
|
+
for (const plugin of options.plugins) {
|
|
49
|
+
if (plugin === 'core') continue;
|
|
50
|
+
if (!(plugin in PLUGINS)) {
|
|
51
|
+
console.log(kleur.yellow(`! Unknown plugin "${plugin}".\n`));
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
plugins.push(plugin);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
options.plugins = plugins;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
prompts.override(options);
|
|
61
|
+
const response = await prompts([
|
|
62
|
+
{
|
|
63
|
+
type: 'text',
|
|
64
|
+
name: 'name',
|
|
65
|
+
message: 'Project name',
|
|
66
|
+
initial: 'my-animation',
|
|
67
|
+
validate: value =>
|
|
68
|
+
isValidPackageName(value)
|
|
69
|
+
? true
|
|
70
|
+
: 'Project name must be a valid npm package name.',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'text',
|
|
74
|
+
name: 'path',
|
|
75
|
+
message: 'Project path',
|
|
76
|
+
|
|
77
|
+
initial: value => {
|
|
78
|
+
return path.normalize(value.replace('@', ''));
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
validate: value => {
|
|
82
|
+
let dir = path.normalize(value.trim());
|
|
83
|
+
if (!fs.existsSync(dir)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (!fs.lstatSync(dir).isDirectory()) {
|
|
87
|
+
return `Project path "${dir}" must be a valid directory.`;
|
|
88
|
+
}
|
|
89
|
+
if (fs.readdirSync(dir).length > 0) {
|
|
90
|
+
return dir === '.'
|
|
91
|
+
? 'Current directory must be empty.'
|
|
92
|
+
: `Target directory "${dir}" must be empty.`;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
format: value => path.resolve(value),
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: 'select',
|
|
100
|
+
name: 'language',
|
|
101
|
+
message: 'Language',
|
|
102
|
+
choices: [
|
|
103
|
+
{
|
|
104
|
+
title: 'TypeScript (Recommended)',
|
|
105
|
+
value: 'ts',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
title: 'JavaScript',
|
|
109
|
+
value: 'js',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: 'multiselect',
|
|
115
|
+
name: 'plugins',
|
|
116
|
+
message: 'How would you like to render your animation?',
|
|
117
|
+
choices: [
|
|
118
|
+
{
|
|
119
|
+
title: 'Image sequence',
|
|
120
|
+
value: 'core',
|
|
121
|
+
disabled: true,
|
|
122
|
+
selected: true,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
title: 'Video (FFmpeg)',
|
|
126
|
+
value: 'ffmpeg',
|
|
127
|
+
selected: true,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
warn: 'This option is always included.',
|
|
131
|
+
onRender() {
|
|
132
|
+
this.value[0].selected = true;
|
|
133
|
+
},
|
|
134
|
+
validate: value => {
|
|
135
|
+
if (!Array.isArray(value)) {
|
|
136
|
+
return '"plugins" option must be an array.';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!value.includes('core')) {
|
|
140
|
+
return 'Image sequence is required.';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return true;
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
if (!response.plugins) {
|
|
149
|
+
console.log(kleur.red('× Scaffolding aborted by the user.\n'));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const templateDir = path.resolve(
|
|
154
|
+
fileURLToPath(import.meta.url),
|
|
155
|
+
'..',
|
|
156
|
+
`template-2d-${response.language}`,
|
|
157
|
+
);
|
|
158
|
+
copyDirectory(templateDir, response.path);
|
|
159
|
+
createConfig(response);
|
|
160
|
+
|
|
161
|
+
const manifest = JSON.parse(
|
|
162
|
+
fs.readFileSync(path.join(templateDir, `package.json`), 'utf-8'),
|
|
163
|
+
);
|
|
164
|
+
manifest.name = response.name;
|
|
165
|
+
manifest.dependencies ??= {};
|
|
166
|
+
for (const plugin of response.plugins) {
|
|
167
|
+
const data = PLUGINS[plugin];
|
|
168
|
+
if (data.version) {
|
|
169
|
+
manifest.dependencies[data.package] = data.version;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
cloneVersions(manifest.dependencies);
|
|
173
|
+
|
|
174
|
+
if (manifest.devDependencies) {
|
|
175
|
+
cloneVersions(manifest.devDependencies);
|
|
176
|
+
}
|
|
177
|
+
fs.writeFileSync(
|
|
178
|
+
path.join(response.path, 'package.json'),
|
|
179
|
+
JSON.stringify(manifest, undefined, 2),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const manager = getPackageManager();
|
|
183
|
+
console.log(kleur.green('\n√ Scaffolding complete. You can now run:'));
|
|
184
|
+
if (response.path !== process.cwd()) {
|
|
185
|
+
console.log(
|
|
186
|
+
` ${kleur.bold('cd')} ${path.relative(process.cwd(), response.path)}`,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const boldManager = kleur.bold(manager);
|
|
190
|
+
if (manager === 'yarn') {
|
|
191
|
+
console.log(` ${boldManager}`);
|
|
192
|
+
console.log(` ${boldManager} start`);
|
|
193
|
+
} else {
|
|
194
|
+
console.log(` ${boldManager} install`);
|
|
195
|
+
console.log(` ${boldManager} start`);
|
|
196
|
+
}
|
|
197
|
+
console.log();
|
|
198
|
+
})();
|
|
199
|
+
|
|
200
|
+
function isValidPackageName(projectName) {
|
|
201
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
202
|
+
projectName,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function copyDirectory(src, dest) {
|
|
207
|
+
fs.mkdirSync(dest, {recursive: true});
|
|
208
|
+
for (const file of fs.readdirSync(src)) {
|
|
209
|
+
let target = file;
|
|
210
|
+
if (file in FILES_TO_MODIFY) {
|
|
211
|
+
if (FILES_TO_MODIFY[file] === false) continue;
|
|
212
|
+
target = FILES_TO_MODIFY[file];
|
|
213
|
+
}
|
|
214
|
+
const srcFile = path.resolve(src, file);
|
|
215
|
+
const destFile = path.resolve(dest, target);
|
|
216
|
+
copy(srcFile, destFile);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function copy(src, dest) {
|
|
221
|
+
const stat = fs.statSync(src);
|
|
222
|
+
if (stat.isDirectory()) {
|
|
223
|
+
copyDirectory(src, dest);
|
|
224
|
+
} else {
|
|
225
|
+
fs.copyFileSync(src, dest);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function createConfig(response) {
|
|
230
|
+
const imports = [];
|
|
231
|
+
const plugins = [];
|
|
232
|
+
for (const plugin of response.plugins) {
|
|
233
|
+
const data = PLUGINS[plugin];
|
|
234
|
+
imports.push(`import ${data.variable} from '${data.package}';\n`);
|
|
235
|
+
plugins.push(`${data.variable}(${data.options?.(response) ?? ''}),`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const configFile = path.resolve(
|
|
239
|
+
response.path,
|
|
240
|
+
`vite.config.${response.language}`,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
fs.writeFileSync(
|
|
244
|
+
configFile,
|
|
245
|
+
`import {defineConfig} from 'vite';
|
|
246
|
+
${imports.join('')}
|
|
247
|
+
export default defineConfig({
|
|
248
|
+
plugins: [
|
|
249
|
+
${plugins.join('\n ')}
|
|
250
|
+
],
|
|
251
|
+
});
|
|
252
|
+
`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function getPackageManager() {
|
|
257
|
+
const ua = process.env.npm_config_user_agent;
|
|
258
|
+
return ua?.split(' ')[0].split('/')[0] ?? 'npm';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function cloneVersions(versions) {
|
|
262
|
+
for (const dependency in versions) {
|
|
263
|
+
if (
|
|
264
|
+
dependency.startsWith('@revideo') &&
|
|
265
|
+
MANIFEST.devDependencies[dependency]
|
|
266
|
+
) {
|
|
267
|
+
versions[dependency] = MANIFEST.devDependencies[dependency];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revideo/create",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Quickly scaffold revideo projects",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "revideo",
|
|
7
|
+
"homepage": "https://re.video/",
|
|
8
|
+
"bugs": "https://github.com/havenhq/revideo/issues",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": {
|
|
12
|
+
"create-revideo": "index.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"template-*"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/havenhq/revideo.git"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@revideo/2d": "^0.1.0",
|
|
24
|
+
"@revideo/core": "^0.1.0",
|
|
25
|
+
"@revideo/ui": "^0.1.0",
|
|
26
|
+
"@revideo/vite-plugin": "^0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"minimist": "^1.2.8",
|
|
30
|
+
"prompts": "^2.4.2"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "48bf2971cfa1dec7ea92ee0d418c35772f7ea84d"
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "2d-starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"start": "vite",
|
|
7
|
+
"serve": "vite",
|
|
8
|
+
"build": "vite build"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@revideo/core": "*",
|
|
12
|
+
"@revideo/2d": "*"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@revideo/ui": "*",
|
|
16
|
+
"@revideo/vite-plugin": "*",
|
|
17
|
+
"vite": "^4.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Circle, makeScene2D} from '@revideo/2d';
|
|
2
|
+
import {createRef} from '@revideo/core';
|
|
3
|
+
|
|
4
|
+
export default makeScene2D(function* (view) {
|
|
5
|
+
// Create your animations here
|
|
6
|
+
|
|
7
|
+
const circle = createRef();
|
|
8
|
+
|
|
9
|
+
view.add(<Circle ref={circle} size={320} fill={'lightseagreen'} />);
|
|
10
|
+
|
|
11
|
+
yield* circle().scale(2, 2).to(1, 2);
|
|
12
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "2d-starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"start": "vite",
|
|
7
|
+
"serve": "vite",
|
|
8
|
+
"build": "tsc && vite build"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@revideo/core": "*",
|
|
12
|
+
"@revideo/2d": "*"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@revideo/ui": "*",
|
|
16
|
+
"@revideo/vite-plugin": "*",
|
|
17
|
+
"typescript": "^5.2.2",
|
|
18
|
+
"vite": "^5.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="@revideo/core/project" />
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Circle, makeScene2D} from '@revideo/2d';
|
|
2
|
+
import {createRef} from '@revideo/core';
|
|
3
|
+
|
|
4
|
+
export default makeScene2D(function* (view) {
|
|
5
|
+
// Create your animations here
|
|
6
|
+
|
|
7
|
+
const circle = createRef<Circle>();
|
|
8
|
+
|
|
9
|
+
view.add(<Circle ref={circle} size={320} fill={'lightseagreen'} />);
|
|
10
|
+
|
|
11
|
+
yield* circle().scale(2, 2).to(1, 2);
|
|
12
|
+
});
|