Skip to content

Commit b6b982b

Browse files
authored
initialize cache on create (#1145)
* initialize cache on create * only sleep on fast steps
1 parent 25b19bd commit b6b982b

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/create.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ const defaultEffects: CreateEffects = {
3737
}
3838
};
3939

40-
// TODO Do we want to accept the output path as a command-line argument,
41-
// still? It’s not sufficient to run observable create non-interactively,
42-
// though we could just apply all the defaults in that case, and then expose
43-
// command-line arguments for the other prompts. In any case, our immediate
44-
// priority is supporting the interactive case, not the automated one.
45-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
46-
export async function create(options = {}, effects: CreateEffects = defaultEffects): Promise<void> {
40+
export async function create(effects: CreateEffects = defaultEffects): Promise<void> {
4741
const {clack} = effects;
4842
clack.intro(`${inverse(" observable create ")} ${faint(`v${process.env.npm_package_version}`)}`);
4943
const defaultRootPath = "hello-framework";
@@ -94,7 +88,7 @@ export async function create(options = {}, effects: CreateEffects = defaultEffec
9488
const templateDir = op.resolve(fileURLToPath(import.meta.url), "..", "..", "templates", template);
9589
const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager ?? "npm"} run`;
9690
const installCommand = `${packageManager ?? "npm"} install`;
97-
await effects.sleep(1000);
91+
await effects.sleep(1000); // this step is fast; give the spinner a chance to show
9892
await recursiveCopyTemplate(
9993
templateDir,
10094
rootPath!,
@@ -109,16 +103,19 @@ export async function create(options = {}, effects: CreateEffects = defaultEffec
109103
);
110104
if (packageManager) {
111105
s.message(`Installing dependencies via ${packageManager}`);
112-
await effects.sleep(1000);
113106
if (packageManager === "yarn") await writeFile(join(rootPath, "yarn.lock"), "");
114107
await promisify(exec)(installCommand, {cwd: rootPath});
115108
}
116109
if (initializeGit) {
117110
s.message("Initializing git repository");
118-
await effects.sleep(1000);
111+
await effects.sleep(1000); // this step is fast; give the spinner a chance to show
119112
await promisify(exec)("git init", {cwd: rootPath});
120113
await promisify(exec)("git add -A", {cwd: rootPath});
121114
}
115+
if (packageManager) {
116+
s.message("Initializing Framework cache");
117+
await promisify(exec)(`${runCommand} build`, {cwd: rootPath});
118+
}
122119
s.stop("Installed! 🎉");
123120
const instructions = [`cd ${rootPath}`, ...(packageManager ? [] : [installCommand]), `${runCommand} dev`];
124121
clack.note(instructions.map((line) => reset(cyan(line))).join("\n"), "Next steps…");

test/create-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("create", () => {
1414
null, // Install dependencies?
1515
false // Initialize git repository?
1616
);
17-
await create(undefined, effects);
17+
await create(effects);
1818
assert.deepStrictEqual(
1919
new Set(effects.outputs.keys()),
2020
new Set([
@@ -42,7 +42,7 @@ describe("create", () => {
4242
null, // Install dependencies?
4343
false // Initialize git repository?
4444
);
45-
await create(undefined, effects);
45+
await create(effects);
4646
assert.deepStrictEqual(
4747
new Set(effects.outputs.keys()),
4848
new Set([

0 commit comments

Comments
 (0)